Prevent a division by zero with some broken batteries

This problem was seen on a laptop with a dead battery.
This commit is contained in:
dumbbell 2011-11-26 13:43:50 +00:00
parent 85d58c8854
commit 06e8068f72

View File

@ -205,6 +205,14 @@ acpi_battery_get_battinfo(device_t dev, struct acpi_battinfo *battinfo)
bif->lfcap = (bif->lfcap * bif->dvol) / 1000;
}
/*
* The calculation above may set bif->lfcap to zero. This was
* seen on a laptop with a broken battery. The result of the
* division was rounded to zero.
*/
if (!acpi_battery_bif_valid(bif))
continue;
/* Calculate percent capacity remaining. */
bi[i].cap = (100 * bst[i].cap) / bif->lfcap;