Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dbe7208c authored by Tony Lindgren's avatar Tony Lindgren Committed by Sebastian Reichel
Browse files

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: 874b2adb ("power: supply: cpcap-battery: Add a battery driver")
Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
Acked-by: default avatarPavel Machek <pavel@ucw.cz>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 9e98c678
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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 */