Module Name: src Committed By: jruoho Date: Fri Jun 3 18:50:36 UTC 2011
Modified Files: src/sys/dev/acpi: acpi_pmtr.c Log Message: Add locking to account improbable but possible race between the notify handler and sysmon_envsys(9)'s refresh routine. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/acpi_pmtr.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_pmtr.c diff -u src/sys/dev/acpi/acpi_pmtr.c:1.3 src/sys/dev/acpi/acpi_pmtr.c:1.4 --- src/sys/dev/acpi/acpi_pmtr.c:1.3 Wed Feb 16 09:05:12 2011 +++ src/sys/dev/acpi/acpi_pmtr.c Fri Jun 3 18:50:36 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_pmtr.c,v 1.3 2011/02/16 09:05:12 jruoho Exp $ */ +/* $NetBSD: acpi_pmtr.c,v 1.4 2011/06/03 18:50:36 jruoho Exp $ */ /*- * Copyright (c) 2011 Jukka Ruohonen <jruoho...@iki.fi> @@ -27,10 +27,11 @@ * SUCH DAMAGE. */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: acpi_pmtr.c,v 1.3 2011/02/16 09:05:12 jruoho Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_pmtr.c,v 1.4 2011/06/03 18:50:36 jruoho Exp $"); #include <sys/param.h> #include <sys/module.h> +#include <sys/mutex.h> #include <dev/acpi/acpireg.h> #include <dev/acpi/acpivar.h> @@ -79,6 +80,7 @@ envsys_data_t sc_sensor_o; uint32_t sc_cap[ACPIPMTR_CAP_COUNT]; int32_t sc_interval; + kmutex_t sc_mtx; }; const char * const acpi_pmtr_ids[] = { @@ -128,6 +130,7 @@ aprint_normal(": ACPI Power Meter\n"); (void)pmf_device_register(self, NULL, NULL); + mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NONE); if (acpipmtr_cap_get(self, true) != true) return; @@ -162,6 +165,8 @@ if (sc->sc_sme != NULL) sysmon_envsys_unregister(sc->sc_sme); + mutex_destroy(&sc->sc_mtx); + return 0; } @@ -369,6 +374,8 @@ { struct acpipmtr_softc *sc = device_private(self); + mutex_enter(&sc->sc_mtx); + switch (sc->sc_cap[ACPIPMTR_CAP_TYPE]) { case ACPIPMTR_POWER_INPUT: @@ -386,6 +393,8 @@ sc->sc_sensor_o.state = ENVSYS_SINVALID; break; } + + mutex_exit(&sc->sc_mtx); } static int32_t @@ -462,8 +471,14 @@ case ACPIPMTR_NOTIFY_CAP: - if (acpipmtr_cap_get(self, false) != true) + mutex_enter(&sc->sc_mtx); + + if (acpipmtr_cap_get(self, false) != true) { + mutex_exit(&sc->sc_mtx); break; + } + + mutex_exit(&sc->sc_mtx); acpipmtr_sensor_type(self); break;