Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/sysmon * fix logic inversion in swwdog_reboot (and t...



details:   https://anonhg.NetBSD.org/src/rev/b838a071a852
branches:  trunk
changeset: 756867:b838a071a852
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Aug 06 16:02:56 2010 +0000

description:
* fix logic inversion in swwdog_reboot (and the sysctl).
* attach sysctl in constructor instead of as a link set to give it
  a chance to work in a module
* teardown sysctl when driver is detached to avoid dangling pointer

diffstat:

 sys/dev/sysmon/swwdog.c |  42 +++++++++++++++++++++---------------------
 1 files changed, 21 insertions(+), 21 deletions(-)

diffs (93 lines):

diff -r 331f3702accf -r b838a071a852 sys/dev/sysmon/swwdog.c
--- a/sys/dev/sysmon/swwdog.c   Fri Aug 06 15:26:16 2010 +0000
+++ b/sys/dev/sysmon/swwdog.c   Fri Aug 06 16:02:56 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: swwdog.c,v 1.10 2010/07/22 14:10:15 pgoyette Exp $     */
+/*     $NetBSD: swwdog.c,v 1.11 2010/08/06 16:02:56 pooka Exp $        */
 
 /*
  * Copyright (c) 2004, 2005 Steven M. Bellovin
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.10 2010/07/22 14:10:15 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: swwdog.c,v 1.11 2010/08/06 16:02:56 pooka Exp $");
 
 /*
  *
@@ -82,6 +82,9 @@
 CFATTACH_DECL_NEW(swwdog, sizeof(struct swwdog_softc),
        swwdog_match, swwdog_attach, swwdog_detach, NULL);
 
+static void swwdog_sysctl_setup(void);
+static struct sysctllog *swwdog_sysctllog;
+
 void
 swwdogattach(int n __unused)
 {
@@ -134,6 +137,8 @@
 
        if (!pmf_device_register(self, swwdog_suspend, NULL))
                aprint_error_dev(self, "couldn't establish power handler\n");
+
+       swwdog_sysctl_setup();
 }
 
 static int
@@ -143,6 +148,7 @@
 
        swwdog_disarm(sc);
        callout_destroy(&sc->sc_c);
+       sysctl_teardown(&swwdog_sysctllog);
 
        return 1;
 }
@@ -207,8 +213,8 @@
        struct swwdog_softc *sc = vsc;
        bool do_panic;
 
-       do_panic = swwdog_reboot;
-       swwdog_reboot = 1;
+       do_panic = !swwdog_reboot;
+       swwdog_reboot = false;
        callout_schedule(&sc->sc_c, 60 * hz);   /* deliberate double-panic */
 
        printf("%s: %d second timer expired\n", device_xname(sc->sc_dev),
@@ -220,25 +226,19 @@
                cpu_reboot(0, NULL);
 }
 
-SYSCTL_SETUP(sysctl_swwdog, "swwdog subtree setup")
+static void
+swwdog_sysctl_setup(void)
 {
-       int err;
        const struct sysctlnode *me;
 
-       err = sysctl_createv(NULL, 0, NULL, NULL, CTLFLAG_PERMANENT,
-           CTLTYPE_NODE, "machdep", NULL,
-           NULL, 0, NULL, 0,
-           CTL_HW, CTL_EOL);
+       KASSERT(swwdog_sysctllog == NULL);
 
-       if (err == 0)
-               err = sysctl_createv(NULL, 0, NULL, &me, CTLFLAG_READWRITE,
-                   CTLTYPE_NODE, "swwdog", NULL,
-                   NULL, 0, NULL, 0,
-                   CTL_HW, CTL_CREATE, CTL_EOL);
-
-       if (err == 0)
-               err = sysctl_createv(NULL, 0, NULL, NULL, CTLFLAG_READWRITE,
-                   CTLTYPE_BOOL, "reboot", "reboot if timer expires",
-                   NULL, 0, &swwdog_reboot, sizeof(bool),
-                   CTL_HW, me->sysctl_num, CTL_CREATE, CTL_EOL);
+       sysctl_createv(&swwdog_sysctllog, 0, NULL, &me, CTLFLAG_READWRITE,
+           CTLTYPE_NODE, "swwdog", NULL,
+           NULL, 0, NULL, 0,
+           CTL_HW, CTL_CREATE, CTL_EOL);
+       sysctl_createv(&swwdog_sysctllog, 0, NULL, NULL, CTLFLAG_READWRITE,
+           CTLTYPE_BOOL, "reboot", "reboot if timer expires",
+           NULL, 0, &swwdog_reboot, sizeof(bool),
+           CTL_HW, me->sysctl_num, CTL_CREATE, CTL_EOL);
 }



Home | Main Index | Thread Index | Old Index