Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/acpi Add locking to account improbable but possible ...



details:   https://anonhg.NetBSD.org/src/rev/1489a20b44e8
branches:  trunk
changeset: 765719:1489a20b44e8
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Fri Jun 03 18:50:36 2011 +0000

description:
Add locking to account improbable but possible race between the notify
handler and sysmon_envsys(9)'s refresh routine.

diffstat:

 sys/dev/acpi/acpi_pmtr.c |  21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diffs (81 lines):

diff -r f62aa025cb46 -r 1489a20b44e8 sys/dev/acpi/acpi_pmtr.c
--- a/sys/dev/acpi/acpi_pmtr.c  Fri Jun 03 18:43:38 2011 +0000
+++ b/sys/dev/acpi/acpi_pmtr.c  Fri Jun 03 18:50:36 2011 +0000
@@ -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 <jruohonen%iki.fi@localhost>
@@ -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;



Home | Main Index | Thread Index | Old Index