git: 64d1a02e4e1a - main - Check for errors from bus_generic_detach in various drivers
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 02 Jan 2025 18:28:26 UTC
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=64d1a02e4e1a5f561d03b2bbc9c20dad255e79e8 commit 64d1a02e4e1a5f561d03b2bbc9c20dad255e79e8 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2025-01-02 18:23:41 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2025-01-02 18:23:41 +0000 Check for errors from bus_generic_detach in various drivers In some cases, move the call to bus_generic_detach earlier so that any detach failures from child devices do not leave the parent device partially detached. Differential Revision: https://reviews.freebsd.org/D47966 --- sys/arm/nvidia/tegra_sdhci.c | 6 +++++- sys/arm/ti/cpsw/if_cpsw.c | 7 +++++-- sys/arm/ti/ti_spi.c | 7 +++++-- sys/arm/xilinx/zy7_devcfg.c | 8 +++++--- sys/arm/xilinx/zy7_qspi.c | 6 ++++-- sys/arm/xilinx/zy7_slcr.c | 5 ++++- sys/arm/xilinx/zy7_spi.c | 6 ++++-- sys/dev/etherswitch/felix/felix.c | 5 +++-- 8 files changed, 35 insertions(+), 15 deletions(-) diff --git a/sys/arm/nvidia/tegra_sdhci.c b/sys/arm/nvidia/tegra_sdhci.c index 3bd9a9bb4632..fa6810b655c6 100644 --- a/sys/arm/nvidia/tegra_sdhci.c +++ b/sys/arm/nvidia/tegra_sdhci.c @@ -417,8 +417,12 @@ tegra_sdhci_detach(device_t dev) { 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 index 9fc3f414477b..ea8f9c18490e 100644 --- a/sys/arm/ti/cpsw/if_cpsw.c +++ b/sys/arm/ti/cpsw/if_cpsw.c @@ -1085,6 +1085,11 @@ static int 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 @@ cpswp_detach(device_t dev) 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 index 26d6691e5bb5..fd0e0b085363 100644 --- a/sys/arm/ti/ti_spi.c +++ b/sys/arm/ti/ti_spi.c @@ -273,6 +273,11 @@ static int 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 @@ ti_spi_detach(device_t dev) /* 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 index 1cb7ff9168cf..6df0fba1f56a 100644 --- a/sys/arm/xilinx/zy7_devcfg.c +++ b/sys/arm/xilinx/zy7_devcfg.c @@ -791,15 +791,17 @@ static int 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 index 53559571f7db..49d4cafd8d61 100644 --- a/sys/arm/xilinx/zy7_qspi.c +++ b/sys/arm/xilinx/zy7_qspi.c @@ -612,9 +612,11 @@ static int 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 index 755b5d4806ed..a46ccb59a07b 100644 --- a/sys/arm/xilinx/zy7_slcr.c +++ b/sys/arm/xilinx/zy7_slcr.c @@ -673,8 +673,11 @@ static int 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 index d032deabf8b7..bb5bb7f46767 100644 --- a/sys/arm/xilinx/zy7_spi.c +++ b/sys/arm/xilinx/zy7_spi.c @@ -448,9 +448,11 @@ static int 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 index b6fb8cbb67c8..098767ee063e 100644 --- a/sys/dev/etherswitch/felix/felix.c +++ b/sys/dev/etherswitch/felix/felix.c @@ -480,9 +480,10 @@ felix_detach(device_t dev) 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);