Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 32e4978bb920 ("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>

authored by

Su Hui and committed by
Sebastian Reichel
b55d073e 054eb237

+4 -1
+4 -1
drivers/power/supply/bq256xx_charger.c
··· 1574 1574 wd_reg_val = i; 1575 1575 break; 1576 1576 } 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] && 1578 1579 bq->watchdog_timer < bq256xx_watchdog_time[i + 1]) 1579 1580 wd_reg_val = i; 1580 1581 } 1581 1582 ret = regmap_update_bits(bq->regmap, BQ256XX_CHARGER_CONTROL_1, 1582 1583 BQ256XX_WATCHDOG_MASK, wd_reg_val << 1583 1584 BQ256XX_WDT_BIT_SHIFT); 1585 + if (ret) 1586 + return ret; 1584 1587 1585 1588 ret = power_supply_get_battery_info(bq->charger, &bat_info); 1586 1589 if (ret == -ENOMEM)