diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2018-07-11 10:58:13 +0300 |
---|---|---|
committer | Sebastian Reichel <sebastian.reichel@collabora.co.uk> | 2018-07-11 13:00:24 +0300 |
commit | 89b135ba1b73cd54a09283b39420c90538283801 (patch) | |
tree | 12bf6bd0072c583b35ebb46a5c336985da670fd2 /drivers/power | |
parent | 7914c67667a06d7b5dbc297dfff49285b9c3a0d4 (diff) | |
download | linux-89b135ba1b73cd54a09283b39420c90538283801.tar.xz |
power: supply: adp5061: Fix a couple off by ones
We end up reading one element beyond the end of the adp5061_vmax[] array
here.
Fixes: fe8e81b7e899 ("adp5061: New driver for ADP5061 I2C battery charger")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/supply/adp5061.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/power/supply/adp5061.c b/drivers/power/supply/adp5061.c index c00a02ef7424..939fd3d8fb1a 100644 --- a/drivers/power/supply/adp5061.c +++ b/drivers/power/supply/adp5061.c @@ -266,8 +266,8 @@ static int adp5061_get_max_voltage(struct adp5061_state *st, return ret; regval = ((regval & ADP5061_TERM_SET_VTRM_MSK) >> 2) - 0x0F; - if (regval > ARRAY_SIZE(adp5061_vmax)) - regval = ARRAY_SIZE(adp5061_vmax); + if (regval >= ARRAY_SIZE(adp5061_vmax)) + regval = ARRAY_SIZE(adp5061_vmax) - 1; val->intval = adp5061_vmax[regval] * 1000; @@ -344,8 +344,8 @@ static int adp5061_get_const_chg_current(struct adp5061_state *st, return ret; regval = ((regval & ADP5061_CHG_CURR_ICHG_MSK) >> 2); - if (regval > ARRAY_SIZE(adp5061_const_ichg)) - regval = ARRAY_SIZE(adp5061_const_ichg); + if (regval >= ARRAY_SIZE(adp5061_const_ichg)) + regval = ARRAY_SIZE(adp5061_const_ichg) - 1; val->intval = adp5061_const_ichg[regval] * 1000; |