summaryrefslogtreecommitdiffstats
path: root/sys/dev
diff options
context:
space:
mode:
authordumbbell <dumbbell@FreeBSD.org>2011-11-26 13:43:50 +0000
committerdumbbell <dumbbell@FreeBSD.org>2011-11-26 13:43:50 +0000
commit06e8068f727d20085e56d3ea79913edf5b1dce44 (patch)
tree49c50e17c5cf95969430d22e4ae31b94ad14fbf3 /sys/dev
parent85d58c885455bf5b3bbe3d4ff65e93d6d4682de7 (diff)
downloadFreeBSD-src-06e8068f727d20085e56d3ea79913edf5b1dce44.zip
FreeBSD-src-06e8068f727d20085e56d3ea79913edf5b1dce44.tar.gz
Prevent a division by zero with some broken batteries
This problem was seen on a laptop with a dead battery.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/acpica/acpi_battery.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/sys/dev/acpica/acpi_battery.c b/sys/dev/acpica/acpi_battery.c
index ba57853..3d7d94a 100644
--- a/sys/dev/acpica/acpi_battery.c
+++ b/sys/dev/acpica/acpi_battery.c
@@ -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;
OpenPOWER on IntegriCloud