From 8c8db531388cbc1fe61a73e581c69915770a4da2 Mon Sep 17 00:00:00 2001 From: ALTracer <11005378+ALTracer@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:29:06 +0300 Subject: [PATCH] target_flash: simplify inner loop --- src/target/target_flash.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/target/target_flash.c b/src/target/target_flash.c index 8dfec31be00..bd365853b8d 100644 --- a/src/target/target_flash.c +++ b/src/target/target_flash.c @@ -320,22 +320,18 @@ static bool flash_blank_check(target_flash_s *flash, target_addr_t src, size_t l platform_timeout_s timeout; platform_timeout_set(&timeout, 500); - while (len) { - const size_t offset = src % flash->writebufsize; - const size_t local_len = MIN(flash->writebufsize - offset, len); + for (size_t offset = 0U; offset < len; offset += flash->writebufsize) { /* Fetch chunk into sector buffer */ - target_mem32_read(target, flash->buf, src, local_len); + target_mem32_read(target, flash->buf, src + offset, flash->writebufsize); /* Compare bytewise with erased value */ const uint8_t erased = flash->erased; - for (size_t i = 0; i < local_len; i++) { + for (size_t i = 0; i < flash->writebufsize; i++) { if (flash->buf[i] != erased) { *mismatch = src + i; return false; } } - src += local_len; - len -= local_len; target_print_progress(&timeout); } return result;