Page MenuHomeFreeBSD

acpi_battery: avoid divide-by-zero when no devices have capacity info
ClosedPublic

Authored by jeffpc_josefsipek.net on Tue, Apr 16, 10:34 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, May 9, 11:18 AM
Unknown Object (File)
Mon, May 6, 7:47 PM
Unknown Object (File)
Fri, Apr 26, 5:15 AM
Unknown Object (File)
Sat, Apr 20, 6:14 PM
Unknown Object (File)
Wed, Apr 17, 8:47 PM
Unknown Object (File)
Wed, Apr 17, 8:45 PM
Unknown Object (File)
Wed, Apr 17, 5:43 PM
Unknown Object (File)
Wed, Apr 17, 12:31 AM
Subscribers

Details

Summary

On laptops with builtin batteries, disconnecting the battery may show up as
a battery without any capacity information. (The theory is that one is
disconnecting the cells but the electronics identifying the battery are
still connected.) As a result, the loop over all batteries in
acpi_battery_get_battinfo results in total_lfcap == 0.

So, just check that total_lfcap is non-zero to avoid a division by zero
(triggerable by sysctl hw.acpi.battery).

Reported/tested by: Stefano Marinelli

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/dev/acpica/acpi_battery.c
273

style(9) asks to avoid using non-booleans in a boolean context, so total_lfcap != 0 -- but then, we probably want total_lfcap > 0 since -ve values don't make sense. I'd also suggest an if-else like just above for valid_rate rather than the ternary op.

This revision is now accepted and ready to land.Tue, Apr 16, 11:00 PM