diff --git a/sys/arm/nvidia/tegra_sdhci.c b/sys/arm/nvidia/tegra_sdhci.c --- a/sys/arm/nvidia/tegra_sdhci.c +++ b/sys/arm/nvidia/tegra_sdhci.c @@ -417,8 +417,12 @@ { struct tegra_sdhci_softc *sc = device_get_softc(dev); struct sdhci_slot *slot = &sc->slot; + int error; + + error = bus_detach_children(dev); + if (error != 0) + return (error); - bus_detach_children(dev); sdhci_fdt_gpio_teardown(sc->gpio); clk_release(sc->clk); bus_teardown_intr(dev, sc->irq_res, sc->intr_cookie); diff --git a/sys/arm/ti/cpsw/if_cpsw.c b/sys/arm/ti/cpsw/if_cpsw.c --- a/sys/arm/ti/cpsw/if_cpsw.c +++ b/sys/arm/ti/cpsw/if_cpsw.c @@ -1085,6 +1085,11 @@ cpswp_detach(device_t dev) { struct cpswp_softc *sc; + int error; + + error = bus_generic_detach(dev); + if (error != 0) + return (error); sc = device_get_softc(dev); CPSW_DEBUGF(sc->swsc, ("")); @@ -1096,8 +1101,6 @@ callout_drain(&sc->mii_callout); } - bus_generic_detach(dev); - if_free(sc->ifp); mtx_destroy(&sc->lock); diff --git a/sys/arm/ti/ti_spi.c b/sys/arm/ti/ti_spi.c --- a/sys/arm/ti/ti_spi.c +++ b/sys/arm/ti/ti_spi.c @@ -273,6 +273,11 @@ ti_spi_detach(device_t dev) { struct ti_spi_softc *sc; + int error; + + error = bus_generic_detach(dev); + if (error != 0) + return (error); sc = device_get_softc(dev); @@ -283,8 +288,6 @@ /* Reset controller. */ TI_SPI_WRITE(sc, MCSPI_SYSCONFIG, MCSPI_SYSCONFIG_SOFTRESET); - bus_generic_detach(dev); - mtx_destroy(&sc->sc_mtx); if (sc->sc_intrhand) bus_teardown_intr(dev, sc->sc_irq_res, sc->sc_intrhand); diff --git a/sys/arm/xilinx/zy7_devcfg.c b/sys/arm/xilinx/zy7_devcfg.c --- a/sys/arm/xilinx/zy7_devcfg.c +++ b/sys/arm/xilinx/zy7_devcfg.c @@ -791,15 +791,17 @@ zy7_devcfg_detach(device_t dev) { struct zy7_devcfg_softc *sc = device_get_softc(dev); + int error; + + error = bus_generic_detach(dev); + if (error != 0) + return (error); if (sc->sysctl_tree_top != NULL) { sysctl_ctx_free(&sc->sysctl_tree); sc->sysctl_tree_top = NULL; } - if (device_is_attached(dev)) - bus_generic_detach(dev); - /* Get rid of /dev/devcfg0. */ if (sc->sc_ctl_dev != NULL) destroy_dev(sc->sc_ctl_dev); diff --git a/sys/arm/xilinx/zy7_qspi.c b/sys/arm/xilinx/zy7_qspi.c --- a/sys/arm/xilinx/zy7_qspi.c +++ b/sys/arm/xilinx/zy7_qspi.c @@ -612,9 +612,11 @@ zy7_qspi_detach(device_t dev) { struct zy7_qspi_softc *sc = device_get_softc(dev); + int error; - if (device_is_attached(dev)) - bus_generic_detach(dev); + error = bus_generic_detach(dev); + if (error != 0) + return (error); /* Disable hardware. */ if (sc->mem_res != NULL) { diff --git a/sys/arm/xilinx/zy7_slcr.c b/sys/arm/xilinx/zy7_slcr.c --- a/sys/arm/xilinx/zy7_slcr.c +++ b/sys/arm/xilinx/zy7_slcr.c @@ -673,8 +673,11 @@ zy7_slcr_detach(device_t dev) { struct zy7_slcr_softc *sc = device_get_softc(dev); + int error; - bus_generic_detach(dev); + error = bus_generic_detach(dev); + if (error != 0) + return (error); /* Release memory resource. */ if (sc->mem_res != NULL) diff --git a/sys/arm/xilinx/zy7_spi.c b/sys/arm/xilinx/zy7_spi.c --- a/sys/arm/xilinx/zy7_spi.c +++ b/sys/arm/xilinx/zy7_spi.c @@ -448,9 +448,11 @@ zy7_spi_detach(device_t dev) { struct zy7_spi_softc *sc = device_get_softc(dev); + int error; - if (device_is_attached(dev)) - bus_generic_detach(dev); + error = bus_generic_detach(dev); + if (error != 0) + return (error); /* Disable hardware. */ if (sc->mem_res != NULL) { diff --git a/sys/dev/etherswitch/felix/felix.c b/sys/dev/etherswitch/felix/felix.c --- a/sys/dev/etherswitch/felix/felix.c +++ b/sys/dev/etherswitch/felix/felix.c @@ -480,9 +480,10 @@ int error; int i; - error = 0; sc = device_get_softc(dev); - bus_generic_detach(dev); + error = bus_generic_detach(dev); + if (error != 0) + return (error); mtx_lock(&sc->mtx); callout_stop(&sc->tick_callout);