From deb619892149bbd832f0542f2c7bd509ed154971 Mon Sep 17 00:00:00 2001 From: Rafael Silva Date: Wed, 24 Aug 2022 12:58:10 +0100 Subject: [PATCH] target_flash: swap while for forloop in buffered flush --- src/target/target_flash.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/target/target_flash.c b/src/target/target_flash.c index e664d26..0367ccd 100644 --- a/src/target/target_flash.c +++ b/src/target/target_flash.c @@ -266,13 +266,8 @@ static bool flash_buffered_flush(target_flash_s *f) const uint8_t *src = f->buf + (aligned_addr - f->buf_addr_base); uint32_t len = f->buf_addr_high - aligned_addr; - while (len) { - ret &= f->write(f, aligned_addr, src, f->writesize) == 0; - - aligned_addr += f->writesize; - src += f->writesize; - len -= MIN(len, f->writesize); - } + for (size_t offset = 0; offset < len; offset += f->writesize) + ret &= f->write(f, aligned_addr + offset, src + offset, f->writesize) == 0; f->buf_addr_base = UINT32_MAX; f->buf_addr_low = UINT32_MAX;