Skip to content

Commit

Permalink
power: supply: cpcap-battery: Fix division by zero
Browse files Browse the repository at this point in the history
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: 874b2ad ("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>
  • Loading branch information
Tony Lindgren authored and Sebastian Reichel committed Apr 9, 2019
1 parent 9e98c67 commit dbe7208
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/power/supply/cpcap-battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down

0 comments on commit dbe7208

Please sign in to comment.