diff options
author | Ruslan Ermilov <ru@FreeBSD.org> | 2005-09-16 11:11:51 +0000 |
---|---|---|
committer | Ruslan Ermilov <ru@FreeBSD.org> | 2005-09-16 11:11:51 +0000 |
commit | 3badacee8c62f420e7519685b3700d5741d67ded (patch) | |
tree | eea8401041be885ba31c07333f6e0206b9d04ab0 | |
parent | c4c6f08f6878d257f78ac12816d7f64b211f8f64 (diff) | |
download | src-3badacee8c62f420e7519685b3700d5741d67ded.tar.gz src-3badacee8c62f420e7519685b3700d5741d67ded.zip |
Fix "struct ifnet" leaks when attach() fails in the middle, e.g.
when mii_phy_probe() or bus_setup_intr() fails. For drivers that
call their detach() in this case, call if_free() there to cover
this case too.
Notes
Notes:
svn path=/head/; revision=150213
-rw-r--r-- | sys/dev/dc/if_dc.c | 4 | ||||
-rw-r--r-- | sys/dev/sf/if_sf.c | 4 | ||||
-rw-r--r-- | sys/dev/sk/if_sk.c | 5 | ||||
-rw-r--r-- | sys/dev/ti/if_ti.c | 4 | ||||
-rw-r--r-- | sys/dev/vr/if_vr.c | 4 | ||||
-rw-r--r-- | sys/pci/if_dc.c | 4 | ||||
-rw-r--r-- | sys/pci/if_pcn.c | 4 | ||||
-rw-r--r-- | sys/pci/if_rl.c | 8 | ||||
-rw-r--r-- | sys/pci/if_sf.c | 4 | ||||
-rw-r--r-- | sys/pci/if_sis.c | 5 | ||||
-rw-r--r-- | sys/pci/if_sk.c | 5 | ||||
-rw-r--r-- | sys/pci/if_ste.c | 4 | ||||
-rw-r--r-- | sys/pci/if_ti.c | 4 | ||||
-rw-r--r-- | sys/pci/if_tl.c | 4 | ||||
-rw-r--r-- | sys/pci/if_vr.c | 4 | ||||
-rw-r--r-- | sys/pci/if_wb.c | 4 | ||||
-rw-r--r-- | sys/pci/if_xl.c | 4 |
17 files changed, 35 insertions, 40 deletions
diff --git a/sys/dev/dc/if_dc.c b/sys/dev/dc/if_dc.c index 1dab3748797f..8a9e8c602046 100644 --- a/sys/dev/dc/if_dc.c +++ b/sys/dev/dc/if_dc.c @@ -2310,7 +2310,6 @@ dc_attach(device_t dev) if (error) { device_printf(dev, "couldn't set up irq\n"); ether_ifdetach(ifp); - if_free(ifp); goto fail; } @@ -2347,8 +2346,9 @@ dc_detach(device_t dev) DC_UNLOCK(sc); callout_drain(&sc->dc_stat_ch); ether_ifdetach(ifp); - if_free(ifp); } + if (ifp) + if_free(ifp); if (sc->dc_miibus) device_delete_child(dev, sc->dc_miibus); bus_generic_detach(dev); diff --git a/sys/dev/sf/if_sf.c b/sys/dev/sf/if_sf.c index e14ce264d120..fa7eb83a71cc 100644 --- a/sys/dev/sf/if_sf.c +++ b/sys/dev/sf/if_sf.c @@ -766,7 +766,6 @@ sf_attach(dev) if (error) { device_printf(dev, "couldn't set up irq\n"); ether_ifdetach(ifp); - if_free(ifp); goto fail; } @@ -802,8 +801,9 @@ sf_detach(dev) SF_UNLOCK(sc); callout_drain(&sc->sf_stat_callout); ether_ifdetach(ifp); - if_free(ifp); } + if (ifp) + if_free(ifp); if (sc->sf_miibus) device_delete_child(dev, sc->sf_miibus); bus_generic_detach(dev); diff --git a/sys/dev/sk/if_sk.c b/sys/dev/sk/if_sk.c index b0d937a11316..6ae2352792e2 100644 --- a/sys/dev/sk/if_sk.c +++ b/sys/dev/sk/if_sk.c @@ -1534,7 +1534,6 @@ sk_attach(dev) sc->sk_unit, sc_if->sk_phytype); error = ENODEV; SK_UNLOCK(sc); - if_free(ifp); goto fail; } @@ -1565,7 +1564,6 @@ sk_attach(dev) sk_ifmedia_upd, sk_ifmedia_sts)) { printf("skc%d: no PHY found!\n", sc_if->sk_unit); ether_ifdetach(ifp); - if_free(ifp); error = ENXIO; goto fail; } @@ -1922,9 +1920,10 @@ sk_detach(dev) /* Can't hold locks while calling detach */ SK_IF_UNLOCK(sc_if); ether_ifdetach(ifp); - if_free(ifp); SK_IF_LOCK(sc_if); } + if (ifp) + if_free(ifp); /* * We're generally called from skc_detach() which is using * device_delete_child() to get to here. It's already trashed diff --git a/sys/dev/ti/if_ti.c b/sys/dev/ti/if_ti.c index bef01aecf63c..a6126df1834e 100644 --- a/sys/dev/ti/if_ti.c +++ b/sys/dev/ti/if_ti.c @@ -2292,7 +2292,6 @@ ti_attach(dev) if (error) { printf("ti%d: couldn't set up irq\n", unit); ether_ifdetach(ifp); - if_free(ifp); goto fail; } @@ -2328,9 +2327,10 @@ ti_detach(dev) if (device_is_attached(dev)) { ti_stop(sc); ether_ifdetach(ifp); - if_free(ifp); bus_generic_detach(dev); } + if (ifp) + if_free(ifp); ifmedia_removeall(&sc->ifmedia); if (sc->ti_rdata) diff --git a/sys/dev/vr/if_vr.c b/sys/dev/vr/if_vr.c index 340aac71fde5..5eabc21dafa1 100644 --- a/sys/dev/vr/if_vr.c +++ b/sys/dev/vr/if_vr.c @@ -769,7 +769,6 @@ vr_attach(dev) if (error) { printf("vr%d: couldn't set up irq\n", unit); ether_ifdetach(ifp); - if_free(ifp); goto fail; } @@ -804,9 +803,10 @@ vr_detach(device_t dev) vr_stop(sc); VR_UNLOCK(sc); /* XXX: Avoid recursive acquire. */ ether_ifdetach(ifp); - if_free(ifp); VR_LOCK(sc); } + if (ifp) + if_free(ifp); if (sc->vr_miibus) device_delete_child(dev, sc->vr_miibus); bus_generic_detach(dev); diff --git a/sys/pci/if_dc.c b/sys/pci/if_dc.c index 1dab3748797f..8a9e8c602046 100644 --- a/sys/pci/if_dc.c +++ b/sys/pci/if_dc.c @@ -2310,7 +2310,6 @@ dc_attach(device_t dev) if (error) { device_printf(dev, "couldn't set up irq\n"); ether_ifdetach(ifp); - if_free(ifp); goto fail; } @@ -2347,8 +2346,9 @@ dc_detach(device_t dev) DC_UNLOCK(sc); callout_drain(&sc->dc_stat_ch); ether_ifdetach(ifp); - if_free(ifp); } + if (ifp) + if_free(ifp); if (sc->dc_miibus) device_delete_child(dev, sc->dc_miibus); bus_generic_detach(dev); diff --git a/sys/pci/if_pcn.c b/sys/pci/if_pcn.c index 36ac64462095..1ec87658c390 100644 --- a/sys/pci/if_pcn.c +++ b/sys/pci/if_pcn.c @@ -623,7 +623,6 @@ pcn_attach(dev) if (mii_phy_probe(dev, &sc->pcn_miibus, pcn_ifmedia_upd, pcn_ifmedia_sts)) { printf("pcn%d: MII without any PHY!\n", sc->pcn_unit); - if_free(ifp); error = ENXIO; goto fail; } @@ -677,8 +676,9 @@ pcn_detach(dev) PCN_UNLOCK(sc); callout_drain(&sc->pcn_stat_callout); ether_ifdetach(ifp); - if_free(ifp); } + if (ifp) + if_free(ifp); if (sc->pcn_miibus) device_delete_child(dev, sc->pcn_miibus); bus_generic_detach(dev); diff --git a/sys/pci/if_rl.c b/sys/pci/if_rl.c index 3f650e3b67dc..556c1a197f4a 100644 --- a/sys/pci/if_rl.c +++ b/sys/pci/if_rl.c @@ -986,7 +986,6 @@ rl_attach(device_t dev) if (error) { if_printf(ifp, "couldn't set up irq\n"); ether_ifdetach(ifp); - if_free(ifp); } fail: @@ -1008,24 +1007,23 @@ rl_detach(device_t dev) { struct rl_softc *sc; struct ifnet *ifp; - int attached; sc = device_get_softc(dev); ifp = sc->rl_ifp; KASSERT(mtx_initialized(&sc->rl_mtx), ("rl mutex not initialized")); - attached = device_is_attached(dev); /* These should only be active if attach succeeded */ - if (attached) { + if (device_is_attached(dev)) { RL_LOCK(sc); rl_stop(sc); RL_UNLOCK(sc); ether_ifdetach(ifp); - if_free(ifp); } #if 0 sc->suspended = 1; #endif + if (ifp) + if_free(ifp); if (sc->rl_miibus) device_delete_child(dev, sc->rl_miibus); bus_generic_detach(dev); diff --git a/sys/pci/if_sf.c b/sys/pci/if_sf.c index e14ce264d120..fa7eb83a71cc 100644 --- a/sys/pci/if_sf.c +++ b/sys/pci/if_sf.c @@ -766,7 +766,6 @@ sf_attach(dev) if (error) { device_printf(dev, "couldn't set up irq\n"); ether_ifdetach(ifp); - if_free(ifp); goto fail; } @@ -802,8 +801,9 @@ sf_detach(dev) SF_UNLOCK(sc); callout_drain(&sc->sf_stat_callout); ether_ifdetach(ifp); - if_free(ifp); } + if (ifp) + if_free(ifp); if (sc->sf_miibus) device_delete_child(dev, sc->sf_miibus); bus_generic_detach(dev); diff --git a/sys/pci/if_sis.c b/sys/pci/if_sis.c index 469ab0202992..ab4a1216976f 100644 --- a/sys/pci/if_sis.c +++ b/sys/pci/if_sis.c @@ -1220,7 +1220,6 @@ sis_attach(device_t dev) if (mii_phy_probe(dev, &sc->sis_miibus, sis_ifmedia_upd, sis_ifmedia_sts)) { printf("sis%d: MII without any PHY!\n", sc->sis_unit); - if_free(ifp); error = ENXIO; goto fail; } @@ -1248,7 +1247,6 @@ sis_attach(device_t dev) if (error) { printf("sis%d: couldn't set up irq\n", unit); ether_ifdetach(ifp); - if_free(ifp); goto fail; } @@ -1282,8 +1280,9 @@ sis_detach(device_t dev) sis_reset(sc); sis_stop(sc); ether_ifdetach(ifp); - if_free(ifp); } + if (ifp) + if_free(ifp); if (sc->sis_miibus) device_delete_child(dev, sc->sis_miibus); bus_generic_detach(dev); diff --git a/sys/pci/if_sk.c b/sys/pci/if_sk.c index b0d937a11316..6ae2352792e2 100644 --- a/sys/pci/if_sk.c +++ b/sys/pci/if_sk.c @@ -1534,7 +1534,6 @@ sk_attach(dev) sc->sk_unit, sc_if->sk_phytype); error = ENODEV; SK_UNLOCK(sc); - if_free(ifp); goto fail; } @@ -1565,7 +1564,6 @@ sk_attach(dev) sk_ifmedia_upd, sk_ifmedia_sts)) { printf("skc%d: no PHY found!\n", sc_if->sk_unit); ether_ifdetach(ifp); - if_free(ifp); error = ENXIO; goto fail; } @@ -1922,9 +1920,10 @@ sk_detach(dev) /* Can't hold locks while calling detach */ SK_IF_UNLOCK(sc_if); ether_ifdetach(ifp); - if_free(ifp); SK_IF_LOCK(sc_if); } + if (ifp) + if_free(ifp); /* * We're generally called from skc_detach() which is using * device_delete_child() to get to here. It's already trashed diff --git a/sys/pci/if_ste.c b/sys/pci/if_ste.c index 416795101321..eca7e11b13d3 100644 --- a/sys/pci/if_ste.c +++ b/sys/pci/if_ste.c @@ -1127,7 +1127,6 @@ ste_attach(dev) if (error) { device_printf(dev, "couldn't set up irq\n"); ether_ifdetach(ifp); - if_free(ifp); goto fail; } @@ -1163,8 +1162,9 @@ ste_detach(dev) STE_UNLOCK(sc); callout_drain(&sc->ste_stat_callout); ether_ifdetach(ifp); - if_free(ifp); } + if (ifp) + if_free(ifp); if (sc->ste_miibus) device_delete_child(dev, sc->ste_miibus); bus_generic_detach(dev); diff --git a/sys/pci/if_ti.c b/sys/pci/if_ti.c index bef01aecf63c..a6126df1834e 100644 --- a/sys/pci/if_ti.c +++ b/sys/pci/if_ti.c @@ -2292,7 +2292,6 @@ ti_attach(dev) if (error) { printf("ti%d: couldn't set up irq\n", unit); ether_ifdetach(ifp); - if_free(ifp); goto fail; } @@ -2328,9 +2327,10 @@ ti_detach(dev) if (device_is_attached(dev)) { ti_stop(sc); ether_ifdetach(ifp); - if_free(ifp); bus_generic_detach(dev); } + if (ifp) + if_free(ifp); ifmedia_removeall(&sc->ifmedia); if (sc->ti_rdata) diff --git a/sys/pci/if_tl.c b/sys/pci/if_tl.c index e67004348242..6743912f88fe 100644 --- a/sys/pci/if_tl.c +++ b/sys/pci/if_tl.c @@ -1307,7 +1307,6 @@ tl_attach(dev) if (error) { device_printf(dev, "couldn't set up irq\n"); ether_ifdetach(ifp); - if_free(ifp); goto fail; } @@ -1343,8 +1342,9 @@ tl_detach(dev) TL_UNLOCK(sc); callout_drain(&sc->tl_stat_callout); ether_ifdetach(ifp); - if_free(ifp); } + if (ifp) + if_free(ifp); if (sc->tl_miibus) device_delete_child(dev, sc->tl_miibus); bus_generic_detach(dev); diff --git a/sys/pci/if_vr.c b/sys/pci/if_vr.c index 340aac71fde5..5eabc21dafa1 100644 --- a/sys/pci/if_vr.c +++ b/sys/pci/if_vr.c @@ -769,7 +769,6 @@ vr_attach(dev) if (error) { printf("vr%d: couldn't set up irq\n", unit); ether_ifdetach(ifp); - if_free(ifp); goto fail; } @@ -804,9 +803,10 @@ vr_detach(device_t dev) vr_stop(sc); VR_UNLOCK(sc); /* XXX: Avoid recursive acquire. */ ether_ifdetach(ifp); - if_free(ifp); VR_LOCK(sc); } + if (ifp) + if_free(ifp); if (sc->vr_miibus) device_delete_child(dev, sc->vr_miibus); bus_generic_detach(dev); diff --git a/sys/pci/if_wb.c b/sys/pci/if_wb.c index a6a677ff873b..205e007efb61 100644 --- a/sys/pci/if_wb.c +++ b/sys/pci/if_wb.c @@ -885,7 +885,6 @@ wb_attach(dev) if (error) { device_printf(dev, "couldn't set up irq\n"); ether_ifdetach(ifp); - if_free(ifp); goto fail; } @@ -922,8 +921,9 @@ wb_detach(dev) if (device_is_attached(dev)) { wb_stop(sc); ether_ifdetach(ifp); - if_free(ifp); } + if (ifp) + if_free(ifp); if (sc->wb_miibus) device_delete_child(dev, sc->wb_miibus); bus_generic_detach(dev); diff --git a/sys/pci/if_xl.c b/sys/pci/if_xl.c index b4f1f86e87bf..520f66829733 100644 --- a/sys/pci/if_xl.c +++ b/sys/pci/if_xl.c @@ -1608,7 +1608,6 @@ done: if (error) { device_printf(dev, "couldn't set up irq\n"); ether_ifdetach(ifp); - if_free(ifp); goto fail; } @@ -1708,8 +1707,9 @@ xl_detach(device_t dev) taskqueue_drain(taskqueue_swi, &sc->xl_task); callout_drain(&sc->xl_stat_callout); ether_ifdetach(ifp); - if_free(ifp); } + if (ifp) + if_free(ifp); if (sc->xl_miibus) device_delete_child(dev, sc->xl_miibus); bus_generic_detach(dev); |