Module Name:    src
Committed By:   mlelstv
Date:           Wed Dec 31 22:01:01 UTC 2014

Modified Files:
        src/sys/dev/acpi: acpi_bat.c

Log Message:
handle unknown values. Also BIF_UNIT is an enum, not a bitmask.


To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 src/sys/dev/acpi/acpi_bat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_bat.c
diff -u src/sys/dev/acpi/acpi_bat.c:1.113 src/sys/dev/acpi/acpi_bat.c:1.114
--- src/sys/dev/acpi/acpi_bat.c:1.113	Thu Oct  2 12:42:12 2014
+++ src/sys/dev/acpi/acpi_bat.c	Wed Dec 31 22:01:01 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_bat.c,v 1.113 2014/10/02 12:42:12 riastradh Exp $	*/
+/*	$NetBSD: acpi_bat.c,v 1.114 2014/12/31 22:01:01 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.113 2014/10/02 12:42:12 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.114 2014/12/31 22:01:01 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/condvar.h>
@@ -381,18 +381,22 @@ acpibat_get_info(device_t dv)
 			goto out;
 		}
 
-		if (elm[i].Integer.Value >= INT_MAX) {
+		if (elm[i].Integer.Value != ACPIBAT_VAL_UNKNOWN &&
+		    elm[i].Integer.Value >= INT_MAX) {
 			rv = AE_LIMIT;
 			goto out;
 		}
 	}
 
-	if ((elm[ACPIBAT_BIF_UNIT].Integer.Value & ACPIBAT_PWRUNIT_MA) != 0) {
+	switch (elm[ACPIBAT_BIF_UNIT].Integer.Value) {
+	case ACPIBAT_PWRUNIT_MA:
 		capunit = ENVSYS_SAMPHOUR;
 		rateunit = ENVSYS_SAMPS;
-	} else {
+		break;
+	default:
 		capunit = ENVSYS_SWATTHOUR;
 		rateunit = ENVSYS_SWATTS;
+		break;
 	}
 
 	sc->sc_sensor[ACPIBAT_DCAPACITY].units = capunit;
@@ -500,10 +504,14 @@ acpibat_print_info(device_t dv, ACPI_OBJ
 	 * Granularity 2.	"Battery capacity granularity between warning
 	 *			 and full in [mAh] or [mWh]. [...]"
 	 */
-	if ((elm[ACPIBAT_BIF_UNIT].Integer.Value & ACPIBAT_PWRUNIT_MA) != 0)
+	switch (elm[ACPIBAT_BIF_UNIT].Integer.Value) {
+	case ACPIBAT_PWRUNIT_MA:
 		unit = "Ah";
-	else
+		break;
+	default:
 		unit = "Wh";
+		break;
+	}
 
 	aprint_verbose_dev(dv, "granularity: "
 	    "low->warn %d.%03d %s, warn->full %d.%03d %s\n",

Reply via email to