Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Mar 2022 10:29:29 GMT
From:      Emmanuel Vadot <manu@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 66f5398552a9 - stable/13 - dwc: Release resources when attach fails
Message-ID:  <202203041029.224ATTnp013466@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=66f5398552a9ba58906f01b6acedab51fc04554d

commit 66f5398552a9ba58906f01b6acedab51fc04554d
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2022-02-22 08:53:11 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-03-04 10:29:13 +0000

    dwc: Release resources when attach fails
    
    PR:     259282
    MFC after:      1 week
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    
    (cherry picked from commit 30f16ad460e2f9631484d04f067d80ee578473bc)
---
 sys/dev/dwc/if_dwc.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/sys/dev/dwc/if_dwc.c b/sys/dev/dwc/if_dwc.c
index 429e250f48e8..0704912b48ad 100644
--- a/sys/dev/dwc/if_dwc.c
+++ b/sys/dev/dwc/if_dwc.c
@@ -1619,6 +1619,7 @@ dwc_attach(device_t dev)
 	/* Reset the PHY if needed */
 	if (dwc_reset(dev) != 0) {
 		device_printf(dev, "Can't reset the PHY\n");
+		bus_release_resources(dev, dwc_spec, sc->res);
 		return (ENXIO);
 	}
 
@@ -1634,6 +1635,7 @@ dwc_attach(device_t dev)
 	}
 	if (i >= MAC_RESET_TIMEOUT) {
 		device_printf(sc->dev, "Can't reset DWC.\n");
+		bus_release_resources(dev, dwc_spec, sc->res);
 		return (ENXIO);
 	}
 
@@ -1654,8 +1656,10 @@ dwc_attach(device_t dev)
 	reg &= ~(MODE_ST | MODE_SR);
 	WRITE4(sc, OPERATION_MODE, reg);
 
-	if (setup_dma(sc))
-	        return (ENXIO);
+	if (setup_dma(sc)) {
+		bus_release_resources(dev, dwc_spec, sc->res);
+		return (ENXIO);
+	}
 
 	/* Setup addresses */
 	WRITE4(sc, RX_DESCR_LIST_ADDR, sc->rxdesc_ring_paddr);
@@ -1671,6 +1675,7 @@ dwc_attach(device_t dev)
 	    NULL, dwc_intr, sc, &sc->intr_cookie);
 	if (error != 0) {
 		device_printf(dev, "could not setup interrupt handler.\n");
+		bus_release_resources(dev, dwc_spec, sc->res);
 		return (ENXIO);
 	}
 
@@ -1696,6 +1701,8 @@ dwc_attach(device_t dev)
 
 	if (error != 0) {
 		device_printf(dev, "PHY attach failed\n");
+		bus_teardown_intr(dev, sc->res[1], sc->intr_cookie);
+		bus_release_resources(dev, dwc_spec, sc->res);
 		return (ENXIO);
 	}
 	sc->mii_softc = device_get_softc(sc->miibus);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202203041029.224ATTnp013466>