Fix "struct ifnet" leaks when attach() fails in the middle.
This commit is contained in:
parent
8b28aef238
commit
ad61f89618
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=150215
@ -427,11 +427,8 @@ bfe_attach(device_t dev)
|
||||
goto fail;
|
||||
}
|
||||
fail:
|
||||
if(error) {
|
||||
if (error)
|
||||
bfe_release_resources(sc);
|
||||
if (ifp != NULL)
|
||||
if_free(ifp);
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -451,7 +448,6 @@ bfe_detach(device_t dev)
|
||||
if (device_is_attached(dev)) {
|
||||
bfe_stop(sc);
|
||||
ether_ifdetach(ifp);
|
||||
if_free(ifp);
|
||||
}
|
||||
|
||||
bfe_chip_reset(sc);
|
||||
@ -939,6 +935,9 @@ bfe_release_resources(struct bfe_softc *sc)
|
||||
if (sc->bfe_res != NULL)
|
||||
bus_release_resource(dev, SYS_RES_MEMORY, 0x10, sc->bfe_res);
|
||||
|
||||
if (sc->bfe_ifp != NULL)
|
||||
if_free(sc->bfe_ifp);
|
||||
|
||||
if(sc->bfe_tx_tag != NULL) {
|
||||
bus_dmamap_unload(sc->bfe_tx_tag, sc->bfe_tx_map);
|
||||
bus_dmamem_free(sc->bfe_tx_tag, sc->bfe_tx_list,
|
||||
|
@ -2460,7 +2460,6 @@ bge_attach(dev)
|
||||
printf("bge%d: MII without any PHY!\n", sc->bge_unit);
|
||||
bge_release_resources(sc);
|
||||
bge_free_jumbo_mem(sc);
|
||||
if_free(ifp);
|
||||
error = ENXIO;
|
||||
goto fail;
|
||||
}
|
||||
@ -2524,7 +2523,6 @@ bge_detach(dev)
|
||||
BGE_UNLOCK(sc);
|
||||
|
||||
ether_ifdetach(ifp);
|
||||
if_free(ifp);
|
||||
|
||||
if (sc->bge_tbi) {
|
||||
ifmedia_removeall(&sc->bge_ifmedia);
|
||||
@ -2565,6 +2563,9 @@ bge_release_resources(sc)
|
||||
bus_release_resource(dev, SYS_RES_MEMORY,
|
||||
BGE_PCI_BAR0, sc->bge_res);
|
||||
|
||||
if (sc->bge_ifp != NULL)
|
||||
if_free(sc->bge_ifp);
|
||||
|
||||
bge_dma_free(sc);
|
||||
|
||||
if (mtx_initialized(&sc->bge_mtx)) /* XXX */
|
||||
|
@ -1627,6 +1627,7 @@ static int cnw_pccard_attach(device_t dev)
|
||||
error = cnw_alloc(dev);
|
||||
if (error) {
|
||||
device_printf(dev, "cnw_alloc() failed! (%d)\n", error);
|
||||
if_free(ifp);
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -1636,6 +1637,7 @@ static int cnw_pccard_attach(device_t dev)
|
||||
if (error) {
|
||||
device_printf(dev, "bus_setup_intr() failed! (%d)\n", error);
|
||||
cnw_free(dev);
|
||||
if_free(ifp);
|
||||
return (error);
|
||||
}
|
||||
|
||||
|
@ -252,6 +252,8 @@ ed_release_resources(device_t dev)
|
||||
sc->irq_rid, sc->irq_res);
|
||||
sc->irq_res = 0;
|
||||
}
|
||||
if (sc->ifp)
|
||||
if_free(sc->ifp);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -374,7 +376,6 @@ ed_detach(device_t dev)
|
||||
ED_UNLOCK(sc);
|
||||
callout_drain(&sc->tick_ch);
|
||||
ether_ifdetach(ifp);
|
||||
if_free(ifp);
|
||||
bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
|
||||
ed_release_resources(dev);
|
||||
ED_LOCK_DESTROY(sc);
|
||||
|
@ -199,8 +199,11 @@ en_pci_attach(device_t dev)
|
||||
sc = device_get_softc(dev);
|
||||
scp = (struct en_pci_softc *)sc;
|
||||
sc->ifp = if_alloc(IFT_ATM);
|
||||
if (sc->ifp == NULL)
|
||||
return (ENOSPC);
|
||||
if (sc->ifp == NULL) {
|
||||
device_printf(dev, "can not if_alloc()\n");
|
||||
error = ENOSPC;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if_initname(sc->ifp, device_get_name(dev),
|
||||
device_get_unit(dev));
|
||||
@ -220,6 +223,7 @@ en_pci_attach(device_t dev)
|
||||
RF_ACTIVE);
|
||||
if (scp->res == NULL) {
|
||||
device_printf(dev, "could not map memory\n");
|
||||
if_free(sc->ifp);
|
||||
error = ENXIO;
|
||||
goto fail;
|
||||
}
|
||||
@ -237,6 +241,7 @@ en_pci_attach(device_t dev)
|
||||
if (scp->irq == NULL) {
|
||||
device_printf(dev, "could not map interrupt\n");
|
||||
bus_release_resource(dev, SYS_RES_MEMORY, PCI_CBMA, scp->res);
|
||||
if_free(sc->ifp);
|
||||
error = ENXIO;
|
||||
goto fail;
|
||||
}
|
||||
@ -267,6 +272,7 @@ en_pci_attach(device_t dev)
|
||||
bus_teardown_intr(dev, scp->irq, scp->ih);
|
||||
bus_release_resource(dev, SYS_RES_IRQ, 0, scp->irq);
|
||||
bus_release_resource(dev, SYS_RES_MEMORY, PCI_CBMA, scp->res);
|
||||
if_free(sc->ifp);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -283,6 +289,7 @@ en_pci_attach(device_t dev)
|
||||
bus_release_resource(dev, SYS_RES_IRQ, 0, scp->irq);
|
||||
bus_release_resource(dev, SYS_RES_MEMORY, PCI_CBMA, scp->res);
|
||||
en_destroy(sc);
|
||||
if_free(sc->ifp);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -196,6 +196,9 @@ ex_release_resources(device_t dev)
|
||||
sc->irq = NULL;
|
||||
}
|
||||
|
||||
if (sc->ifp)
|
||||
if_free(sc->ifp);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -276,7 +279,6 @@ ex_detach(device_t dev)
|
||||
|
||||
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
||||
ether_ifdetach(ifp);
|
||||
if_free(ifp);
|
||||
|
||||
ex_release_resources(dev);
|
||||
|
||||
|
@ -497,6 +497,9 @@ hatm_destroy(struct hatm_softc *sc)
|
||||
cv_destroy(&sc->cv_rcclose);
|
||||
cv_destroy(&sc->vcc_cv);
|
||||
mtx_destroy(&sc->mtx);
|
||||
|
||||
if (sc->ifp != NULL)
|
||||
if_free(sc->ifp);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1631,7 +1634,6 @@ hatm_detach(device_t dev)
|
||||
mtx_unlock(&sc->mtx);
|
||||
|
||||
atm_ifdetach(sc->ifp);
|
||||
if_free(sc->ifp);
|
||||
|
||||
hatm_destroy(sc);
|
||||
|
||||
@ -1655,8 +1657,7 @@ hatm_attach(device_t dev)
|
||||
ifp = sc->ifp = if_alloc(IFT_ATM);
|
||||
if (ifp == NULL) {
|
||||
device_printf(dev, "could not if_alloc()\n");
|
||||
error = ENOSPC;
|
||||
goto failed;
|
||||
return (ENOSPC);
|
||||
}
|
||||
|
||||
sc->dev = dev;
|
||||
|
@ -1777,6 +1777,8 @@ ie_release_resources (device_t dev)
|
||||
if (sc->mem_res)
|
||||
bus_release_resource(dev, SYS_RES_MEMORY,
|
||||
sc->mem_rid, sc->mem_res);
|
||||
if (sc->ifp)
|
||||
if_free(sc->ifp);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -1796,7 +1798,6 @@ ie_detach (device_t dev)
|
||||
ie_stop(sc);
|
||||
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
||||
ether_ifdetach(ifp);
|
||||
if_free(ifp);
|
||||
ie_release_resources(dev);
|
||||
|
||||
return (0);
|
||||
|
@ -1122,8 +1122,9 @@ vge_detach(dev)
|
||||
*/
|
||||
ifp->if_flags &= ~IFF_UP;
|
||||
ether_ifdetach(ifp);
|
||||
if_free(ifp);
|
||||
}
|
||||
if (ifp)
|
||||
if_free(ifp);
|
||||
if (sc->vge_miibus)
|
||||
device_delete_child(dev, sc->vge_miibus);
|
||||
bus_generic_detach(dev);
|
||||
|
Loading…
Reference in New Issue
Block a user