gpio: fix uninit-value in swnode_find_gpio
PATCH 1/1 gpio: fix uninit-value in swnode_find_gpio
Fix an issue detected by the Smatch tool:\
drivers/gpio/gpiolib-swnode.c:78 swnode_find_gpio() error:
uninitialized symbol 'ret'.
The issue occurs because the 'ret' variable may be used without initialization if the for_each_gpio_property_name loop does not run. This could lead to returning an undefined value, causing unpredictable behavior.
Initialize 'ret' to -EINVAL before the loop to ensure the function returns an error code if no properties are parsed, maintaining proper error handling.
--- drivers/gpio/gpiolib-swnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib-swnode.c +1 -1
@@ -64,7 +64,7 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode,struct fwnode_reference_args args;struct gpio_desc *desc;char propname[32 ];/* 32 is max size of property name */ -int ret; +int ret =0 ; swnode =to_software_node (fwnode);if (!swnode)
Signature · 1 line
2.34.1
PATCH v2 1/1 gpio: fix uninit-value in swnode_find_gpio
Fix an issue detected by the Smatch tool:
drivers/gpio/gpiolib-swnode.c:78 swnode_find_gpio() error:
uninitialized symbol 'ret'.
The issue occurs because the 'ret' variable may be used without initialization if the for_each_gpio_property_name loop does not run. This could lead to returning an undefined value, causing unpredictable behavior.
Initialize 'ret' to 0 before the loop to ensure the function returns an error code if no properties are parsed, maintaining proper error handling.
---
V1: https://lore.kernel.org/lkml/[email protected]/T/#u
V2: Improved commit message.
drivers/gpio/gpiolib-swnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib-swnode.c +1 -1
@@ -64,7 +64,7 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode,struct fwnode_reference_args args;struct gpio_desc *desc;char propname[32 ];/* 32 is max size of property name */ -int ret; +int ret =0 ; swnode =to_software_node (fwnode);if (!swnode)
Signature · 1 line
2.34.1
Quoted 11 lines · Suraj Sonawane
Fix an issue detected by the Smatch tool:
drivers/gpio/gpiolib-swnode.c:78swnode_find_gpio()error:
uninitialized symbol 'ret'.The issue occurs because the 'ret' variable may be used without initialization if the
for_each_gpio_property_nameloop does not run. This could lead to returning an undefined value, causing unpredictable behavior.
Quoted 5 lines
Initialize 'ret' to 0 before the loop to ensure the function returns an error code if no properties are parsed, maintaining proper error handling.
Signed-off-by Suraj Sonawane <[email protected]>
Please add a Fixes tag too.
Bart
PATCH v3 1/1 gpio: fix uninit-value in swnode_find_gpio
In reply to Suraj SonawaneFix an issue detected by the Smatch tool:
drivers/gpio/gpiolib-swnode.c:78 swnode_find_gpio() error:
uninitialized symbol 'ret'.
The issue occurs because the 'ret' variable may be used without initialization if the for_each_gpio_property_name loop does not run. This could lead to returning an undefined value, causing unpredictable behavior.
Initialize 'ret' to 0 before the loop to ensure the function returns an error code if no properties are parsed, maintaining proper error handling.
---
V1: https://lore.kernel.org/lkml/[email protected]/T/#u
V2: Improved commit message.
V3: Add fixes tag.
drivers/gpio/gpiolib-swnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib-swnode.c +1 -1
@@ -64,7 +64,7 @@ struct gpio_desc *swnode_find_gpio(struct fwnode_handle *fwnode,struct fwnode_reference_args args;struct gpio_desc *desc;char propname[32 ];/* 32 is max size of property name */ -int ret; +int ret =0 ; swnode =to_software_node (fwnode);if (!swnode)
Signature · 1 line
2.34.1
Bartosz Golaszewski
AppliedFrom: Bartosz Golaszewski <[email protected]>
Quoted 11 lines · Suraj Sonawane
Fix an issue detected by the Smatch tool:
drivers/gpio/gpiolib-swnode.c:78swnode_find_gpio()error:
uninitialized symbol 'ret'.The issue occurs because the 'ret' variable may be used without initialization if the
for_each_gpio_property_nameloop does not run. This could lead to returning an undefined value, causing unpredictable behavior.[...]
Applied, thanks!
[1/1] gpio: fix uninit-value in swnode_find_gpio
commit: a14968aea637bbe38a99e6089944e4ad8e6c49e5
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
Quoted 14 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Quoted 10 lines · Suraj Sonawane
Fix an issue detected by the Smatch tool:
drivers/gpio/gpiolib-swnode.c:78swnode_find_gpio()error:
uninitialized symbol 'ret'.The issue occurs because the 'ret' variable may be used without initialization if the
for_each_gpio_property_nameloop does not run. This could lead to returning an undefined value, causing unpredictable behavior.
Quoted 8 lines
Quoted 1 line
[...]
Applied, thanks!
[1/1] gpio: fix uninit-value in
swnode_find_gpiocommit: a14968aea637bbe38a99e6089944e4ad8e6c49e5Best regards,
Thank you for applying this patch.