mirror of
https://github.com/freebsd/freebsd-src
synced 2024-11-05 18:22:52 +00:00
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 commit2e850b832f
) (cherry picked from commit788987e034
)
This commit is contained in:
parent
e03c9c311e
commit
1a4e512adb
1 changed files with 8 additions and 1 deletions
|
@ -266,7 +266,14 @@ acpi_battery_get_battinfo(device_t dev, struct acpi_battinfo *battinfo)
|
|||
*/
|
||||
if (valid_units > 0) {
|
||||
if (dev == NULL) {
|
||||
battinfo->cap = (total_cap * 100) / total_lfcap;
|
||||
/*
|
||||
* Avoid division by zero if none of the batteries had valid
|
||||
* capacity info.
|
||||
*/
|
||||
if (total_lfcap > 0)
|
||||
battinfo->cap = (total_cap * 100) / total_lfcap;
|
||||
else
|
||||
battinfo->cap = 0;
|
||||
battinfo->min = total_min;
|
||||
battinfo->state = batt_stat;
|
||||
battinfo->rate = valid_rate;
|
||||
|
|
Loading…
Reference in a new issue