Skip to contentSkip to conversation

power: supply: Fix uninitialized variable in ip5xxx_battery_set_property

PATCH In review Karol Przybylski 2 participants 2 messages Dec 9, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 power: supply: Fix uninitialized variable in ip5xxx_battery_set_property

The variable vmax in the ip5xxx_battery_set_property function is used uninitialized when passed to switch/case statements.

This patch initializes vmax to 0 at declaration.

Issue discovered in coverity, CID 1602239

---
 drivers/power/supply/ip5xxx_power.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/ip5xxx_power.c +1 -1
index 4bcf0ea0e..65d3266c3 100644
@@ -541,7 +541,7 @@ static int ip5xxx_battery_set_property(struct power_supply *psy,
 {
 	struct ip5xxx *ip5xxx = power_supply_get_drvdata(psy);
 	unsigned int rval;
-	int ret, vmax;
+	int ret, vmax = 0;
 
 	ret = ip5xxx_initialize(psy);
 	if (ret)
Signature · 1 line
2.34.1
#1 lore raw

Hi,

Quoted 16 lines · Karol Przybylski

The variable vmax in the ip5xxx_battery_set_property function is used uninitialized when passed to switch/case statements.

This patch initializes vmax to 0 at declaration.

Issue discovered in coverity, CID 1602239

---
  drivers/power/supply/ip5xxx_power.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/ip5xxx_power.c +0 -0
index 4bcf0ea0e..65d3266c3 100644

drivers/power/supply/ip5xxx_power.c static int ip5xxx_battery_set_property(struct power_supply *psy, · line 547

Quoted 8 lines
drivers/power/supply/ip5xxx_power.c +1 -1
@@ -541,7 +541,7 @@ static int ip5xxx_battery_set_property(struct power_supply *psy,
  {
  	struct ip5xxx *ip5xxx = power_supply_get_drvdata(psy);
  	unsigned int rval;
-	int ret, vmax;
+	int ret, vmax = 0;
 
  	ret = ip5xxx_initialize(psy);
  	if (ret)

This is not the proper way to fix this. See my patch below.

Bence