diff options
| author | Tony Lindgren <tony@atomide.com> | 2019-04-07 14:12:48 -0400 |
|---|---|---|
| committer | Sebastian Reichel <sre@kernel.org> | 2019-04-09 18:53:20 -0400 |
| commit | dbe7208c6c4aec083571f2ec742870a0d0edbea3 (patch) | |
| tree | c4b36fe416c4a6054f12bc6f42541ba08bdb4a2e | |
| parent | 9e98c678c2d6ae3a17cb2de55d17f69dddaa231b (diff) | |
power: supply: cpcap-battery: Fix division by zero
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>
| -rw-r--r-- | drivers/power/supply/cpcap-battery.c | 3 |
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, | |||
| 221 | int avg_current; | 221 | int avg_current; |
| 222 | u32 cc_lsb; | 222 | u32 cc_lsb; |
| 223 | 223 | ||
| 224 | if (!divider) | ||
| 225 | return 0; | ||
| 226 | |||
| 224 | sample &= 0xffffff; /* 24-bits, unsigned */ | 227 | sample &= 0xffffff; /* 24-bits, unsigned */ |
| 225 | offset &= 0x7ff; /* 10-bits, signed */ | 228 | offset &= 0x7ff; /* 10-bits, signed */ |
| 226 | 229 | ||
