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
Unknown Object (File)
Wed, Oct 15, 2:10 AM
Unknown Object (File)
Sat, Oct 4, 2:57 AM
Unknown Object (File)
Wed, Sep 24, 4:31 AM
Unknown Object (File)
Sat, Sep 20, 4:01 PM
Unknown Object (File)
Sep 13 2025, 7:46 PM
Unknown Object (File)
Sep 13 2025, 10:24 AM
Unknown Object (File)
Sep 13 2025, 7:14 AM
Unknown Object (File)
Sep 13 2025, 5:46 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 Passed
Unit
No Test Coverage
Build Status
Buildable 57136
Build 54024: arc lint + arc unit

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