power: Address two Smatch reported issues
cover power: Address two Smatch reported issues
Smatch reported issues with two power drivers due to redundant code and an unitialised variable.
---
Andrew Goodbody (2):
power: axp: Remove redundant code
power: power_i2c: ret is uninitialised if not DM_I2C
drivers/power/axp818.c | 2 -- drivers/power/power_i2c.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-)
---
base-commit: 3526f990b77fca1c933f1d8b24eb9385010a05bf
change-id: 20250807-power_misc-635ac27b477b
Best regards,
Signature · 1 line
Andrew Goodbody <[email protected]>
PATCH 1/2 power: axp: Remove redundant code
In axp_init after checking the chip ID there is an else clause that returns ret. ret is guaranteed to be 0 at this point as the code would have returned above if not. The next statement is a return 0 so the return ret is redundant, remove it.
This issue was found by Smatch.
--- drivers/power/axp818.c | 2 -- 1 file changed, 2 deletions(-)
drivers/power/axp818.c +0 -2
@@ -248,8 +248,6 @@ int axp_init(void)if (!(axp_chip_id ==0x51 ))return -ENODEV ; -else -return ret;return 0 ; }
Signature · 1 line
2.39.5
Re: [PATCH 1/2] power: axp: Remove redundant code
Hi Andrew,
Quoted 7 lines · Andrew Goodbody
In
axp_initafter checking the chip ID there is an else clause that returns ret. ret is guaranteed to be 0 at this point as the code would have returned above if not. The next statement is a return 0 so the return ret is redundant, remove it.This issue was found by Smatch.
Thanks!
Quentin
PATCH 2/2 power: power_i2c: ret is uninitialised if not DM_I2C
In reply to Andrew GoodbodyIn pmic_reg_read ret is only assigned to inside #if CONFIG_IS_ENABLED(DM_I2C) so move the test and return ret inside as well and also guard the declaration of ret with CONFIG_IS_ENABLED(DM_I2C) to prevent a warning about an unused variable.
This issue was found by Smatch.
--- drivers/power/power_i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/power_i2c.c +2 -2
@@ -75,7 +75,7 @@ int pmic_reg_read(struct pmic *p, u32 reg, u32 *val) {unsigned char buf[4 ] = {0 };u32 ret_val =0 ; -int ret; +int __maybe_unused ret;if (check_reg (p, reg))return -EINVAL ;
@@ -91,9 +91,9 @@ int pmic_reg_read(struct pmic *p, u32 reg, u32 *val) return -ENXIO; } ret =dm_i2c_read (dev, reg, buf, pmic_i2c_tx_num); -#endif if (ret)return ret; +#endif switch (pmic_i2c_tx_num) {case 3 :
Signature · 1 line
2.39.5
Re: [PATCH 2/2] power: power_i2c: ret is uninitialised if not DM_I2C
Hi Andrew,
Quoted 17 lines · Andrew Goodbody
In
pmic_reg_readret is only assigned to inside #ifCONFIG_IS_ENABLED(DM_I2C)so move the test and return ret inside as well and also guard the declaration of ret withCONFIG_IS_ENABLED(DM_I2C)to prevent a warning about an unused variable.This issue was found by Smatch.
Signed-off-by Andrew Goodbody <[email protected]>--- drivers/power/power_i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/power/power_i2c.c +0
-0
drivers/power/power_i2c.c int pmic_reg_read(struct pmic *p, u32 reg, u32 *val) · line 78
Quoted 5 lines
drivers/power/power_i2c.c +1
-1@@ -75,7 +75,7 @@ int pmic_reg_read(struct pmic *p, u32 reg, u32 *val) {unsigned char buf[4 ] = {0 };u32 ret_val =0 ; -int ret; +int __maybe_unused ret;
Or move the declaration with the struct udevice *dev; afetr the #if CONFIG_IS_ENABLED(DM_I2C)?
in any case.
Thanks!
Quentin
Quoted 4 lines · Andrew Goodbody
Smatch reported issues with two power drivers due to redundant code and an unitialised variable.
Applied to u-boot/next, thanks!
[1/2] power: axp: Remove redundant code
commit: 446b7b8f2d9b5b9bcd473c91f1e45cbb77be6c5f
[2/2] power: power_i2c: ret is uninitialised if not DM_I2C
commit: aa136393c8fd448e903e3fd3297efb13e54c42d7Signature · 1 line
Tom