- 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.
This commit is contained in:
msaitoh 2017-10-23 09:27:46 +00:00
parent 82d818af91
commit a80b2b73e3
1 changed files with 14 additions and 4 deletions

View File

@ -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);
}