Refactor slightly and bump WARNS to 4.

This commit is contained in:
jruoho 2010-10-26 03:11:10 +00:00
parent 6e39448e16
commit 6b1e267f66
2 changed files with 45 additions and 42 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: atk0110.c,v 1.13 2010/10/25 17:06:58 jruoho Exp $ */ /* $NetBSD: atk0110.c,v 1.14 2010/10/26 03:11:10 jruoho Exp $ */
/* $OpenBSD: atk0110.c,v 1.1 2009/07/23 01:38:16 cnst Exp $ */ /* $OpenBSD: atk0110.c,v 1.1 2009/07/23 01:38:16 cnst Exp $ */
/* /*
@ -18,7 +18,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: atk0110.c,v 1.13 2010/10/25 17:06:58 jruoho Exp $"); __KERNEL_RCSID(0, "$NetBSD: atk0110.c,v 1.14 2010/10/26 03:11:10 jruoho Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/malloc.h> #include <sys/malloc.h>
@ -43,8 +43,6 @@ __KERNEL_RCSID(0, "$NetBSD: atk0110.c,v 1.13 2010/10/25 17:06:58 jruoho Exp $");
#define _COMPONENT ACPI_RESOURCE_COMPONENT #define _COMPONENT ACPI_RESOURCE_COMPONENT
ACPI_MODULE_NAME ("acpi_aibs") ACPI_MODULE_NAME ("acpi_aibs")
#define AIBS_MORE_SENSORS
struct aibs_sensor { struct aibs_sensor {
envsys_data_t s; envsys_data_t s;
ACPI_INTEGER i; ACPI_INTEGER i;
@ -138,14 +136,15 @@ static void
aibs_attach_sif(device_t self, enum envsys_units st) aibs_attach_sif(device_t self, enum envsys_units st)
{ {
struct aibs_softc *sc = device_private(self); struct aibs_softc *sc = device_private(self);
ACPI_STATUS s; ACPI_OBJECT *bp, *o, *oi;
ACPI_BUFFER b; ACPI_BUFFER b;
ACPI_OBJECT *bp, *o; ACPI_STATUS rv;
int i, n; uint32_t i, n;
char name[] = "?SIF"; char name[] = "?SIF";
struct aibs_sensor *as; struct aibs_sensor *as;
switch (st) { switch (st) {
case ENVSYS_STEMP: case ENVSYS_STEMP:
name[0] = 'T'; name[0] = 'T';
break; break;
@ -159,50 +158,51 @@ aibs_attach_sif(device_t self, enum envsys_units st)
return; return;
} }
b.Length = ACPI_ALLOCATE_BUFFER; rv = acpi_eval_struct(sc->sc_node->ad_handle, name, &b);
s = AcpiEvaluateObjectTyped(sc->sc_node->ad_handle, name, NULL, &b,
ACPI_TYPE_PACKAGE); if (ACPI_FAILURE(rv))
if (ACPI_FAILURE(s)) { goto out;
aprint_error_dev(self, "%s not found\n", name);
return;
}
bp = b.Pointer; bp = b.Pointer;
if (bp->Type != ACPI_TYPE_PACKAGE) {
rv = AE_TYPE;
goto out;
}
o = bp->Package.Elements; o = bp->Package.Elements;
if (o[0].Type != ACPI_TYPE_INTEGER) { if (o[0].Type != ACPI_TYPE_INTEGER) {
aprint_error_dev(self, "%s[0]: invalid type\n", name); rv = AE_TYPE;
ACPI_FREE(b.Pointer); goto out;
return; }
if (o[0].Integer.Value > UINT32_MAX) {
rv = AE_AML_NUMERIC_OVERFLOW;
goto out;
} }
n = o[0].Integer.Value; n = o[0].Integer.Value;
if (bp->Package.Count - 1 < n) {
aprint_error_dev(self, "%s: invalid package\n", name);
ACPI_FREE(b.Pointer);
return;
} else if (bp->Package.Count - 1 > n) {
int on = n;
#ifdef AIBS_MORE_SENSORS if (n == 0) {
n = bp->Package.Count - 1; rv = AE_LIMIT;
#endif goto out;
aprint_error_dev(self, "%s: malformed package: %i/%i"
", assume %i\n", name, on, bp->Package.Count - 1, n);
} }
if (n < 1) {
aprint_error_dev(self, "%s: no members in the package\n", if (bp->Package.Count - 1 != n) {
name); rv = AE_BAD_VALUE;
ACPI_FREE(b.Pointer); goto out;
return;
} }
as = malloc(sizeof(*as) * n, M_DEVBUF, M_NOWAIT | M_ZERO); as = malloc(sizeof(*as) * n, M_DEVBUF, M_NOWAIT | M_ZERO);
if (as == NULL) { if (as == NULL) {
aprint_error_dev(self, "%s: malloc fail\n", name); rv = AE_NO_MEMORY;
ACPI_FREE(b.Pointer); goto out;
return;
} }
switch (st) { switch (st) {
case ENVSYS_STEMP: case ENVSYS_STEMP:
sc->sc_asens_temp = as; sc->sc_asens_temp = as;
break; break;
@ -218,9 +218,7 @@ aibs_attach_sif(device_t self, enum envsys_units st)
} }
for (i = 0, o++; i < n; i++, o++) { for (i = 0, o++; i < n; i++, o++) {
ACPI_OBJECT *oi;
/* acpica5 automatically evaluates the referenced package */
if(o[0].Type != ACPI_TYPE_PACKAGE) { if(o[0].Type != ACPI_TYPE_PACKAGE) {
aprint_error_dev(self, aprint_error_dev(self,
"%s: %i: not a package: %u type\n", "%s: %i: not a package: %u type\n",
@ -257,8 +255,13 @@ aibs_attach_sif(device_t self, enum envsys_units st)
name[0], i); name[0], i);
} }
ACPI_FREE(b.Pointer); out:
return; if (b.Pointer != NULL)
ACPI_FREE(b.Pointer);
if (ACPI_FAILURE(rv))
aprint_error_dev(self, "failed to evaluate %s: %s\n",
name, AcpiFormatException(rv));
} }
static int static int

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.1 2010/10/25 17:17:57 jruoho Exp $ # $NetBSD: Makefile,v 1.2 2010/10/26 03:11:10 jruoho Exp $
.include "../Makefile.inc" .include "../Makefile.inc"
@ -8,6 +8,6 @@ KMOD= aibs
IOCONF= AIBS.ioconf IOCONF= AIBS.ioconf
SRCS= atk0110.c SRCS= atk0110.c
WARNS= 3 WARNS= 4
.include <bsd.kmodule.mk> .include <bsd.kmodule.mk>