NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/55206: acpibat reporting broken by acpi_ec.c r1.81



>Number:         55206
>Category:       kern
>Synopsis:       acpibat reporting broken by acpi_ec.c r1.81
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Apr 25 14:35:01 +0000 2020
>Originator:     abs%absd.org@localhost
>Release:        NetBSD 9.99.56
>Organization:
	
>Environment:
System: NetBSD forsaken.absd.org 9.99.56 NetBSD 9.99.56 (GENERIC) #0: Fri Apr 24 22:39:44 BST 2020 abs%iris.absd.org@localhost:/home/netbsd/src/sys/arch/amd64/compile/obj/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
        src/sys/dev/acpi/acpi_ec.c r1.81 looks to break reporting of
        acpibat on at least Thinkpad T430 and T480 (envstat)

Relevant dmesg diff from before and after acpi_ec.c r1.81

@@ -245,9 +245,11 @@
 uhub0: 4 ports with 4 removable, self powered
 uhub1 at usb1: NetBSD (0x0000) xHCI root hub (0x0000), class 9/0, rev 2.00/1.00, addr 0
 uhub1: 4 ports with 4 removable, self powered
+ACPI Error: AE_BAD_PARAMETER, Returned by Handler for [EmbeddedControl] (20200326/evregion-317)
+ACPI Error: Aborting method \_SB.PCI0.LPC.EC.GBIF due to previous error (AE_BAD_PARAMETER) (20200326/psparse-581)
+ACPI Error: Aborting method \_SB.PCI0.LPC.EC.BAT0._BIF due to previous error (AE_BAD_PARAMETER) (20200326/psparse-581)
+acpibat0: autoconfiguration error: failed to evaluate _BIF: AE_ERROR
 acpiacad0: AC adapter online.
-acpibat0: LGC LION rechargeable battery
-acpibat0: granularity: low->warn 0.001 Wh, warn->full 0.001 Wh
 IPsec: Initialized Security Association Processing.
 uhub2 at usb3: NetBSD (0x0000) EHCI root hub (0x0000), class 9/0, rev 2.00/1.00, addr 1
 uhub2: 3 ports with 3 removable, self powered

>How-To-Repeat:
	Boot a recent kernel on a machine with src/sys/dev/acpi/acpi_ec.c

>Fix:

acpi_ec.c r1.81 rejects any request with a width larger than
sizeof(ACPI_INTEGER)*8.

Adjusting it to truncate the width to the maximum value allows acpibat
to attach correctly

Sample patch and different output

acpiacad0: AC adapter online.
autoconfiguration error: acpiecdt0: invalid address space width: 128
autoconfiguration error: acpiecdt0: invalid address space width: 128
acpibat0: LGC LION rechargeable battery

diff --git a/sys/dev/acpi/acpi_ec.c b/sys/dev/acpi/acpi_ec.c
index dcf8a4e5be38..602525d96e79 100644

--- a/sys/dev/acpi/acpi_ec.c
+++ b/sys/dev/acpi/acpi_ec.c
@@ -101,6 +101,8 @@ ACPI_MODULE_NAME            ("acpi_ec")
 #define	EC_STATUS_SCI		0x20
 #define	EC_STATUS_SMI		0x40
 
+#define MAX_ACPIEC_WIDTH	sizeof(ACPI_INTEGER)*8
+
 static const char *ec_hid[] = {
 	"PNP0C09",
 	NULL,
@@ -662,12 +664,18 @@ acpiec_space_handler(uint32_t func, ACPI_PHYSICAL_ADDRESS paddr,
 	uint8_t addr, reg;
 	unsigned int i;
 
-	if (paddr > 0xff || width % 8 != 0 || width > sizeof(ACPI_INTEGER)*8 ||
-	    value == NULL || arg == NULL || paddr + width / 8 > 0x100)
+	dv = arg;
+
+        if (width > MAX_ACPIEC_WIDTH ) {
+          aprint_error("%s: invalid address space width: %d\n",
+              device_xname(dv), width);
+          width = MAX_ACPIEC_WIDTH;
+        }
+	if (paddr > 0xff || width % 8 != 0 || value == NULL ||
+            arg == NULL || paddr + width / 8 > 0x100)
 		return AE_BAD_PARAMETER;
 
 	addr = paddr;
-	dv = arg;
 
 	rv = AE_OK;
 



Home | Main Index | Thread Index | Old Index