diff options
author | Andreas Kemnade <andreas@kemnade.info> | 2018-09-17 07:20:35 +0200 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2018-09-20 02:15:41 +0200 |
commit | 8314c212f995bc0d06b54ad02ef0ab4089781540 (patch) | |
tree | 5f3db3db4f652fd179cf26beeb86eb7ec68bff5c /drivers/power | |
parent | ad1570d99f280f73c72510d7f79db9adf599474b (diff) |
power: supply: twl4030_charger: fix charging current out-of-bounds
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>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/supply/twl4030_charger.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/power/supply/twl4030_charger.c b/drivers/power/supply/twl4030_charger.c index bbcaee56db9d..c629c1642531 100644 --- a/drivers/power/supply/twl4030_charger.c +++ b/drivers/power/supply/twl4030_charger.c @@ -420,7 +420,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) { |