Page MenuHomeFreeBSD

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

Authored by jeffpc_josefsipek.net on Apr 16 2024, 10:34 PM.
Tags
None
Referenced Files
F102076660: D44818.id.diff
Thu, Nov 7, 8:14 AM
Unknown Object (File)
Tue, Nov 5, 10:59 AM
Unknown Object (File)
Sun, Oct 27, 6:14 PM
Unknown Object (File)
Sat, Oct 19, 9:34 PM
Unknown Object (File)
Thu, Oct 17, 11:27 PM
Unknown Object (File)
Wed, Oct 16, 4:12 PM
Unknown Object (File)
Tue, Oct 15, 8:33 PM
Unknown Object (File)
Tue, Oct 15, 8:02 PM
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.Apr 16 2024, 11:00 PM