Use bus_generic_detach instead of device_delete_children in detach

While here, check for errors from bus_generic_detach and move it to
the start of detach if necessary.

Differential Revision:	https://reviews.freebsd.org/D47969
This commit is contained in:
John Baldwin
2025-01-02 13:24:28 -05:00
parent 20f932af29
commit 3ddaf8200b
46 changed files with 139 additions and 76 deletions
+1 -1
View File
@@ -386,7 +386,7 @@ vybrid_ehci_detach(device_t dev)
sc = &esc->base;
/* First detach all children; we can't detach if that fails. */
if ((err = device_delete_children(dev)) != 0)
if ((err = bus_generic_detach(dev)) != 0)
return (err);
/*
+1 -1
View File
@@ -227,7 +227,7 @@ a37x0_spi_detach(device_t dev)
int err;
struct a37x0_spi_softc *sc;
if ((err = device_delete_children(dev)) != 0)
if ((err = bus_generic_detach(dev)) != 0)
return (err);
sc = device_get_softc(dev);
mtx_destroy(&sc->sc_mtx);
+5 -5
View File
@@ -113,14 +113,17 @@ tegra_ehci_detach(device_t dev)
{
struct tegra_ehci_softc *sc;
ehci_softc_t *esc;
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
esc = &sc->ehci_softc;
if (sc->clk != NULL)
clk_release(sc->clk);
if (esc->sc_bus.bdev != NULL)
device_delete_child(dev, esc->sc_bus.bdev);
if (esc->sc_flags & EHCI_SCFLG_DONEINIT)
ehci_detach(esc);
if (esc->sc_intr_hdl != NULL)
@@ -135,9 +138,6 @@ tegra_ehci_detach(device_t dev)
if (sc->usb_alloc_called)
usb_bus_mem_free_all(&esc->sc_bus, &ehci_iterate_hw_softc);
/* During module unload there are lots of children leftover. */
device_delete_children(dev);
return (0);
}
+5 -1
View File
@@ -916,12 +916,16 @@ tegra_xhci_detach(device_t dev)
{
struct tegra_xhci_softc *sc;
struct xhci_softc *xsc;
int error;
sc = device_get_softc(dev);
xsc = &sc->xhci_softc;
/* during module unload there are lots of children leftover */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
if (sc->xhci_inited) {
usb_callout_drain(&xsc->sc_callout);
xhci_halt_controller(xsc);
+4 -1
View File
@@ -404,9 +404,12 @@ static int
musbotg_detach(device_t dev)
{
struct musbotg_super_softc *sc = device_get_softc(dev);
int error;
/* during module unload there are lots of children leftover */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
if (sc->sc_otg.sc_irq_res && sc->sc_otg.sc_intr_hdl) {
/*
+3 -1
View File
@@ -406,7 +406,9 @@ omap_ehci_detach(device_t dev)
int err;
/* during module unload there are lots of children leftover */
device_delete_children(dev);
err = bus_generic_detach(dev);
if (err != 0)
return (err);
/*
* disable interrupts that might have been switched on in ehci_init
+4 -1
View File
@@ -432,9 +432,12 @@ static int
omap_uhh_detach(device_t dev)
{
struct omap_uhh_softc *isc = device_get_softc(dev);
int error;
/* during module unload there are lots of children leftover */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
if (isc->uhh_mem_res) {
bus_release_resource(dev, SYS_RES_MEMORY, 0, isc->uhh_mem_res);
+4 -1
View File
@@ -315,9 +315,12 @@ static int
zy7_ehci_detach(device_t dev)
{
ehci_softc_t *sc = device_get_softc(dev);
int error;
/* during module unload there are lots of children leftover */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
if ((sc->sc_flags & EHCI_SCFLG_DONEINIT) != 0) {
ehci_detach(sc);
+4 -2
View File
@@ -391,10 +391,12 @@ int
ahci_detach(device_t dev)
{
struct ahci_controller *ctlr = device_get_softc(dev);
int i;
int error, i;
/* Detach & delete all children */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
/* Free interrupts. */
for (i = 0; i < ctlr->numirqs; i++) {
+4 -1
View File
@@ -134,9 +134,12 @@ int
ata_pci_detach(device_t dev)
{
struct ata_pci_controller *ctlr = device_get_softc(dev);
int error;
/* detach & delete all children */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
if (ctlr->r_irq) {
bus_teardown_intr(dev, ctlr->r_irq, ctlr->handle);
+1 -1
View File
@@ -545,7 +545,7 @@ atopcase_destroy(struct atopcase_softc *sc)
{
int err;
err = device_delete_children(sc->sc_dev);
err = bus_generic_detach(sc->sc_dev);
if (err)
return (err);
+5 -3
View File
@@ -845,19 +845,21 @@ e6000sw_writephy_locked(device_t dev, int phy, int reg, int data)
static int
e6000sw_detach(device_t dev)
{
int phy;
int error, phy;
e6000sw_softc_t *sc;
sc = device_get_softc(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
if (device_is_attached(dev))
taskqueue_drain_timeout(sc->sc_tq, &sc->sc_tt);
if (sc->sc_tq != NULL)
taskqueue_free(sc->sc_tq);
device_delete_children(dev);
sx_destroy(&sc->sx);
for (phy = 0; phy < sc->num_ports; phy++) {
if (sc->ifp[phy] != NULL)
+1 -1
View File
@@ -457,7 +457,7 @@ hv_hid_detach(device_t dev)
int ret;
sc = device_get_softc(dev);
ret = device_delete_children(dev);
ret = bus_generic_detach(dev);
if (ret != 0)
return (ret);
if (sc->hs_xact_ctx != NULL)
+1 -1
View File
@@ -144,7 +144,7 @@ iicbus_detach(device_t dev)
struct iicbus_softc *sc = IICBUS_SOFTC(dev);
int err;
if ((err = device_delete_children(dev)) != 0)
if ((err = bus_generic_detach(dev)) != 0)
return (err);
iicbus_reset(dev, IIC_FASTEST, 0, NULL);
mtx_destroy(&sc->lock);
+1 -1
View File
@@ -1218,7 +1218,7 @@ iichid_detach(device_t dev)
int error;
sc = device_get_softc(dev);
error = device_delete_children(dev);
error = bus_generic_detach(dev);
if (error)
return (error);
iichid_teardown_interrupt(sc);
+6 -1
View File
@@ -550,9 +550,14 @@ int
intelspi_detach(device_t dev)
{
struct intelspi_softc *sc;
int error;
sc = device_get_softc(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
INTELSPI_LOCK_DESTROY(sc);
if (sc->sc_irq_ih)
@@ -566,7 +571,7 @@ intelspi_detach(device_t dev)
bus_release_resource(dev, SYS_RES_IRQ,
sc->sc_irq_rid, sc->sc_irq_res);
return (device_delete_children(dev));
return (0);
}
int
+1 -1
View File
@@ -778,7 +778,7 @@ dwmmc_detach(device_t dev)
sc = device_get_softc(dev);
ret = device_delete_children(dev);
ret = bus_generic_detach(dev);
if (ret != 0)
return (ret);
+4 -1
View File
@@ -176,9 +176,12 @@ static int
mvs_detach(device_t dev)
{
struct mvs_controller *ctlr = device_get_softc(dev);
int error;
/* Detach & delete all children */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
/* Free interrupt. */
if (ctlr->irq.r_irq) {
+4 -1
View File
@@ -180,9 +180,12 @@ static int
mvs_detach(device_t dev)
{
struct mvs_controller *ctlr = device_get_softc(dev);
int error;
/* Detach & delete all children */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
/* Free interrupt. */
if (ctlr->irq.r_irq) {
+1 -1
View File
@@ -843,7 +843,7 @@ mvneta_detach(device_t dev)
for (q = 0; q < MVNETA_TX_QNUM_MAX; q++)
mvneta_ring_dealloc_tx_queue(sc, q);
device_delete_children(dev);
bus_generic_detach(dev);
if (sc->ih_cookie[0] != NULL)
bus_teardown_intr(dev, sc->res[1], sc->ih_cookie[0]);
+1 -1
View File
@@ -146,7 +146,7 @@ owc_gpiobus_detach(device_t dev)
sc = device_get_softc(dev);
if ((err = device_delete_children(dev)) != 0)
if ((err = bus_generic_detach(dev)) != 0)
return (err);
gpio_pin_release(sc->sc_pin);
+5 -1
View File
@@ -159,9 +159,13 @@ static int
p2sb_detach(device_t dev)
{
struct p2sb_softc *sc;
int error;
/* Teardown the state in our softc created in our attach routine. */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
sc = device_get_softc(dev);
mtx_destroy(&sc->mutex);
if (sc->res != NULL)
+4 -1
View File
@@ -1815,13 +1815,16 @@ int
ppc_detach(device_t dev)
{
struct ppc_data *ppc = DEVTOSOFTC(dev);
int error;
if (ppc->res_irq == 0) {
return (ENXIO);
}
/* detach & delete all children */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
if (ppc->res_irq != 0) {
bus_teardown_intr(dev, ppc->res_irq, ppc->intr_cookie);
+2 -2
View File
@@ -3784,10 +3784,10 @@ rtsx_detach(device_t dev)
WRITE4(sc, RTSX_BIER, sc->rtsx_intr_enabled);
/* Stop device. */
error = device_delete_children(sc->rtsx_dev);
sc->rtsx_mmc_dev = NULL;
error = bus_generic_detach(sc->rtsx_dev);
if (error)
return (error);
sc->rtsx_mmc_dev = NULL;
taskqueue_drain_timeout(taskqueue_swi_giant, &sc->rtsx_card_insert_task);
taskqueue_drain(taskqueue_swi_giant, &sc->rtsx_card_remove_task);
+4 -1
View File
@@ -203,9 +203,12 @@ static int
siis_detach(device_t dev)
{
struct siis_controller *ctlr = device_get_softc(dev);
int error;
/* Detach & delete all children */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
/* Free interrupts. */
if (ctlr->irq.r_irq) {
+1 -1
View File
@@ -6684,7 +6684,7 @@ hdaa_detach(device_t dev)
struct hdaa_devinfo *devinfo = device_get_softc(dev);
int error;
if ((error = device_delete_children(dev)) != 0)
if ((error = bus_generic_detach(dev)) != 0)
return (error);
hdaa_lock(devinfo);
+1 -1
View File
@@ -541,7 +541,7 @@ hdacc_detach(device_t dev)
struct hdacc_softc *codec = device_get_softc(dev);
int error;
if ((error = device_delete_children(dev)) != 0)
if ((error = bus_generic_detach(dev)) != 0)
return (error);
free(codec->fgs, M_HDACC);
return (0);
+1 -1
View File
@@ -985,7 +985,7 @@ hdsp_detach(device_t dev)
return (0);
}
err = device_delete_children(dev);
err = bus_generic_detach(dev);
if (err)
return (err);
+1 -1
View File
@@ -877,7 +877,7 @@ hdspe_detach(device_t dev)
return (0);
}
err = device_delete_children(dev);
err = bus_generic_detach(dev);
if (err)
return (err);
+1 -1
View File
@@ -68,7 +68,7 @@ spibus_attach(device_t dev)
int
spibus_detach(device_t dev)
{
return (device_delete_children(dev));
return (bus_generic_detach(dev));
}
static int
+4 -1
View File
@@ -127,9 +127,12 @@ static int
dwc_otg_detach(device_t dev)
{
struct dwc_otg_softc *sc = device_get_softc(dev);
int error;
/* during module unload there are lots of children leftover */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
if (sc->sc_irq_res && sc->sc_intr_hdl) {
/*
+4 -1
View File
@@ -162,9 +162,12 @@ int
dwc_otg_detach(device_t dev)
{
struct dwc_otg_fdt_softc *sc = device_get_softc(dev);
int error;
/* during module unload there are lots of children leftover */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
if (sc->sc_otg.sc_irq_res && sc->sc_otg.sc_intr_hdl) {
/*
+5 -9
View File
@@ -372,10 +372,14 @@ fsl_ehci_attach(device_t self)
static int
fsl_ehci_detach(device_t self)
{
int err;
ehci_softc_t *sc;
/* During module unload there are lots of children leftover */
err = bus_generic_detach(self);
if (err != 0)
return (err);
sc = device_get_softc(self);
/*
* only call ehci_detach() after ehci_init()
@@ -399,14 +403,6 @@ fsl_ehci_detach(device_t self)
sc->sc_intr_hdl = NULL;
}
if (sc->sc_bus.bdev) {
device_delete_child(self, sc->sc_bus.bdev);
sc->sc_bus.bdev = NULL;
}
/* During module unload there are lots of children leftover */
device_delete_children(self);
if (sc->sc_irq_res) {
bus_release_resource(self, SYS_RES_IRQ, 0, sc->sc_irq_res);
sc->sc_irq_res = NULL;
+1 -1
View File
@@ -314,7 +314,7 @@ imx_ehci_detach(device_t dev)
esc = &sc->ehci_softc;
/* First detach all children; we can't detach if that fails. */
if ((err = device_delete_children(dev)) != 0)
if ((err = bus_generic_detach(dev)) != 0)
return (err);
if (esc->sc_flags & EHCI_SCFLG_DONEINIT)
+3 -7
View File
@@ -171,13 +171,9 @@ ehci_msm_detach(device_t dev)
sc = device_get_softc(dev);
if (sc->sc_bus.bdev) {
bdev = sc->sc_bus.bdev;
device_detach(bdev);
device_delete_child(dev, bdev);
}
device_delete_children(dev);
err = bus_generic_detach(dev);
if (err != 0)
return (err);
if (sc->sc_irq_res && sc->sc_intr_hdl) {
/* only call ehci_detach() after ehci_init() */
+3 -1
View File
@@ -283,7 +283,9 @@ mv_ehci_detach(device_t self)
int err;
/* during module unload there are lots of children leftover */
device_delete_children(self);
err = bus_generic_detach(self);
if (err != 0)
return (err);
/*
* disable interrupts that might have been switched on in mv_ehci_attach
+4 -1
View File
@@ -505,9 +505,12 @@ static int
ehci_pci_detach(device_t self)
{
ehci_softc_t *sc = device_get_softc(self);
int error;
/* during module unload there are lots of children leftover */
device_delete_children(self);
error = bus_generic_detach(self);
if (error != 0)
return (error);
pci_disable_busmaster(self);
+3 -1
View File
@@ -139,7 +139,9 @@ generic_ehci_detach(device_t self)
int err;
/* during module unload there are lots of children leftover */
device_delete_children(self);
err = bus_generic_detach(self);
if (err != 0)
return (err);
if (sc->sc_irq_res && sc->sc_intr_hdl) {
/*
+3 -1
View File
@@ -231,7 +231,9 @@ generic_ohci_detach(device_t dev)
struct hwrst_list *rst, *rst_tmp;
/* during module unload there are lots of children leftover */
device_delete_children(dev);
err = bus_generic_detach(dev);
if (err != 0)
return (err);
/*
* Put the controller into reset, then disable clocks and do
+3 -1
View File
@@ -152,7 +152,9 @@ generic_xhci_detach(device_t dev)
int err;
/* during module unload there are lots of children leftover */
device_delete_children(dev);
err = bus_generic_detach(dev);
if (err != 0)
return (err);
if (sc->sc_irq_res != NULL && sc->sc_intr_hdl != NULL) {
err = bus_teardown_intr(dev, sc->sc_irq_res, sc->sc_intr_hdl);
+4 -9
View File
@@ -561,16 +561,13 @@ static int
awusbdrd_detach(device_t dev)
{
struct awusbdrd_softc *sc;
device_t bdev;
int error;
sc = device_get_softc(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
if (sc->sc.sc_bus.bdev != NULL) {
bdev = sc->sc.sc_bus.bdev;
device_detach(bdev);
device_delete_child(dev, bdev);
}
sc = device_get_softc(dev);
musbotg_uninit(&sc->sc);
error = bus_teardown_intr(dev, sc->res[1], sc->sc.sc_intr_hdl);
@@ -594,8 +591,6 @@ awusbdrd_detach(device_t dev)
bus_release_resources(dev, awusbdrd_spec, sc->res);
device_delete_children(dev);
return (0);
}
+4 -1
View File
@@ -320,9 +320,12 @@ static int
ohci_pci_detach(device_t self)
{
ohci_softc_t *sc = device_get_softc(self);
int error;
/* during module unload there are lots of children leftover */
device_delete_children(self);
error = bus_generic_detach(self);
if (error != 0)
return (error);
pci_disable_busmaster(self);
+4 -1
View File
@@ -414,9 +414,12 @@ int
uhci_pci_detach(device_t self)
{
uhci_softc_t *sc = device_get_softc(self);
int error;
/* during module unload there are lots of children leftover */
device_delete_children(self);
error = bus_generic_detach(self);
if (error != 0)
return (error);
/*
* disable interrupts that might have been switched on in
+4 -1
View File
@@ -465,9 +465,12 @@ static int
xhci_pci_detach(device_t self)
{
struct xhci_softc *sc = device_get_softc(self);
int error;
/* during module unload there are lots of children leftover */
device_delete_children(self);
error = bus_generic_detach(self);
if (error != 0)
return (error);
usb_callout_drain(&sc->sc_callout);
xhci_halt_controller(sc);
+5 -1
View File
@@ -851,8 +851,12 @@ static int
usbhid_detach(device_t dev)
{
struct usbhid_softc *sc = device_get_softc(dev);
int error;
error = bus_generic_detach(dev);
if (error != 0)
return (error);
device_delete_children(dev);
mtx_destroy(&sc->sc_mtx);
return (0);
+4 -1
View File
@@ -441,9 +441,12 @@ static int
udl_detach(device_t dev)
{
struct udl_softc *sc = device_get_softc(dev);
int error;
/* delete all child devices */
device_delete_children(dev);
error = bus_generic_detach(dev);
if (error != 0)
return (error);
UDL_LOCK(sc);
sc->sc_gone = 1;