Skip to content

Commit c3fbf5b

Browse files
committed
target_flash: Simplify inner loop of blank_check
1 parent 80eaef9 commit c3fbf5b

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/target/target_flash.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,22 +390,18 @@ static bool flash_blank_check(target_flash_s *flash, target_addr_t src, size_t l
390390
platform_timeout_s timeout;
391391
platform_timeout_set(&timeout, 500);
392392

393-
while (len) {
394-
const size_t offset = src % flash->writebufsize;
395-
const size_t local_len = MIN(flash->writebufsize - offset, len);
393+
for (size_t offset = 0U; offset < len; offset += flash->writebufsize) {
396394
/* Fetch chunk into sector buffer */
397-
target_mem32_read(target, flash->buf, src, local_len);
395+
target_mem32_read(target, flash->buf, src + offset, flash->writebufsize);
398396

399397
/* Compare bytewise with erased value */
400398
const uint8_t erased = flash->erased;
401-
for (size_t i = 0; i < local_len; i++) {
399+
for (size_t i = 0; i < flash->writebufsize; i++) {
402400
if (flash->buf[i] != erased) {
403401
*mismatch = src + i;
404402
return false;
405403
}
406404
}
407-
src += local_len;
408-
len -= local_len;
409405
target_print_progress(&timeout);
410406
}
411407
return result;

0 commit comments

Comments
 (0)