aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Lindgren <tony@atomide.com>2019-04-07 11:12:48 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-05-25 18:22:25 +0200
commit04aa8a51e7230e9e84ddc6a52b9934394a47d31e (patch)
tree91694ea1a080f3505465b26ca390c123bef769e0
parent38a725dd0be77e83b6b546b2060d7f37512f83e5 (diff)
downloadlinux-yocto-04aa8a51e7230e9e84ddc6a52b9934394a47d31e.tar.gz
linux-yocto-04aa8a51e7230e9e84ddc6a52b9934394a47d31e.tar.bz2
linux-yocto-04aa8a51e7230e9e84ddc6a52b9934394a47d31e.zip
power: supply: cpcap-battery: Fix division by zero
[ Upstream commit dbe7208c6c4aec083571f2ec742870a0d0edbea3 ] If called fast enough so samples do not increment, we can get division by zero in kernel: __div0 cpcap_battery_cc_raw_div cpcap_battery_get_property power_supply_get_property.part.1 power_supply_get_property power_supply_show_property power_supply_uevent Fixes: 874b2adbed12 ("power: supply: cpcap-battery: Add a battery driver") Signed-off-by: Tony Lindgren <tony@atomide.com> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/power/supply/cpcap-battery.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
index 08d5037fd052..6887870ba32c 100644
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -221,6 +221,9 @@ static int cpcap_battery_cc_raw_div(struct cpcap_battery_ddata *ddata,
int avg_current;
u32 cc_lsb;
+ if (!divider)
+ return 0;
+
sample &= 0xffffff; /* 24-bits, unsigned */
offset &= 0x7ff; /* 10-bits, signed */