From 7774e97aa77c1fc18283a1ee1bfb9bdf7c6a14f2 Mon Sep 17 00:00:00 2001 From: Nishanth Menon Date: Tue, 11 Oct 2016 12:39:05 -0500 Subject: ti: common: board_detect: Return a valid empty string for un-initialized eeprom 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 Reviewed-by: Lokesh Vutla Reviewed-by: Tom Rini [trini: Correct was'nt -> wasn't typo] Signed-off-by: Tom Rini --- board/ti/common/board_detect.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'board/ti/common/board_detect.c') diff --git a/board/ti/common/board_detect.c b/board/ti/common/board_detect.c index 13aac2f030..6e7ca9196d 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; } -- cgit v1.2.3