diff options
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/dc/if_dc.c | 14 | ||||
-rw-r--r-- | sys/dev/sf/if_sf.c | 18 | ||||
-rw-r--r-- | sys/dev/sk/if_sk.c | 18 | ||||
-rw-r--r-- | sys/dev/ti/if_ti.c | 18 | ||||
-rw-r--r-- | sys/dev/vr/if_vr.c | 18 |
5 files changed, 67 insertions, 19 deletions
diff --git a/sys/dev/dc/if_dc.c b/sys/dev/dc/if_dc.c index 15acd86..5979bd3 100644 --- a/sys/dev/dc/if_dc.c +++ b/sys/dev/dc/if_dc.c @@ -2282,6 +2282,7 @@ dc_attach(dev) if (error) { printf("dc%d: couldn't set up irq\n", unit); + ether_ifdetach(ifp); goto fail; } @@ -2291,6 +2292,13 @@ fail: return (error); } +/* + * Shutdown hardware and free up resources. This can be called any + * time after the mutex has been initialized. It is called in both + * the error case in attach and the normal detach case so it needs + * to be careful about only freeing resources that have actually been + * allocated. + */ static int dc_detach(dev) device_t dev; @@ -2305,12 +2313,14 @@ dc_detach(dev) ifp = &sc->arpcom.ac_if; + /* These should only be active if attach succeeded */ if (device_is_alive(dev)) { dc_stop(sc); ether_ifdetach(ifp); - device_delete_child(dev, sc->dc_miibus); - bus_generic_detach(dev); } + if (sc->dc_miibus) + device_delete_child(dev, sc->dc_miibus); + bus_generic_detach(dev); if (sc->dc_intrhand) bus_teardown_intr(dev, sc->dc_irq, sc->dc_intrhand); diff --git a/sys/dev/sf/if_sf.c b/sys/dev/sf/if_sf.c index a7ebb01..511e450 100644 --- a/sys/dev/sf/if_sf.c +++ b/sys/dev/sf/if_sf.c @@ -792,11 +792,13 @@ sf_attach(dev) */ ether_ifattach(ifp, sc->arpcom.ac_enaddr); + /* Hook interrupt last to avoid having to lock softc */ error = bus_setup_intr(dev, sc->sf_irq, INTR_TYPE_NET, sf_intr, sc, &sc->sf_intrhand); if (error) { printf("sf%d: couldn't set up irq\n", unit); + ether_ifdetach(ifp); goto fail; } @@ -807,6 +809,13 @@ fail: return(error); } +/* + * Shutdown hardware and free up resources. This can be called any + * time after the mutex has been initialized. It is called in both + * the error case in attach and the normal detach case so it needs + * to be careful about only freeing resources that have actually been + * allocated. + */ static int sf_detach(dev) device_t dev; @@ -819,13 +828,14 @@ sf_detach(dev) SF_LOCK(sc); ifp = &sc->arpcom.ac_if; + /* These should only be active if attach succeeded */ if (device_is_alive(dev)) { - if (bus_child_present(dev)) - sf_stop(sc); + sf_stop(sc); ether_ifdetach(ifp); - device_delete_child(dev, sc->sf_miibus); - bus_generic_detach(dev); } + if (sc->sf_miibus) + device_delete_child(dev, sc->sf_miibus); + bus_generic_detach(dev); if (sc->sf_intrhand) bus_teardown_intr(dev, sc->sf_irq, sc->sf_intrhand); diff --git a/sys/dev/sk/if_sk.c b/sys/dev/sk/if_sk.c index 1093f34..49424bb 100644 --- a/sys/dev/sk/if_sk.c +++ b/sys/dev/sk/if_sk.c @@ -1178,6 +1178,7 @@ sk_attach_xmac(dev) if (mii_phy_probe(dev, &sc_if->sk_miibus, sk_ifmedia_upd, sk_ifmedia_sts)) { printf("skc%d: no PHY found!\n", sc_if->sk_unit); + ether_ifdetach(ifp); error = ENXIO; goto fail_xmac; } @@ -1335,6 +1336,7 @@ sk_attach(dev) bus_generic_attach(dev); + /* Hook interrupt last to avoid having to lock softc */ error = bus_setup_intr(dev, sc->sk_irq, INTR_TYPE_NET, sk_intr, sc, &sc->sk_intrhand); @@ -1350,6 +1352,13 @@ fail: return(error); } +/* + * Shutdown hardware and free up resources. This can be called any + * time after the mutex has been initialized. It is called in both + * the error case in attach and the normal detach case so it needs + * to be careful about only freeing resources that have actually been + * allocated. + */ static int sk_detach_xmac(dev) device_t dev; @@ -1365,13 +1374,14 @@ sk_detach_xmac(dev) SK_IF_LOCK(sc_if); ifp = &sc_if->arpcom.ac_if; + /* These should only be active if attach_xmac succeeded */ if (device_is_alive(dev)) { - if (bus_child_present(dev)) - sk_stop(sc_if); + sk_stop(sc_if); ether_ifdetach(ifp); - device_delete_child(dev, sc_if->sk_miibus); - bus_generic_detach(dev); } + if (sc_if->sk_miibus) + device_delete_child(dev, sc_if->sk_miibus); + bus_generic_detach(dev); if (sc_if->sk_cdata.sk_jumbo_buf) contigfree(sc_if->sk_cdata.sk_jumbo_buf, SK_JMEM, M_DEVBUF); if (sc_if->sk_rdata) { diff --git a/sys/dev/ti/if_ti.c b/sys/dev/ti/if_ti.c index c1b5796..5046685 100644 --- a/sys/dev/ti/if_ti.c +++ b/sys/dev/ti/if_ti.c @@ -2115,6 +2115,7 @@ ti_attach(dev) mtx_init(&sc->ti_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, MTX_DEF | MTX_RECURSE); + ifmedia_init(&sc->ifmedia, IFM_IMASK, ti_ifmedia_upd, ti_ifmedia_sts); sc->arpcom.ac_if.if_capabilities = IFCAP_HWCSUM | IFCAP_VLAN_HWTAGGING; sc->arpcom.ac_if.if_capenable = sc->arpcom.ac_if.if_capabilities; @@ -2259,7 +2260,6 @@ ti_attach(dev) ifp->if_snd.ifq_maxlen = TI_TX_RING_CNT - 1; /* Set up ifmedia support. */ - ifmedia_init(&sc->ifmedia, IFM_IMASK, ti_ifmedia_upd, ti_ifmedia_sts); if (sc->ti_copper) { /* * Copper cards allow manual 10/100 mode selection, @@ -2310,11 +2310,13 @@ ti_attach(dev) */ ether_ifattach(ifp, sc->arpcom.ac_enaddr); + /* Hook interrupt last to avoid having to lock softc */ error = bus_setup_intr(dev, sc->ti_irq, INTR_TYPE_NET, ti_intr, sc, &sc->ti_intrhand); if (error) { printf("ti%d: couldn't set up irq\n", unit); + ether_ifdetach(ifp); goto fail; } @@ -2352,7 +2354,13 @@ ti_unref_special(device_t dev) return(0); } - +/* + * Shutdown hardware and free up resources. This can be called any + * time after the mutex has been initialized. It is called in both + * the error case in attach and the normal detach case so it needs + * to be careful about only freeing resources that have actually been + * allocated. + */ static int ti_detach(dev) device_t dev; @@ -2368,13 +2376,13 @@ ti_detach(dev) TI_LOCK(sc); ifp = &sc->arpcom.ac_if; + /* These should only be active if attach succeeded */ if (device_is_alive(dev)) { - if (bus_child_present(dev)) - ti_stop(sc); + ti_stop(sc); ether_ifdetach(ifp); bus_generic_detach(dev); - ifmedia_removeall(&sc->ifmedia); } + ifmedia_removeall(&sc->ifmedia); if (sc->ti_intrhand) bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand); diff --git a/sys/dev/vr/if_vr.c b/sys/dev/vr/if_vr.c index 793ae64..84bd474 100644 --- a/sys/dev/vr/if_vr.c +++ b/sys/dev/vr/if_vr.c @@ -878,11 +878,13 @@ vr_attach(dev) */ ether_ifattach(ifp, eaddr); + /* Hook interrupt last to avoid having to lock softc */ error = bus_setup_intr(dev, sc->vr_irq, INTR_TYPE_NET, vr_intr, sc, &sc->vr_intrhand); if (error) { printf("vr%d: couldn't set up irq\n", unit); + ether_ifdetach(ifp); goto fail; } @@ -893,6 +895,13 @@ fail: return(error); } +/* + * Shutdown hardware and free up resources. This can be called any + * time after the mutex has been initialized. It is called in both + * the error case in attach and the normal detach case so it needs + * to be careful about only freeing resources that have actually been + * allocated. + */ static int vr_detach(dev) device_t dev; @@ -905,13 +914,14 @@ vr_detach(dev) VR_LOCK(sc); ifp = &sc->arpcom.ac_if; + /* These should only be active if attach succeeded */ if (device_is_alive(dev)) { - if (bus_child_present(dev)) - vr_stop(sc); + vr_stop(sc); ether_ifdetach(ifp); - device_delete_child(dev, sc->vr_miibus); - bus_generic_detach(dev); } + if (sc->vr_miibus) + device_delete_child(dev, sc->vr_miibus); + bus_generic_detach(dev); if (sc->vr_intrhand) bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand); |