summaryrefslogtreecommitdiff
path: root/drivers/power
diff options
context:
space:
mode:
authorAndreas Kemnade <andreas@kemnade.info>2018-09-17 08:20:35 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-11-25 11:52:32 +0300
commitd6e9e55c0dcf0db0d18a360e67ac30c2276aa09c (patch)
tree06032b90e9140e908bbdbda8847be72a070bbc7c /drivers/power
parent63ce52b6ee1685f3a3bac8e62dd526662adc89a3 (diff)
downloadlinux-d6e9e55c0dcf0db0d18a360e67ac30c2276aa09c.tar.xz
power: supply: twl4030_charger: fix charging current out-of-bounds
[ Upstream commit 8314c212f995bc0d06b54ad02ef0ab4089781540 ] the charging current uses unsigned int variables, if we step back if the current is still low, we would run into negative which means setting the target to a huge value. Better add checks here. Signed-off-by: Andreas Kemnade <andreas@kemnade.info> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/supply/twl4030_charger.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/supply/twl4030_charger.c
index bcd4dc304f27..14fed11e8f6e 100644
--- a/drivers/power/supply/twl4030_charger.c
+++ b/drivers/power/supply/twl4030_charger.c
@@ -449,7 +449,8 @@ static void twl4030_current_worker(struct work_struct *data)
if (v < USB_MIN_VOLT) {
/* Back up and stop adjusting. */
- bci->usb_cur -= USB_CUR_STEP;
+ if (bci->usb_cur >= USB_CUR_STEP)
+ bci->usb_cur -= USB_CUR_STEP;
bci->usb_cur_target = bci->usb_cur;
} else if (bci->usb_cur >= bci->usb_cur_target ||
bci->usb_cur + USB_CUR_STEP > USB_MAX_CURRENT) {