From patchwork Fri May 17 05:50:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 244503 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 665C82C00A9 for ; Fri, 17 May 2013 15:51:29 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 12FDE4A03F; Fri, 17 May 2013 07:51:25 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jhm8Odu+fpRX; Fri, 17 May 2013 07:51:24 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 777C84A050; Fri, 17 May 2013 07:51:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C90164A025 for ; Fri, 17 May 2013 07:51:07 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CYxzGqDhHQCI for ; Fri, 17 May 2013 07:51:00 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from smtp.mei.co.jp (smtp.mei.co.jp [133.183.100.20]) by theia.denx.de (Postfix) with ESMTP id AD2EE4A02C for ; Fri, 17 May 2013 07:50:52 +0200 (CEST) Received: from mail-gw.jp.panasonic.com ([157.8.1.157]) by smtp.mei.co.jp (8.12.11.20060614/3.7W/kc-maile12) with ESMTP id r4H5omGK009792 for ; Fri, 17 May 2013 14:50:48 +0900 (JST) Received: from epochmail.jp.panasonic.com ([157.8.1.130]) by mail.jp.panasonic.com (8.11.6p2/3.7W/kc-maili14) with ESMTP id r4H5on018989 for ; Fri, 17 May 2013 14:50:49 +0900 Received: by epochmail.jp.panasonic.com (8.12.11.20060308/3.7W/lomi17) id r4H5onti023133; Fri, 17 May 2013 14:50:49 +0900 Received: from poodle by lomi17.jp.panasonic.com (8.12.11.20060308/3.7W) with ESMTP id r4H5omQ4023110; Fri, 17 May 2013 14:50:48 +0900 Received: from beagle.diag.org (beagle.diag.org [10.186.51.83]) by poodle (Postfix) with ESMTP id D829F2740045; Fri, 17 May 2013 14:50:48 +0900 (JST) From: Masahiro Yamada To: u-boot@lists.denx.de Date: Fri, 17 May 2013 14:50:37 +0900 Message-Id: <1368769837-10630-3-git-send-email-yamada.m@jp.panasonic.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1368769837-10630-1-git-send-email-yamada.m@jp.panasonic.com> References: <1368769837-10630-1-git-send-email-yamada.m@jp.panasonic.com> Subject: [U-Boot] [PATCH 2/2] cfi_flash: return NULL for invalid base address input X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 --- drivers/mtd/cfi_flash.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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