Module Name: src
Committed By: msaitoh
Date: Mon Oct 23 09:27:46 UTC 2017
Modified Files:
src/sys/dev/ic: dwc_gmac.c
Log Message:
- 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.
To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/dev/ic/dwc_gmac.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/ic/dwc_gmac.c
diff -u src/sys/dev/ic/dwc_gmac.c:1.40 src/sys/dev/ic/dwc_gmac.c:1.41
--- src/sys/dev/ic/dwc_gmac.c:1.40 Mon Feb 20 07:43:29 2017
+++ src/sys/dev/ic/dwc_gmac.c Mon Oct 23 09:27:46 2017
@@ -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 *s
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 *s
* 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 *s
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);
}