On Sat, Oct 23, 2010 at 04:20:12PM +0000, Jacob Meuser wrote:
> like the timeout(9) diff, but for network interfaces.  I discussed this
> a bit with damien@ when I ran into this with rum(4), and he suggested
> testing if_flags.  I don't work on network drivers ...

new version after feedback from deraadt.  check ifp->if_softc instead
of ifp->if_flags and just skip net detach instead of returning early.

ok? 

fwiw, the previous version was in snaps, along with some other
diffs, for a while, maybe the first two weeks of oct or so.

-- 
jake...@sdf.lonestar.org
SDF Public Access UNIX System - http://sdf.lonestar.org

Index: if_atu.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_atu.c,v
retrieving revision 1.95
diff -u -p -r1.95 if_atu.c
--- if_atu.c    23 Oct 2010 15:42:09 -0000      1.95
+++ if_atu.c    23 Oct 2010 16:53:44 -0000
@@ -1504,8 +1504,10 @@ atu_detach(struct device *self, int flag
                if (sc->atu_ep[ATU_ENDPT_RX] != NULL)
                        usbd_abort_pipe(sc->atu_ep[ATU_ENDPT_RX]);
 
-               ieee80211_ifdetach(ifp);
-               if_detach(ifp);
+               if (ifp->if_softc != NULL) {
+                       ieee80211_ifdetach(ifp);
+                       if_detach(ifp);
+               }
        }
 
        return(0);
Index: if_aue.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_aue.c,v
retrieving revision 1.81
diff -u -p -r1.81 if_aue.c
--- if_aue.c    23 Oct 2010 16:14:06 -0000      1.81
+++ if_aue.c    23 Oct 2010 16:53:45 -0000
@@ -872,8 +872,10 @@ aue_detach(struct device *self, int flag
 
        mii_detach(&sc->aue_mii, MII_PHY_ANY, MII_OFFSET_ANY);
        ifmedia_delete_instance(&sc->aue_mii.mii_media, IFM_INST_ANY);
-       ether_ifdetach(ifp);
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ether_ifdetach(ifp);
+               if_detach(ifp);
+       }
 
 #ifdef DIAGNOSTIC
        if (sc->aue_ep[AUE_ENDPT_TX] != NULL ||
Index: if_axe.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_axe.c,v
retrieving revision 1.101
diff -u -p -r1.101 if_axe.c
--- if_axe.c    23 Oct 2010 16:14:07 -0000      1.101
+++ if_axe.c    23 Oct 2010 16:53:45 -0000
@@ -864,8 +864,10 @@ axe_detach(struct device *self, int flag
 
        mii_detach(&sc->axe_mii, MII_PHY_ANY, MII_OFFSET_ANY);
        ifmedia_delete_instance(&sc->axe_mii.mii_media, IFM_INST_ANY);
-       ether_ifdetach(ifp);
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ether_ifdetach(ifp);
+               if_detach(ifp);
+       }
 
 #ifdef DIAGNOSTIC
        if (sc->axe_ep[AXE_ENDPT_TX] != NULL ||
Index: if_cdce.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_cdce.c,v
retrieving revision 1.46
diff -u -p -r1.46 if_cdce.c
--- if_cdce.c   24 Sep 2010 08:33:58 -0000      1.46
+++ if_cdce.c   23 Oct 2010 16:53:46 -0000
@@ -380,9 +380,10 @@ cdce_detach(struct device *self, int fla
        if (ifp->if_flags & IFF_RUNNING)
                cdce_stop(sc);
 
-       ether_ifdetach(ifp);
-
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ether_ifdetach(ifp);
+               if_detach(ifp);
+       }
 
        sc->cdce_attached = 0;
        splx(s);
Index: if_cue.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_cue.c,v
retrieving revision 1.55
diff -u -p -r1.55 if_cue.c
--- if_cue.c    23 Oct 2010 16:14:07 -0000      1.55
+++ if_cue.c    23 Oct 2010 16:53:46 -0000
@@ -576,9 +576,10 @@ cue_detach(struct device *self, int flag
        if (ifp->if_flags & IFF_RUNNING)
                cue_stop(sc);
 
-       ether_ifdetach(ifp);
-
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ether_ifdetach(ifp);
+               if_detach(ifp);
+       }
 
 #ifdef DIAGNOSTIC
        if (sc->cue_ep[CUE_ENDPT_TX] != NULL ||
Index: if_kue.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_kue.c,v
retrieving revision 1.60
diff -u -p -r1.60 if_kue.c
--- if_kue.c    24 Sep 2010 08:33:58 -0000      1.60
+++ if_kue.c    23 Oct 2010 16:53:46 -0000
@@ -570,9 +570,10 @@ kue_detach(struct device *self, int flag
        if (ifp->if_flags & IFF_RUNNING)
                kue_stop(sc);
 
-       ether_ifdetach(ifp);
-
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ether_ifdetach(ifp);
+               if_detach(ifp);
+       }
 
 #ifdef DIAGNOSTIC
        if (sc->kue_ep[KUE_ENDPT_TX] != NULL ||
Index: if_mos.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_mos.c,v
retrieving revision 1.10
diff -u -p -r1.10 if_mos.c
--- if_mos.c    23 Oct 2010 16:14:07 -0000      1.10
+++ if_mos.c    23 Oct 2010 16:53:47 -0000
@@ -799,8 +799,10 @@ mos_detach(struct device *self, int flag
 
        mii_detach(&sc->mos_mii, MII_PHY_ANY, MII_OFFSET_ANY);
        ifmedia_delete_instance(&sc->mos_mii.mii_media, IFM_INST_ANY);
-       ether_ifdetach(ifp);
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ether_ifdetach(ifp);
+               if_detach(ifp);
+       }
 
 #ifdef DIAGNOSTIC
        if (sc->mos_ep[MOS_ENDPT_TX] != NULL ||
Index: if_ral.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_ral.c,v
retrieving revision 1.115
diff -u -p -r1.115 if_ral.c
--- if_ral.c    23 Oct 2010 16:14:07 -0000      1.115
+++ if_ral.c    23 Oct 2010 16:53:47 -0000
@@ -363,8 +363,10 @@ ural_detach(struct device *self, int fla
 
        s = splusb();
 
-       ieee80211_ifdetach(ifp);        /* free all nodes */
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ieee80211_ifdetach(ifp);        /* free all nodes */
+               if_detach(ifp);
+       }
 
        usb_rem_task(sc->sc_udev, &sc->sc_task);
        if (timeout_initialized(&sc->scan_to))
Index: if_rum.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_rum.c,v
retrieving revision 1.92
diff -u -p -r1.92 if_rum.c
--- if_rum.c    23 Oct 2010 16:14:07 -0000      1.92
+++ if_rum.c    23 Oct 2010 16:53:48 -0000
@@ -460,8 +460,10 @@ rum_detach(struct device *self, int flag
 
        s = splusb();
 
-       ieee80211_ifdetach(ifp);        /* free all nodes */
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ieee80211_ifdetach(ifp);        /* free all nodes */
+               if_detach(ifp);
+       }
 
        usb_rem_task(sc->sc_udev, &sc->sc_task);
        if (timeout_initialized(&sc->scan_to))
Index: if_uath.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_uath.c,v
retrieving revision 1.45
diff -u -p -r1.45 if_uath.c
--- if_uath.c   23 Oct 2010 16:14:07 -0000      1.45
+++ if_uath.c   23 Oct 2010 16:53:49 -0000
@@ -461,8 +461,10 @@ uath_detach(struct device *self, int fla
        /* close Tx/Rx pipes */
        uath_close_pipes(sc);
 
-       ieee80211_ifdetach(ifp);        /* free all nodes */
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ieee80211_ifdetach(ifp);        /* free all nodes */
+               if_detach(ifp);
+       }
 
        splx(s);
 
Index: if_udav.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_udav.c,v
retrieving revision 1.48
diff -u -p -r1.48 if_udav.c
--- if_udav.c   23 Oct 2010 16:14:07 -0000      1.48
+++ if_udav.c   23 Oct 2010 16:53:49 -0000
@@ -351,8 +351,10 @@ udav_detach(struct device *self, int fla
 
        mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
        ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY);
-       ether_ifdetach(ifp);
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ether_ifdetach(ifp);
+               if_detach(ifp);
+       }
 
 #ifdef DIAGNOSTIC
        if (sc->sc_pipe_tx != NULL)
Index: if_upgt.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_upgt.c,v
retrieving revision 1.52
diff -u -p -r1.52 if_upgt.c
--- if_upgt.c   23 Oct 2010 16:14:07 -0000      1.52
+++ if_upgt.c   23 Oct 2010 16:53:50 -0000
@@ -499,7 +499,7 @@ upgt_detach(struct device *self, int fla
        /* free firmware */
        upgt_fw_free(sc);
 
-       if (sc->sc_flags & UPGT_DEVICE_ATTACHED) {
+       if (ifp->if_softc != NULL) {
                /* detach interface */
                ieee80211_ifdetach(ifp);
                if_detach(ifp);
Index: if_url.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_url.c,v
retrieving revision 1.58
diff -u -p -r1.58 if_url.c
--- if_url.c    23 Oct 2010 16:14:07 -0000      1.58
+++ if_url.c    23 Oct 2010 16:53:50 -0000
@@ -358,8 +358,10 @@ url_detach(struct device *self, int flag
 
        mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
        ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY);
-       ether_ifdetach(ifp);
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ether_ifdetach(ifp);
+               if_detach(ifp);
+       }
 
 #ifdef DIAGNOSTIC
        if (sc->sc_pipe_tx != NULL)
Index: if_urndis.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_urndis.c,v
retrieving revision 1.26
diff -u -p -r1.26 if_urndis.c
--- if_urndis.c 24 Sep 2010 08:33:59 -0000      1.26
+++ if_urndis.c 23 Oct 2010 16:53:50 -0000
@@ -1532,8 +1532,10 @@ urndis_detach(struct device *self, int f
 
        ifp = GET_IFP(sc);
 
-       ether_ifdetach(ifp);
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ether_ifdetach(ifp);
+               if_detach(ifp);
+       }
 
        urndis_stop(sc);
        sc->sc_attached = 0;
Index: if_urtw.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_urtw.c,v
retrieving revision 1.33
diff -u -p -r1.33 if_urtw.c
--- if_urtw.c   23 Oct 2010 16:14:07 -0000      1.33
+++ if_urtw.c   23 Oct 2010 16:53:51 -0000
@@ -775,8 +775,10 @@ urtw_detach(struct device *self, int fla
 
        s = splusb();
 
-       ieee80211_ifdetach(ifp);        /* free all nodes */
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ieee80211_ifdetach(ifp);        /* free all nodes */
+               if_detach(ifp);
+       }
 
        usb_rem_task(sc->sc_udev, &sc->sc_task);
        usb_rem_task(sc->sc_udev, &sc->sc_ledtask);
Index: if_wi_usb.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_wi_usb.c,v
retrieving revision 1.48
diff -u -p -r1.48 if_wi_usb.c
--- if_wi_usb.c 24 Sep 2010 08:33:59 -0000      1.48
+++ if_wi_usb.c 23 Oct 2010 16:53:52 -0000
@@ -427,8 +427,10 @@ wi_usb_detach(struct device *self, int f
 
        wsc->wi_flags = 0;
 
-       ether_ifdetach(ifp);
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ether_ifdetach(ifp);
+               if_detach(ifp);
+       }
 
        sc->wi_usb_attached = 0;
 
Index: if_zyd.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/if_zyd.c,v
retrieving revision 1.84
diff -u -p -r1.84 if_zyd.c
--- if_zyd.c    23 Oct 2010 16:14:07 -0000      1.84
+++ if_zyd.c    23 Oct 2010 16:53:53 -0000
@@ -455,8 +455,10 @@ zyd_detach(struct device *self, int flag
                return 0;
        }
 
-       ieee80211_ifdetach(ifp);
-       if_detach(ifp);
+       if (ifp->if_softc != NULL) {
+               ieee80211_ifdetach(ifp);
+               if_detach(ifp);
+       }
 
        zyd_free_rx_list(sc);
        zyd_free_tx_list(sc);

Reply via email to