Various coverity fixes
cover Various coverity fixes
This series aims to fix or suppress various Coverity warnings reported on recent patches.
Simon Glass (10):
test: pwm: Add a check that dev is not NULL
edid: Use sizeof() in cea_is_hdmi_vsdb_present()
fdtgrep: Deal with NULL data passed to check_type_include()
fdt: Add a check to do_fdt() for coverity
fdt: Add a check to fdt_print() for coverity
test: wdt: Add a check that dev is not NULL
test: bus: Add a check that dev is not NULL
dm: core: Supress dead-code warning in __of_get_next_child()
board_f: Use IS_ENABLED instead of #ifdef in initf_bootstage() rkcommon.c: Drop pointless assignment
cmd/fdt.c | 4 ++-- common/board_f.c | 7 ++----- common/edid.c | 4 ++-- drivers/core/of_access.c | 6 ++++++ test/dm/bus.c | 3 +++ test/dm/pwm.c | 1 + test/dm/wdt.c | 1 + tools/fdtgrep.c | 25 ++++++++++++++----------- tools/rkcommon.c | 3 ++- 9 files changed, 33 insertions(+), 21 deletions(-)
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 1/10 test: pwm: Add a check that dev is not NULL
We know that uclass_get_device() does not return NULL for dev when it succeeds but coverity does not. Add an extra check to hopefully keep it happy.
---
test/dm/pwm.c | 1 + 1 file changed, 1 insertion(+)
test/dm/pwm.c +1 -0
@@ -18,6 +18,7 @@ static int dm_test_pwm_base(struct unit_test_state *uts)struct udevice *dev;ut_assertok (uclass_get_device (UCLASS_PWM ,0 , &dev)); +ut_assertnonnull (dev);ut_assertok (pwm_set_config (dev,0 ,100 ,50 ));ut_assertok (pwm_set_enable (dev,0 , true));ut_assertok (pwm_set_enable (dev,1 , true));
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 1/10 test: pwm: Add a check that dev is not NULL
Quoted 7 lines · Simon Glass
We know that
uclass_get_device()does not return NULL for dev when it succeeds but coverity does not. Add an extra check to hopefully keep it happy.Signed-off-by Simon Glass <[email protected]>Reported-by Coverity (CID: 161690)Fixes 43b4156 (dm: sandbox: pwm: Add a basic pwm test)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170612/6d68914d/attachment.sig>
PATCH 2/10 edid: Use sizeof() in cea_is_hdmi_vsdb_present()
In reply to Simon GlassWe should not use an open-coded value here. Use sizeof() instead.
---
common/edid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
common/edid.c +2 -2
@@ -148,8 +148,8 @@ static bool cea_is_hdmi_vsdb_present(struct edid_cea861_info *info)/* check for end of data block */ end = info->dtd_offset;if (end ==0 ) - end =127 ; -if (end <4 || end >127 ) + end =sizeof (info->data); +if (end <4 || end >sizeof (info->data))return false; end -=4 ;
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 2/10 edid: Use sizeof() in cea_is_hdmi_vsdb_present()
Quoted 5 lines · Simon Glass
We should not use an open-coded value here. Use
sizeof()instead.Signed-off-by Simon Glass <[email protected]>Reported-by Coverity (CID: 163252)Fixes 43c6bdd0 (edid: Add HDMI flag to timing info)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170612/7a61390a/attachment.sig>
PATCH 3/10 fdtgrep: Deal with NULL data passed to check_type_include()
In reply to Simon GlassSince the parameter can be NULL we must be careful not to dereference it in this case.
---
tools/fdtgrep.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
tools/fdtgrep.c +14 -11
@@ -522,18 +522,21 @@ static int check_type_include(void *priv, int type, const char *data, int size)* return 1 at the first match. For exclusive conditions, we must * check that there are no matches. */ -for (val = disp->value_head; val; val = val->next) { -if (!(type & val->type)) -continue ; - match =fdt_stringlist_contains (data, size, val->string); -debug (" - val->type=%x, str='%s', match=%d\n" , - val->type, val->string, match); -if (match && val->include) { -debug (" - match inc %s\n" , val->string); -return 1 ; +if (data) { +for (val = disp->value_head; val; val = val->next) { +if (!(type & val->type)) +continue ; + match =fdt_stringlist_contains (data, size, + val->string); +debug (" - val->type=%x, str='%s', match=%d\n" , + val->type, val->string, match); +if (match && val->include) { +debug (" - match inc %s\n" , val->string); +return 1 ; + } +if (match) + none_match &= ~val->type; } -if (match) - none_match &= ~val->type; }/*
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 3/10 fdtgrep: Deal with NULL data passed to check_type_include()
Quoted 6 lines · Simon Glass
Since the parameter can be NULL we must be careful not to dereference it in this case.
Signed-off-by Simon Glass <[email protected]>Reported-by Coverity (CID: 163250)Fixes 1043d0a0 (fdt: Add fdtgrep tool)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170612/83667846/attachment.sig>
PATCH 4/10 fdt: Add a check to do_fdt() for coverity
In reply to Simon GlassWe know that fdt_getprop() does not return NULL when len is > 0 but coverity does not. Add an extra check to keep it happy.
---
cmd/fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/fdt.c +1 -1
@@ -371,7 +371,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])/* no property value */ setenv (var,"" );return 0 ; - }else if (len >0 ) { + }else if (nodep && len >0 ) {if (subcmd[0 ] =='v' ) {int ret;
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 4/10 fdt: Add a check to do_fdt() for coverity
Quoted 6 lines · Simon Glass
We know that
fdt_getprop()does not return NULL when len is > 0 but coverity does not. Add an extra check to keep it happy.Signed-off-by Simon Glass <[email protected]>Reported-by Coverity (CID: 163249)Fixes bc80295b (fdt: Add get commands to fdt)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170612/510fb0ad/attachment.sig>
PATCH 5/10 fdt: Add a check to fdt_print() for coverity
In reply to Simon GlassWe know that fdt_getprop() does not return NULL when len is > 0 but coverity does not. Add an extra check to keep it happy.
---
cmd/fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/fdt.c +1 -1
@@ -962,7 +962,7 @@ static int fdt_print(const char *pathp, char *prop, int depth)/* no property value */ printf ("%s %s\n" , pathp, prop);return 0 ; - }else if (len >0 ) { + }else if (nodep && len >0 ) {printf ("%s = " , prop);print_data (nodep, len);printf ("\n" );
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 5/10 fdt: Add a check to fdt_print() for coverity
Quoted 5 lines · Simon Glass
We know that
fdt_getprop()does not return NULL when len is > 0 but coverity does not. Add an extra check to keep it happy.Signed-off-by Simon Glass <[email protected]>Reported-by Coverity (CID: 163248)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170612/1ca0bebd/attachment.sig>
PATCH 6/10 test: wdt: Add a check that dev is not NULL
In reply to Simon GlassWe know that uclass_get_device() does not return NULL for dev when it succeeds but coverity does not. Add an extra check to hopefully keep it happy.
---
test/dm/wdt.c | 1 + 1 file changed, 1 insertion(+)
test/dm/wdt.c +1 -0
@@ -20,6 +20,7 @@ static int dm_test_wdt_base(struct unit_test_state *uts)const u64 timeout =42 ;ut_assertok (uclass_get_device (UCLASS_WDT ,0 , &dev)); +ut_assertnonnull (dev);ut_asserteq (0 , state->wdt.counter);ut_asserteq (false, state->wdt.running);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 6/10 test: wdt: Add a check that dev is not NULL
Quoted 7 lines · Simon Glass
We know that
uclass_get_device()does not return NULL for dev when it succeeds but coverity does not. Add an extra check to hopefully keep it happy.Signed-off-by Simon Glass <[email protected]>Reported-by Coverity (CID: 163247)Fixes 0753bc2 (dm: Simple Watchdog uclass)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170612/43cd1fe4/attachment.sig>
PATCH 7/10 test: bus: Add a check that dev is not NULL
In reply to Simon GlassWe know that uclass_get_device() and device_find_child_by_of_offset() do not return NULL for dev when they succeeds but coverity does not. Add an extra check to hopefully keep it happy.
---
test/dm/bus.c | 3 +++ 1 file changed, 3 insertions(+)
test/dm/bus.c +3 -0
@@ -171,13 +171,16 @@ static int dm_test_bus_children_of_offset(struct unit_test_state *uts)int node;ut_assertok (uclass_get_device (UCLASS_TEST_BUS ,0 , &bus)); +ut_assertnonnull (bus);/* Find a valid child */ node =fdt_path_offset (blob,"/some-bus/c-test at 1" );ut_assert (node >0 );ut_assertok (device_find_child_by_of_offset (bus, node, &dev)); +ut_assertnonnull (dev);ut_assert (!(dev->flags &DM_FLAG_ACTIVATED ));ut_assertok (device_get_child_by_of_offset (bus, node, &dev)); +ut_assertnonnull (dev);ut_assert (dev->flags &DM_FLAG_ACTIVATED );return 0 ;
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 7/10 test: bus: Add a check that dev is not NULL
Quoted 7 lines · Simon Glass
We know that
uclass_get_device()anddevice_find_child_by_of_offset()do not return NULL for dev when they succeeds but coverity does not. Add an extra check to hopefully keep it happy.Signed-off-by Simon Glass <[email protected]>Reported-by Coverity (CID: 163246)Fixes 0753bc2 (dm: Simple Watchdog uclass)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170612/c107cfdb/attachment.sig>
PATCH 8/10 dm: core: Supress dead-code warning in __of_get_next_child()
In reply to Simon GlassSuppress a warning on next = next->sibling.
Fixes 644ec0a (dm: core: Add livetree access functions)
---
drivers/core/of_access.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/core/of_access.c +6 -0
@@ -244,6 +244,12 @@ static struct device_node *__of_get_next_child(const struct device_node *node,return NULL ; next = prev ? prev->sibling : node->child; +/* +* coverity[dead_error_line : FALSE] +* Dead code here since our current implementation of of_node_get() +* always returns NULL (Coverity CID 163245). But we leave it as is +* since we may want to implement get/put later. +*/ for (; next; next = next->sibling)if (of_node_get (next))break ;
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 8/10 dm: core: Supress dead-code warning in __of_get_next_child()
Quoted 5 lines · Simon Glass
Suppress a warning on next =
next->sibling.Signed-off-by Simon Glass <[email protected]>Reported-by Coverity (CID: 163245)Fixes 644ec0a (dm: core: Add livetree access functions)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170612/5fa51648/attachment.sig>
PATCH 9/10 board_f: Use IS_ENABLED instead of #ifdef in initf_bootstage()
In reply to Simon GlassThe current implementation makes it look like the 'if (from_spl)' part is dead code because these features are not enabled for sandbox. We could enable it for sandbox_spl, but this is not done yet (it requires sharing memory between SPL and U-Boot proper which is in fact supported).
It is probably nicer to avoid #ifdef anyway. Change it.
---
common/board_f.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
common/board_f.c +2 -5
@@ -707,11 +707,8 @@ static int jump_to_copy(void)/* Record the board_init_f() bootstage (after arch_cpu_init()) */ static int initf_bootstage (void ) { -#if defined(CONFIG_SPL_BOOTSTAGE ) && defined(CONFIG_BOOTSTAGE_STASH ) -bool from_spl = true; -#else -bool from_spl = false; -#endif +bool from_spl =IS_ENABLED (CONFIG_SPL_BOOTSTAGE ) && +IS_ENABLED (CONFIG_BOOTSTAGE_STASH );int ret; ret =bootstage_init (!from_spl);
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 9/10 board_f: Use IS_ENABLED instead of #ifdef in initf_bootstage()
Quoted 10 lines · Simon Glass
The current implementation makes it look like the 'if (
from_spl)' part is dead code because these features are not enabled for sandbox. We could enable it forsandbox_spl, but this is not done yet (it requires sharing memory between SPL and U-Boot proper which is in fact supported).It is probably nicer to avoid #ifdef anyway. Change it.
Signed-off-by Simon Glass <[email protected]>Reported-by Coverity (CID: 163244)Fixes 824bb1b (bootstage: Support SPL)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170612/0470bd88/attachment.sig>
PATCH 10/10 rkcommon.c: Drop pointless assignment
In reply to Simon GlassAssigning a variable to itself is not necessary. Drop this and also add a check for malloc() failure.
---
tools/rkcommon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/rkcommon.c +2 -1
@@ -259,8 +259,9 @@ int rkcommon_vrec_header(struct image_tool_params *params,/* Allocate, clear and install the header */ tparams->hdr =malloc (tparams->header_size); +if (!tparams->hdr) +return -ENOMEM ;memset (tparams->hdr,0 , tparams->header_size); - tparams->header_size = tparams->header_size;/* * If someone passed in 0 for the alignment, we'd better handle
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH 10/10 rkcommon.c: Drop pointless assignment
Quoted 6 lines · Simon Glass
Assigning a variable to itself is not necessary. Drop this and also add a check for
malloc()failure.Signed-off-by Simon Glass <[email protected]>Reported-by Coverity (CID: 161418)Fixes 111bcc4 (rockchip: mkimage: pad the header to 8-bytes (using a 'nop') for RK3399)
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170612/18d23db0/attachment.sig>
cover Various coverity fixes
In reply to Simon GlassQuoted 4 lines · Simon Glass
This series aims to fix or suppress various Coverity warnings reported on recent patches.
Quoted 11 lines
Simon Glass (10):
test: pwm: Add a check that dev is not NULL
edid: Usesizeof()incea_is_hdmi_vsdb_present()
fdtgrep: Deal with NULL data passed tocheck_type_include()
fdt: Add a check todo_fdt()for coverity
fdt: Add a check tofdt_print()for coverity
test: wdt: Add a check that dev is not NULL
test: bus: Add a check that dev is not NULL
dm: core: Supress dead-code warning in__of_get_next_child()
board_f: UseIS_ENABLEDinstead of #ifdef ininitf_bootstage()rkcommon.c: Drop pointless assignment
Thanks for taking care of these!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170607/898a2a25/attachment.sig>
cover Various coverity fixes
Hi Tom,
Quoted 18 lines · Tom Rini
Quoted 4 lines · Simon Glass
This series aims to fix or suppress various Coverity warnings reported on recent patches.
Quoted 11 lines
Simon Glass (10):
test: pwm: Add a check that dev is not NULL
edid: Usesizeof()incea_is_hdmi_vsdb_present()
fdtgrep: Deal with NULL data passed tocheck_type_include()
fdt: Add a check todo_fdt()for coverity
fdt: Add a check tofdt_print()for coverity
test: wdt: Add a check that dev is not NULL
test: bus: Add a check that dev is not NULL
dm: core: Supress dead-code warning in__of_get_next_child()
board_f: UseIS_ENABLEDinstead of #ifdef ininitf_bootstage()rkcommon.c: Drop pointless assignment
Quoted 1 line
Thanks for taking care of these!
:-) Hopefully these do actually fix the problems.
Regards,
Simon