Skip to content

Commit d5e8780

Browse files
committed
target_flash: Simplify inner loop of blank_check
1 parent dd25f4c commit d5e8780

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
@@ -391,22 +391,18 @@ static bool flash_blank_check(target_flash_s *flash, target_addr_t src, size_t l
391391
platform_timeout_s timeout;
392392
platform_timeout_set(&timeout, 500);
393393

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

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

0 commit comments

Comments
 (0)