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
F163319555: D44818.diff
Wed, Jul 22, 2:00 AM
Unknown Object (File)
Mon, Jul 20, 9:41 PM
Unknown Object (File)
Mon, Jul 20, 4:47 PM
Unknown Object (File)
Wed, Jul 15, 10:40 PM
Unknown Object (File)
Tue, Jul 7, 10:37 PM
Unknown Object (File)
Fri, Jul 3, 12:33 PM
Unknown Object (File)
Fri, Jul 3, 8:12 AM
Unknown Object (File)
Fri, Jul 3, 6:25 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.Apr 16 2024, 11:00 PM