Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/powerpc/booke/dev If error occured in pq3etsec_atta...



details:   https://anonhg.NetBSD.org/src/rev/40d2f504073e
branches:  trunk
changeset: 827307:40d2f504073e
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Mon Oct 23 09:23:48 2017 +0000

description:
If error occured in pq3etsec_attach(), free resources and return.

diffstat:

 sys/arch/powerpc/booke/dev/pq3etsec.c |  61 +++++++++++++++++++++++++++-------
 1 files changed, 48 insertions(+), 13 deletions(-)

diffs (155 lines):

diff -r 5d8507350461 -r 40d2f504073e sys/arch/powerpc/booke/dev/pq3etsec.c
--- a/sys/arch/powerpc/booke/dev/pq3etsec.c     Mon Oct 23 09:23:25 2017 +0000
+++ b/sys/arch/powerpc/booke/dev/pq3etsec.c     Mon Oct 23 09:23:48 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pq3etsec.c,v 1.31 2017/10/02 01:55:40 knakahara Exp $  */
+/*     $NetBSD: pq3etsec.c,v 1.32 2017/10/23 09:23:48 msaitoh Exp $    */
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -41,7 +41,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.31 2017/10/02 01:55:40 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.32 2017/10/23 09:23:48 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -648,27 +648,27 @@
        error = pq3etsec_rxq_attach(sc, &sc->sc_rxq, 0);
        if (error) {
                aprint_error(": failed to init rxq: %d\n", error);
-               return;
+               goto fail_1;
        }
 
        error = pq3etsec_txq_attach(sc, &sc->sc_txq, 0);
        if (error) {
                aprint_error(": failed to init txq: %d\n", error);
-               return;
+               goto fail_2;
        }
 
        error = pq3etsec_mapcache_create(sc, &sc->sc_rx_mapcache, 
            ETSEC_MAXRXMBUFS, MCLBYTES, ETSEC_NRXSEGS);
        if (error) {
                aprint_error(": failed to allocate rx dmamaps: %d\n", error);
-               return;
+               goto fail_3;
        }
 
        error = pq3etsec_mapcache_create(sc, &sc->sc_tx_mapcache, 
            ETSEC_MAXTXMBUFS, MCLBYTES, ETSEC_NTXSEGS);
        if (error) {
                aprint_error(": failed to allocate tx dmamaps: %d\n", error);
-               return;
+               goto fail_4;
        }
 
        sc->sc_tx_ih = intr_establish(cnl->cnl_intrs[0], IPL_VM, IST_ONCHIP,
@@ -676,7 +676,7 @@
        if (sc->sc_tx_ih == NULL) {
                aprint_error(": failed to establish tx interrupt: %d\n",
                    cnl->cnl_intrs[0]);
-               return;
+               goto fail_5;
        }
 
        sc->sc_rx_ih = intr_establish(cnl->cnl_intrs[1], IPL_VM, IST_ONCHIP,
@@ -684,7 +684,7 @@
        if (sc->sc_rx_ih == NULL) {
                aprint_error(": failed to establish rx interrupt: %d\n",
                    cnl->cnl_intrs[1]);
-               return;
+               goto fail_6;
        }
 
        sc->sc_error_ih = intr_establish(cnl->cnl_intrs[2], IPL_VM, IST_ONCHIP,
@@ -692,7 +692,7 @@
        if (sc->sc_error_ih == NULL) {
                aprint_error(": failed to establish error interrupt: %d\n",
                    cnl->cnl_intrs[2]);
-               return;
+               goto fail_7;
        }
 
        int softint_flags = SOFTINT_NET;
@@ -703,7 +703,7 @@
            pq3etsec_soft_intr, sc);
        if (sc->sc_soft_ih == NULL) {
                aprint_error(": failed to establish soft interrupt\n");
-               return;
+               goto fail_8;
        }
 
        /*
@@ -719,7 +719,7 @@
                sc->sc_mdio_dev = device_find_by_driver_unit("mdio", mdio);
                if (sc->sc_mdio_dev == NULL) {
                        aprint_error(": failed to locate mdio device\n");
-                       return;
+                       goto fail_9;
                }
                aprint_normal("\n");
        }
@@ -734,7 +734,6 @@
        sc->sc_ic_tx_count = 16;
        pq3etsec_set_ic_rx(sc);
        pq3etsec_set_ic_tx(sc);
-       pq3etsec_sysctl_setup(NULL, sc);
 
        char enaddr[ETHER_ADDR_LEN] = {
            [0] = sc->sc_macstnaddr2 >> 16,
@@ -794,7 +793,13 @@
        /*
         * Attach the interface.
         */
-       if_initialize(ifp);
+       error = if_initialize(ifp);
+       if (error != 0) {
+               aprint_error_dev(sc->sc_dev, "if_initialize failed(%d)\n",
+                   error);
+               goto fail_10;
+       }
+       pq3etsec_sysctl_setup(NULL, sc);
        ether_ifattach(ifp, enaddr);
        if_register(ifp);
 
@@ -818,6 +823,36 @@
            NULL, xname, "rx pause");
        evcnt_attach_dynamic(&sc->sc_ev_mii_ticks, EVCNT_TYPE_MISC,
            NULL, xname, "mii ticks");
+       return;
+
+fail_10:
+       ifmedia_removeall(&sc->sc_mii.mii_media);
+       mii_detach(&sc->sc_mii, sc->sc_phy_addr, MII_OFFSET_ANY);
+fail_9:
+       softint_disestablish(sc->sc_soft_ih);
+fail_8:
+       intr_disestablish(sc->sc_error_ih);
+fail_7:
+       intr_disestablish(sc->sc_rx_ih);
+fail_6:
+       intr_disestablish(sc->sc_tx_ih);
+fail_5:
+       pq3etsec_mapcache_destroy(sc, sc->sc_tx_mapcache);
+fail_4:
+       pq3etsec_mapcache_destroy(sc, sc->sc_rx_mapcache);
+fail_3:
+#if 0 /* notyet */
+       pq3etsec_txq_detach(sc);
+#endif
+fail_2:
+#if 0 /* notyet */
+       pq3etsec_rxq_detach(sc);
+#endif
+fail_1:
+       callout_destroy(&sc->sc_mii_callout);
+       mutex_obj_free(sc->sc_lock);
+       mutex_obj_free(sc->sc_hwlock);
+       bus_space_unmap(sc->sc_bst, sc->sc_bsh, cnl->cnl_size);
 }
 
 static uint64_t



Home | Main Index | Thread Index | Old Index