]> git.sur5r.net Git - openocd/commitdiff
flash/nor/core: fix warning in flash_iterate_address_range_inner
authorTomas Vanek <vanekt@fbl.cz>
Thu, 18 Jan 2018 08:42:41 +0000 (09:42 +0100)
committerTomas Vanek <vanekt@fbl.cz>
Sat, 3 Mar 2018 09:41:25 +0000 (09:41 +0000)
Refactor the code to improve readability.

Reported by Clang static analyzer.

Change-Id: I671447050e93c6f067917c4456b36ac11abb4663
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4355
Tested-by: jenkins
src/flash/nor/core.c

index 7b91e57b2a38a43a15bb70019946d96b30f8e490..6eb7052ef56c69e62f06ca8d90bab04ae6b11210 100644 (file)
@@ -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];