Skip to contentSkip to conversation

power: supply: sbs-battery: Fix a signedness bug in sbs_get_battery_capacity()

PATCH In review Dan Carpenter 2 participants 2 messages Sep 25, 2019 – Oct 20, 2019

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

PATCH 1/1 power: supply: sbs-battery: Fix a signedness bug in sbs_get_battery_capacity()

The "mode" variable is an enum and in this context GCC treats it as an unsigned int so the error handling is never triggered.

Fixes 51d075660457 ("bq20z75: Add support for charge properties")
---
 drivers/power/supply/sbs-battery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/sbs-battery.c +1 -1
index f8d74e9f7931..62110af1abcf 100644
@@ -555,7 +555,7 @@ static int sbs_get_battery_capacity(struct i2c_client *client,
 		mode = BATTERY_MODE_AMPS;
 
 	mode = sbs_set_battery_mode(client, mode);
-	if (mode < 0)
+	if ((int)mode < 0)
 		return mode;
 
 	ret = sbs_read_word_data(client, sbs_data[reg_offset].addr);
Signature · 1 line
2.20.1
#1 lore raw

Hi,

Quoted 6 lines · Dan Carpenter

The "mode" variable is an enum and in this context GCC treats it as an unsigned int so the error handling is never triggered.

Fixes 51d075660457 ("bq20z75: Add support for charge properties")

---

Thanks, queued.

-- Sebastian

Quoted 19 lines
 drivers/power/supply/sbs-battery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/sbs-battery.c +1 -1
index f8d74e9f7931..62110af1abcf 100644
@@ -555,7 +555,7 @@ static int sbs_get_battery_capacity(struct i2c_client *client,
 		mode = BATTERY_MODE_AMPS;
 
 	mode = sbs_set_battery_mode(client, mode);
-	if (mode < 0)
+	if ((int)mode < 0)
 		return mode;
 
 	ret = sbs_read_word_data(client, sbs_data[reg_offset].addr);
Signature · 1 line
2.20.1