callout: Fix callout_terminate() if the callout_reset() is never called
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Tue, 10 Dec 2013 15:38:36 +0000 (23:38 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Tue, 10 Dec 2013 15:41:30 +0000 (23:41 +0800)
If callout_reset() is never called, then c_gd will be NULL

sys/kern/kern_timeout.c

index aeeb276..4086737 100644 (file)
@@ -583,10 +583,12 @@ callout_terminate(struct callout *c)
 
        if (c->c_flags & CALLOUT_DID_INIT) {
                callout_stop(c);
-               sc = &softclock_pcpu_ary[c->c_gd->gd_cpuid];
-               if (sc->running == c) {
-                       while (sc->running == c)
-                               tsleep(&sc->running, 0, "crace", 1);
+               if (c->c_gd) {
+                       sc = &softclock_pcpu_ary[c->c_gd->gd_cpuid];
+                       if (sc->running == c) {
+                               while (sc->running == c)
+                                       tsleep(&sc->running, 0, "crace", 1);
+                       }
                }
                KKASSERT((c->c_flags & (CALLOUT_PENDING|CALLOUT_ACTIVE)) == 0);
                c->c_flags &= ~CALLOUT_DID_INIT;