Skip to content

Commit b55d073

Browse files
Su Huisre
authored andcommitted
power: supply: bq256xx: fix some problem in bq256xx_hw_init
smatch complains that there is a buffer overflow and clang complains 'ret' is never read. Smatch error: drivers/power/supply/bq256xx_charger.c:1578 bq256xx_hw_init() error: buffer overflow 'bq256xx_watchdog_time' 4 <= 4 Clang static checker: Value stored to 'ret' is never read. Add check for buffer overflow and error code from regmap_update_bits(). Fixes: 32e4978 ("power: supply: bq256xx: Introduce the BQ256XX charger driver") Signed-off-by: Su Hui <suhui@nfschina.com> Link: https://lore.kernel.org/r/20231116041822.1378758-1-suhui@nfschina.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent 054eb23 commit b55d073

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

drivers/power/supply/bq256xx_charger.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,13 +1574,16 @@ static int bq256xx_hw_init(struct bq256xx_device *bq)
15741574
wd_reg_val = i;
15751575
break;
15761576
}
1577-
if (bq->watchdog_timer > bq256xx_watchdog_time[i] &&
1577+
if (i + 1 < BQ256XX_NUM_WD_VAL &&
1578+
bq->watchdog_timer > bq256xx_watchdog_time[i] &&
15781579
bq->watchdog_timer < bq256xx_watchdog_time[i + 1])
15791580
wd_reg_val = i;
15801581
}
15811582
ret = regmap_update_bits(bq->regmap, BQ256XX_CHARGER_CONTROL_1,
15821583
BQ256XX_WATCHDOG_MASK, wd_reg_val <<
15831584
BQ256XX_WDT_BIT_SHIFT);
1585+
if (ret)
1586+
return ret;
15841587

15851588
ret = power_supply_get_battery_info(bq->charger, &bat_info);
15861589
if (ret == -ENOMEM)

0 commit comments

Comments
 (0)