Module Name: src Committed By: jruoho Date: Sun Jan 31 06:45:10 UTC 2010
Modified Files: src/sys/dev/acpi: acpi_bat.c Log Message: Allocate the sensor structures dynamically. To generate a diff of this commit: cvs rdiff -u -r1.80 -r1.81 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.80 src/sys/dev/acpi/acpi_bat.c:1.81 --- src/sys/dev/acpi/acpi_bat.c:1.80 Sun Jan 31 06:10:53 2010 +++ src/sys/dev/acpi/acpi_bat.c Sun Jan 31 06:45:09 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_bat.c,v 1.80 2010/01/31 06:10:53 jruoho Exp $ */ +/* $NetBSD: acpi_bat.c,v 1.81 2010/01/31 06:45:09 jruoho Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -75,11 +75,12 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.80 2010/01/31 06:10:53 jruoho Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.81 2010/01/31 06:45:09 jruoho Exp $"); #include <sys/param.h> #include <sys/systm.h> #include <sys/kernel.h> /* for hz */ +#include <sys/kmem.h> #include <sys/device.h> #include <sys/mutex.h> @@ -149,7 +150,7 @@ struct acpi_devnode *sc_node; struct sysmon_envsys *sc_sme; struct timeval sc_lastupdate; - envsys_data_t sc_sensor[ACPIBAT_COUNT]; + envsys_data_t *sc_sensor; kmutex_t sc_mutex; kcondvar_t sc_condvar; int sc_present; @@ -236,7 +237,9 @@ sc->sc_node = aa->aa_node; sc->sc_present = 0; + sc->sc_sme = NULL; + sc->sc_sensor = NULL; mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_NONE); cv_init(&sc->sc_condvar, device_xname(self)); @@ -247,10 +250,18 @@ rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle, ACPI_ALL_NOTIFY, acpibat_notify_handler, self); - if (ACPI_SUCCESS(rv)) - acpibat_init_envsys(self); - else + if (ACPI_FAILURE(rv)) { aprint_error_dev(self, "couldn't install notify handler\n"); + return; + } + + sc->sc_sensor = kmem_zalloc(ACPIBAT_COUNT * + sizeof(*sc->sc_sensor), KM_SLEEP); + + if (sc->sc_sensor == NULL) + return; + + acpibat_init_envsys(self); } /* @@ -276,6 +287,10 @@ if (sc->sc_sme != NULL) sysmon_envsys_unregister(sc->sc_sme); + if (sc->sc_sensor != NULL) + kmem_free(sc->sc_sensor, ACPIBAT_COUNT * + sizeof(*sc->sc_sensor)); + pmf_device_deregister(self); return 0; @@ -723,8 +738,12 @@ fail: aprint_error_dev(dv, "failed to initialize sysmon\n"); + sysmon_envsys_destroy(sc->sc_sme); + kmem_free(sc->sc_sensor, ACPIBAT_COUNT * sizeof(*sc->sc_sensor)); + sc->sc_sme = NULL; + sc->sc_sensor = NULL; } static void