Patchwork [U-Boot,2/2] cfi_flash: return NULL for invalid base address input

login
register
mail settings
Submitter Masahiro Yamada
Date May 17, 2013, 5:50 a.m.
Message ID <1368769837-10630-3-git-send-email-yamada.m@jp.panasonic.com>
Download mbox | patch
Permalink /patch/244503/
State Awaiting Upstream
Delegated to: Stefan Roese
Headers show

Comments

Masahiro Yamada - May 17, 2013, 5:50 a.m.
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>
---
 drivers/mtd/cfi_flash.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Stefan Roese - May 23, 2013, 7:50 a.m.
On 05/17/2013 07:50 AM, Masahiro Yamada wrote:
> 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.

Applied to u-boot-cfi-flash/master.

Thanks,
Stefan

Patch

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 6dd47b4..ac8318a 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -183,16 +183,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