From: Tomas Vanek Date: Thu, 18 Jan 2018 08:42:41 +0000 (+0100) Subject: flash/nor/core: fix warning in flash_iterate_address_range_inner X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a088e3942300a02a7a170aa26d780dd156baf0b4;p=openocd flash/nor/core: fix warning in flash_iterate_address_range_inner Refactor the code to improve readability. Reported by Clang static analyzer. Change-Id: I671447050e93c6f067917c4456b36ac11abb4663 Signed-off-by: Tomas Vanek Reviewed-on: http://openocd.zylin.com/4355 Tested-by: jenkins --- diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c index 7b91e57b..6eb7052e 100644 --- a/src/flash/nor/core.c +++ b/src/flash/nor/core.c @@ -399,18 +399,21 @@ static int flash_iterate_address_range_inner(struct target *target, return ERROR_FLASH_DST_BREAKS_ALIGNMENT; } - addr -= c->base; - last_addr -= c->base; + if (c->prot_blocks == NULL || c->num_prot_blocks == 0) { + /* flash driver does not define protect blocks, use sectors instead */ + iterate_protect_blocks = false; + } - if (iterate_protect_blocks && c->prot_blocks && c->num_prot_blocks) { + if (iterate_protect_blocks) { block_array = c->prot_blocks; num_blocks = c->num_prot_blocks; } else { block_array = c->sectors; num_blocks = c->num_sectors; - iterate_protect_blocks = false; } + addr -= c->base; + last_addr -= c->base; for (i = 0; i < num_blocks; i++) { struct flash_sector *f = &block_array[i];