summaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
authorRicardo Rivera-Matos <r-rivera-matos@ti.com>2021-01-13 16:53:52 -0600
committerSebastian Reichel <sre@kernel.org>2021-01-14 23:38:56 +0100
commitc3f1813516477c014d41e207d95190daf0838107 (patch)
tree628f48c8d5f43a0c2a62330c8fd7b90ec70cf4cd /drivers/power
parentb059b48500dab78cb6c7be006280dbc001c0a46b (diff)
power: supply: bq256xx: Fix BQ256XX_NUM_WD_VAL and bq256xx_watchdog_time[] overrun
Corrects BQ256XX_NUM_WD_VAL from value of "8" to "4" and fixes the issue when 'i' is equal to array size then array index over runs the array Fixes: 32e4978bb920 ("power: supply: bq256xx: Introduce the BQ256XX charger driver") Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Ricardo Rivera-Matos <r-rivera-matos@ti.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/supply/bq256xx_charger.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/power/supply/bq256xx_charger.c b/drivers/power/supply/bq256xx_charger.c
index 6d1c524743d4..2ab5ba4af92b 100644
--- a/drivers/power/supply/bq256xx_charger.c
+++ b/drivers/power/supply/bq256xx_charger.c
@@ -135,7 +135,7 @@
#define BQ256XX_NTC_FAULT_COLD (BIT(2) | BIT(0))
#define BQ256XX_NTC_FAULT_HOT (BIT(2) | BIT(1))
-#define BQ256XX_NUM_WD_VAL 8
+#define BQ256XX_NUM_WD_VAL 4
#define BQ256XX_WATCHDOG_MASK GENMASK(5, 4)
#define BQ256XX_WATCHDOG_MAX 1600000
#define BQ256XX_WATCHDOG_DIS 0
@@ -1508,6 +1508,10 @@ static int bq256xx_hw_init(struct bq256xx_device *bq)
int i;
for (i = 0; i < BQ256XX_NUM_WD_VAL; i++) {
+ if (bq->watchdog_timer == bq256xx_watchdog_time[i]) {
+ wd_reg_val = i;
+ break;
+ }
if (bq->watchdog_timer > bq256xx_watchdog_time[i] &&
bq->watchdog_timer < bq256xx_watchdog_time[i + 1])
wd_reg_val = i;