diff options
| author | msaitoh <msaitoh@NetBSD.org> | 2017-10-23 09:27:46 +0000 |
|---|---|---|
| committer | msaitoh <msaitoh@NetBSD.org> | 2017-10-23 09:27:46 +0000 |
| commit | 9eedcbc3f2a4f80b648f731a022e733de42990c9 (patch) | |
| tree | b1c24d4f99707b430afd4f2451679f26732b2091 /sys/dev | |
| parent | d0ea8ede6bb7d41154d83370ff9c67ae33c7684c (diff) | |
- If if_initialize() failed in the attach function, free resources and return.
- Add missing dwc_gmac_free_dma_rings() and mutex_destroy() when attach
failed.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/ic/dwc_gmac.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/sys/dev/ic/dwc_gmac.c b/sys/dev/ic/dwc_gmac.c index 82fc0849bb6..5983ca3b878 100644 --- a/sys/dev/ic/dwc_gmac.c +++ b/sys/dev/ic/dwc_gmac.c @@ -1,4 +1,4 @@ -/* $NetBSD: dwc_gmac.c,v 1.40 2017/02/20 07:43:29 ozaki-r Exp $ */ +/* $NetBSD: dwc_gmac.c,v 1.41 2017/10/23 09:27:46 msaitoh Exp $ */ /*- * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.40 2017/02/20 07:43:29 ozaki-r Exp $"); +__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.41 2017/10/23 09:27:46 msaitoh Exp $"); /* #define DWC_GMAC_DEBUG 1 */ @@ -146,6 +146,7 @@ dwc_gmac_attach(struct dwc_gmac_softc *sc, uint32_t mii_clk) struct mii_data * const mii = &sc->sc_mii; struct ifnet * const ifp = &sc->sc_ec.ec_if; prop_dictionary_t dict; + int rv; mutex_init(&sc->sc_mdio_lock, MUTEX_DEFAULT, IPL_NET); sc->sc_mii_clk = mii_clk & 7; @@ -259,7 +260,9 @@ dwc_gmac_attach(struct dwc_gmac_softc *sc, uint32_t mii_clk) * Ready, attach interface */ /* Attach the interface. */ - if_initialize(ifp); + rv = if_initialize(ifp); + if (rv != 0) + goto fail_2; sc->sc_ipq = if_percpuq_create(&sc->sc_ec.ec_if); if_deferred_start_init(ifp, NULL); ether_ifattach(ifp, enaddr); @@ -277,10 +280,17 @@ dwc_gmac_attach(struct dwc_gmac_softc *sc, uint32_t mii_clk) mutex_exit(sc->sc_lock); return; - +fail_2: + ifmedia_removeall(&mii->mii_media); + mii_detach(&mii, MII_PHY_ANY, MII_OFFSET_ANY); + mutex_destroy(&sc->sc_txq.t_mtx); + mutex_destroy(&sc->sc_rxq.r_mtx); + mutex_obj_free(sc->sc_lock); fail: dwc_gmac_free_rx_ring(sc, &sc->sc_rxq); dwc_gmac_free_tx_ring(sc, &sc->sc_txq); + dwc_gmac_free_dma_rings(sc); + mutex_destroy(&sc->sc_mdio_lock); } |
