HomeFreeBSD

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

Description

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

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 by: Stefano Marinelli
Tested by: Stefano Marinelli
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D44818

(cherry picked from commit 2e850b832f5d2adb9b230d191277d67c00caaab9)
(cherry picked from commit 788987e034b1c73d779a3aa179f79f672bbdb366)

Details

Provenance
jeffpc_josefsipek.netAuthored on Tue, Apr 16, 11:01 PM
emasteCommitted on Wed, Apr 24, 2:06 PM
Reviewer
emaste
Differential Revision
D44818: acpi_battery: avoid divide-by-zero when no devices have capacity info
Parents
rGe03c9c311e89: arm: Fix a typo in a KASSERT message
Branches
Unknown
Tags
Unknown