Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: ip5xxx: Fix integer overflow in current_now calculation

When current is larger than ~2A, the multiplication in current_now
property overflows and the kernel reports invalid negative current
value. Change the numerator and denominator while preserving their
ratio to allow up to +-6A before the overflow.

Fixes: 75853406fa27 ("power: supply: Add a driver for Injoinic power bank ICs")
Signed-off-by: Ondrej Jirman <megi@xff.cz>
Reviewed-by: Samuel Holland <samuel@sholland.org>
[use 149197/200 instead of 261095/350 as suggested by Samuel]
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Ondrej Jirman and committed by
Sebastian Reichel
f9be5cb6 883babd4

+1 -1
+1 -1
drivers/power/supply/ip5xxx_power.c
··· 352 352 ret = ip5xxx_battery_read_adc(ip5xxx, IP5XXX_BATIADC_DAT0, 353 353 IP5XXX_BATIADC_DAT1, &raw); 354 354 355 - val->intval = DIV_ROUND_CLOSEST(raw * 745985, 1000); 355 + val->intval = DIV_ROUND_CLOSEST(raw * 149197, 200); 356 356 return 0; 357 357 358 358 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT: