Source-Changes-HG archive

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

[.joined/src/trunk]: .joined/src/sys/dev/acpi acpibat(4): Fix attach and deta...



details:   https://anonhg.NetBSD.org/.joined/src/rev/8ab72995ee38
branches:  trunk
changeset: 359332:8ab72995ee38
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Fri Dec 31 14:20:24 2021 +0000

description:
acpibat(4): Fix attach and detach ordering.

On attach: Don't register acpibat_resume handler with pmf or
acpibat_notify_handler with acpi until it is safe to call
acpibat_update_info and acpibat_update_status.
=> This requires the sc->sc_sensor array to be allocated, so allocate
   that first.
=> This requires sc->sc_sme to be created, so defer them to
   config_interrupts after sysmon_envsys_register.
=> Make sure to register the notify handler before initially polling
   the info and status.

On detach: Deregister pmf handler and acpi notifier before we destroy
anything.

diffstat:

 sys/dev/acpi/acpi_bat.c |  21 ++++++++-------------
 1 files changed, 8 insertions(+), 13 deletions(-)

diffs (78 lines):

diff -r e03b62c72cb9 -r 8ab72995ee38 sys/dev/acpi/acpi_bat.c
--- a/sys/dev/acpi/acpi_bat.c   Fri Dec 31 14:19:57 2021 +0000
+++ b/sys/dev/acpi/acpi_bat.c   Fri Dec 31 14:20:24 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_bat.c,v 1.117 2021/01/29 15:20:13 thorpej Exp $   */
+/*     $NetBSD: acpi_bat.c,v 1.118 2021/12/31 14:20:24 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.117 2021/01/29 15:20:13 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.118 2021/12/31 14:20:24 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/condvar.h>
@@ -235,20 +235,13 @@
        sc->sc_wcapacity = 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));
 
-       (void)pmf_device_register(self, NULL, acpibat_resume);
-       (void)acpi_register_notify(sc->sc_node, acpibat_notify_handler);
-
        sc->sc_sensor = kmem_zalloc(ACPIBAT_COUNT *
            sizeof(*sc->sc_sensor), KM_SLEEP);
 
-       if (sc->sc_sensor == NULL)
-               return;
-
        config_interrupts(self, acpibat_init_envsys);
 
        /*
@@ -270,11 +263,9 @@
 {
        struct acpibat_softc *sc = device_private(self);
 
+       pmf_device_deregister(self);
        acpi_deregister_notify(sc->sc_node);
 
-       cv_destroy(&sc->sc_condvar);
-       mutex_destroy(&sc->sc_mutex);
-
        if (sc->sc_sme != NULL)
                sysmon_envsys_unregister(sc->sc_sme);
 
@@ -282,7 +273,8 @@
                kmem_free(sc->sc_sensor, ACPIBAT_COUNT *
                    sizeof(*sc->sc_sensor));
 
-       pmf_device_deregister(self);
+       cv_destroy(&sc->sc_condvar);
+       mutex_destroy(&sc->sc_mutex);
 
        return 0;
 }
@@ -774,12 +766,15 @@
        sc->sc_sme->sme_flags = SME_POLL_ONLY | SME_INIT_REFRESH;
        sc->sc_sme->sme_get_limits = acpibat_get_limits;
 
+       (void)acpi_register_notify(sc->sc_node, acpibat_notify_handler);
        acpibat_update_info(dv);
        acpibat_update_status(dv);
 
        if (sysmon_envsys_register(sc->sc_sme))
                goto fail;
 
+       (void)pmf_device_register(dv, NULL, acpibat_resume);
+
        return;
 
 fail:



Home | Main Index | Thread Index | Old Index