]> git.sur5r.net Git - u-boot/commitdiff
cfi_flash: return NULL for invalid base address input
authorMasahiro Yamada <yamada.m@jp.panasonic.com>
Fri, 17 May 2013 05:50:37 +0000 (14:50 +0900)
committerStefan Roese <sr@denx.de>
Thu, 23 May 2013 07:48:45 +0000 (09:48 +0200)
When base address given was out of valid flash address ranges,
flash_get_info() function returned the pointer to the last
element of flash_info[i] array.

This patch changes this function to return NULL pointer
in such a case, which is more correct behaviour.

The function flash_protect_default() calls flash_protect()
immediately after flash_get_info() invocation.
With this correction, flash_protect() function would be
able to return soon, for NULL flash_info.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Stefan Roese <sr@denx.de>
drivers/mtd/cfi_flash.c

index 28250c23f8fbb28f58cb86c420eedfbbccbf7bcf..25f875202c337deafbda8f30b530325f21c5d88c 100644 (file)
@@ -184,16 +184,16 @@ u64 flash_read64(void *addr)__attribute__((weak, alias("__flash_read64")));
 flash_info_t *flash_get_info(ulong base)
 {
        int i;
-       flash_info_t *info = NULL;
+       flash_info_t *info;
 
        for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) {
                info = &flash_info[i];
                if (info->size && info->start[0] <= base &&
                    base <= info->start[0] + info->size - 1)
-                       break;
+                       return info;
        }
 
-       return info;
+       return NULL;
 }
 #endif