From patchwork Tue Oct 11 17:39:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishanth Menon X-Patchwork-Id: 77510 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp107046qge; Tue, 11 Oct 2016 10:39:41 -0700 (PDT) X-Received: by 10.194.11.100 with SMTP id p4mr6204145wjb.125.1476207581184; Tue, 11 Oct 2016 10:39:41 -0700 (PDT) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id j10si6210723wjq.30.2016.10.11.10.39.40; Tue, 11 Oct 2016 10:39:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE dis=NONE) header.from=ti.com Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B6DFAA7544; Tue, 11 Oct 2016 19:39:33 +0200 (CEST) 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 R6d8TXDeoh8U; Tue, 11 Oct 2016 19:39:33 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5FF3FA752D; Tue, 11 Oct 2016 19:39:24 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E05B84B6B3 for ; Tue, 11 Oct 2016 19:39:16 +0200 (CEST) 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 cHdeXvTpyD54 for ; Tue, 11 Oct 2016 19:39:16 +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 comal.ext.ti.com (comal.ext.ti.com [198.47.26.152]) by theia.denx.de (Postfix) with ESMTPS id 2E13C4B68A for ; Tue, 11 Oct 2016 19:39:13 +0200 (CEST) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id u9BHdASI010273; Tue, 11 Oct 2016 12:39:10 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id u9BHd9xl028019; Tue, 11 Oct 2016 12:39:10 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.294.0; Tue, 11 Oct 2016 12:39:09 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id u9BHd9fY014851; Tue, 11 Oct 2016 12:39:09 -0500 From: Nishanth Menon To: Lokesh Vutla , Tom Rini Date: Tue, 11 Oct 2016 12:39:05 -0500 Message-ID: <20161011173905.26208-4-nm@ti.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161011173905.26208-1-nm@ti.com> References: <20161011173905.26208-1-nm@ti.com> MIME-Version: 1.0 Cc: u-boot@lists.denx.de, Brad Griffis Subject: [U-Boot] [PATCH 3/3] ti: common: board_detect: Return a valid empty string for un-initialized eeprom X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Current logic for query of revision, board_name, config returns NULL. Users of these functions do a direct strncmp to compare. Unfortunately, as per conventions require two valid strings to compare against and the current implementation causes a crash when compared with NULL. We'd still like to maintain the simplistic usage of these APIs instead of redundant if (string) res=strncmp(fn(),"cmp",n); flowing all over the place. Hence, since the version, name and config is already pre-initialized with empty string, just dont check for invalid header in the first place and return the empty string to the caller. Reported-by: Brad Griffis Signed-off-by: Nishanth Menon --- board/ti/common/board_detect.c | 12 +++--------- board/ti/common/board_detect.h | 6 +++--- 2 files changed, 6 insertions(+), 12 deletions(-) -- 2.10.0 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c index 13aac2f03037..6e7ca9196d22 100644 --- a/board/ti/common/board_detect.c +++ b/board/ti/common/board_detect.c @@ -231,9 +231,7 @@ char * __maybe_unused board_ti_get_rev(void) { struct ti_common_eeprom *ep = TI_EEPROM_DATA; - if (ep->header == TI_DEAD_EEPROM_MAGIC) - return NULL; - + /* if ep->header == TI_DEAD_EEPROM_MAGIC, this is empty already */ return ep->version; } @@ -241,9 +239,7 @@ char * __maybe_unused board_ti_get_config(void) { struct ti_common_eeprom *ep = TI_EEPROM_DATA; - if (ep->header == TI_DEAD_EEPROM_MAGIC) - return NULL; - + /* if ep->header == TI_DEAD_EEPROM_MAGIC, this is empty already */ return ep->config; } @@ -251,9 +247,7 @@ char * __maybe_unused board_ti_get_name(void) { struct ti_common_eeprom *ep = TI_EEPROM_DATA; - if (ep->header == TI_DEAD_EEPROM_MAGIC) - return NULL; - + /* if ep->header == TI_DEAD_EEPROM_MAGIC, this is empty already */ return ep->name; } diff --git a/board/ti/common/board_detect.h b/board/ti/common/board_detect.h index eb17f6f52a12..2ded3ed7764b 100644 --- a/board/ti/common/board_detect.h +++ b/board/ti/common/board_detect.h @@ -141,7 +141,7 @@ bool board_ti_rev_is(char *rev_tag, int cmp_len); /** * board_ti_get_rev() - Get board revision for TI EVMs * - * Return: NULL if eeprom was'nt read. + * Return: Empty string if eeprom was'nt read. * Board revision otherwise */ char *board_ti_get_rev(void); @@ -149,7 +149,7 @@ char *board_ti_get_rev(void); /** * board_ti_get_config() - Get board config for TI EVMs * - * Return: NULL if eeprom was'nt read. + * Return: Empty string if eeprom was'nt read. * Board config otherwise */ char *board_ti_get_config(void); @@ -157,7 +157,7 @@ char *board_ti_get_config(void); /** * board_ti_get_name() - Get board name for TI EVMs * - * Return: NULL if eeprom was'nt read. + * Return: Empty string if eeprom was'nt read. * Board name otherwise */ char *board_ti_get_name(void);