Skip to content

Commit 8c8db53

Browse files
committed
target_flash: simplify inner loop
1 parent 5b19498 commit 8c8db53

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
@@ -320,22 +320,18 @@ static bool flash_blank_check(target_flash_s *flash, target_addr_t src, size_t l
320320
platform_timeout_s timeout;
321321
platform_timeout_set(&timeout, 500);
322322

323-
while (len) {
324-
const size_t offset = src % flash->writebufsize;
325-
const size_t local_len = MIN(flash->writebufsize - offset, len);
323+
for (size_t offset = 0U; offset < len; offset += flash->writebufsize) {
326324
/* Fetch chunk into sector buffer */
327-
target_mem32_read(target, flash->buf, src, local_len);
325+
target_mem32_read(target, flash->buf, src + offset, flash->writebufsize);
328326

329327
/* Compare bytewise with erased value */
330328
const uint8_t erased = flash->erased;
331-
for (size_t i = 0; i < local_len; i++) {
329+
for (size_t i = 0; i < flash->writebufsize; i++) {
332330
if (flash->buf[i] != erased) {
333331
*mismatch = src + i;
334332
return false;
335333
}
336334
}
337-
src += local_len;
338-
len -= local_len;
339335
target_print_progress(&timeout);
340336
}
341337
return result;

0 commit comments

Comments
 (0)