if_ath - Properly remove sysctls on detach.
authorAntonio Huete Jimenez <tuxillo@quantumachine.net>
Thu, 15 Apr 2010 17:37:19 +0000 (19:37 +0200)
committerAntonio Huete Jimenez <tuxillo@quantumachine.net>
Thu, 15 Apr 2010 17:37:19 +0000 (19:37 +0200)
Submitted-by: Johannes Hofmann <johannes.hofmann@gmx.de>
sys/dev/netif/ath/ath/if_ath.c
sys/dev/netif/ath/ath/if_athvar.h
sys/dev/netif/ath/rate_sample/sample.c

index aa83d04..0001f3f 100644 (file)
@@ -372,6 +372,14 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
        if_initname(ifp, device_get_name(sc->sc_dev),
                device_get_unit(sc->sc_dev));
 
+       /* prepare sysctl tree for use in sub modules */
+       sysctl_ctx_init(&sc->sc_sysctl_ctx);
+       sc->sc_sysctl_tree = SYSCTL_ADD_NODE(&sc->sc_sysctl_ctx,
+               SYSCTL_STATIC_CHILDREN(_hw),
+               OID_AUTO,
+               device_get_nameunit(sc->sc_dev),
+               CTLFLAG_RD, 0, "");
+
        ah = ath_hal_attach(devid, sc, sc->sc_st, sc->sc_sh, &status);
        if (ah == NULL) {
                if_printf(ifp, "unable to attach hardware; HAL status %u\n",
@@ -782,6 +790,10 @@ ath_detach(struct ath_softc *sc)
        ath_desc_free(sc);
        ath_tx_cleanup(sc);
        ath_hal_detach(sc->sc_ah);      /* NB: sets chip in full sleep */
+       if (sc->sc_sysctl_tree) {
+               sysctl_ctx_free(&sc->sc_sysctl_ctx);
+               sc->sc_sysctl_tree = NULL;
+       }
        if_free(ifp);
 
        return 0;
@@ -6552,11 +6564,7 @@ ath_sysctlattach(struct ath_softc *sc)
        struct ath_hal *ah = sc->sc_ah;
 
        ctx = &sc->sc_sysctl_ctx;
-       sysctl_ctx_init(ctx);
-        tree = SYSCTL_ADD_NODE(ctx, SYSCTL_STATIC_CHILDREN(_hw),
-                               OID_AUTO,
-                               device_get_nameunit(sc->sc_dev),
-                               CTLFLAG_RD, 0, "");
+       tree = sc->sc_sysctl_tree;
         if (tree == NULL) {
                device_printf(sc->sc_dev, "can't add sysctl node\n");
                return;
index 815dd36..5b7fac9 100644 (file)
@@ -345,6 +345,7 @@ struct ath_softc {
        u_int32_t               sc_avgtsfdeltap;/* TDMA slot adjust (+) */
        u_int32_t               sc_avgtsfdeltam;/* TDMA slot adjust (-) */
        struct sysctl_ctx_list  sc_sysctl_ctx;
+       struct sysctl_oid       *sc_sysctl_tree;
 };
 
 #define        ATH_LOCK_INIT(_sc) \
index f0df2a2..465ac72 100644 (file)
@@ -953,11 +953,7 @@ ath_rate_sysctlattach(struct ath_softc *sc, struct sample_softc *ssc)
        struct sysctl_oid *tree;
 
        ctx = &sc->sc_sysctl_ctx;
-       sysctl_ctx_init(ctx);
-       tree = SYSCTL_ADD_NODE(ctx, SYSCTL_STATIC_CHILDREN(_hw),
-                              OID_AUTO,
-                              device_get_nameunit(sc->sc_dev),
-                              CTLFLAG_RD, 0, "");
+       tree = sc->sc_sysctl_tree;
        if (tree == NULL) {
                device_printf(sc->sc_dev, "can't add sysctl node\n");
                return;