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

ds2760_battery: Fix integer overflow for time_to_empty_now

On the device we're currently developing, battery sizes of ~2.8Ah and
current flow of ~600mA are typical.

With that values, the life_sec computation overflows due to the
multiplication by 3600.

Signed-off-by: Daniel Mack <daniel@caiaq.de>
Cc: Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>
Cc: Matt Reimer <mreimer@vpop.net>
Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>

authored by

Daniel Mack and committed by
Anton Vorontsov
b0525b48 83a8af0d

+3 -3
+3 -3
drivers/power/ds2760_battery.c
··· 211 211 if (di->rem_capacity > 100) 212 212 di->rem_capacity = 100; 213 213 214 - if (di->current_uA) 215 - di->life_sec = -((di->accum_current_uAh - di->empty_uAh) * 216 - 3600L) / di->current_uA; 214 + if (di->current_uA >= 100L) 215 + di->life_sec = -((di->accum_current_uAh - di->empty_uAh) * 36L) 216 + / (di->current_uA / 100L); 217 217 else 218 218 di->life_sec = 0; 219 219