Source-Changes-HG archive

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

[src/trunk]: src/sys/net - If if_initialize() failed in the attach function, ...



details:   https://anonhg.NetBSD.org/src/rev/68ac212a626b
branches:  trunk
changeset: 357004:68ac212a626b
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Mon Oct 23 09:22:51 2017 +0000

description:
- If if_initialize() failed in the attach function, free resources and return.
- Add some missing frees in bridge_clone_destroy().
- KNF

diffstat:

 sys/net/if_bridge.c |  120 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 66 insertions(+), 54 deletions(-)

diffs (truncated from 462 to 300 lines):

diff -r fe62f3dae3ea -r 68ac212a626b sys/net/if_bridge.c
--- a/sys/net/if_bridge.c       Mon Oct 23 09:22:24 2017 +0000
+++ b/sys/net/if_bridge.c       Mon Oct 23 09:22:51 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_bridge.c,v 1.135 2017/10/02 07:40:24 ozaki-r Exp $  */
+/*     $NetBSD: if_bridge.c,v 1.136 2017/10/23 09:22:51 msaitoh Exp $  */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.135 2017/10/02 07:40:24 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.136 2017/10/23 09:22:51 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bridge_ipf.h"
@@ -436,12 +436,23 @@
        ifp->if_dlt = DLT_EN10MB;
        ifp->if_hdrlen = ETHER_HDR_LEN;
 
-       if_initialize(ifp);
+       error = if_initialize(ifp);
+       if (error != 0) {
+               pserialize_destroy(sc->sc_iflist_psref.bip_psz);
+               mutex_destroy(&sc->sc_iflist_psref.bip_lock);
+               callout_destroy(&sc->sc_brcallout);
+               callout_destroy(&sc->sc_bstpcallout);
+               workqueue_destroy(sc->sc_rtage_wq);
+               bridge_rtable_fini(sc);
+               kmem_free(sc, sizeof(*sc));
+
+               return error;
+       }
        if_register(ifp);
 
        if_alloc_sadl(ifp);
 
-       return (0);
+       return 0;
 }
 
 /*
@@ -480,12 +491,13 @@
 
        pserialize_destroy(sc->sc_iflist_psref.bip_psz);
        mutex_destroy(&sc->sc_iflist_psref.bip_lock);
-
+       callout_destroy(&sc->sc_brcallout);
+       callout_destroy(&sc->sc_bstpcallout);
        workqueue_destroy(sc->sc_rtage_wq);
-
+       kmem_free(sc->sc_rthash, sizeof(*sc->sc_rthash) * BRIDGE_RTHASH_SIZE);
        kmem_free(sc, sizeof(*sc));
 
-       return (0);
+       return 0;
 }
 
 /*
@@ -530,7 +542,7 @@
                     KAUTH_REQ_NETWORK_INTERFACE_BRIDGE_SETPRIV,
                     ifd, NULL, NULL);
                if (error)
-                       return (error);
+                       return error;
 
                break;
        }
@@ -618,7 +630,7 @@
 
        splx(s);
 
-       return (error);
+       return error;
 }
 
 /*
@@ -733,7 +745,7 @@
 
        ifs = if_get(req->ifbr_ifsname, &psref);
        if (ifs == NULL)
-               return (ENOENT);
+               return ENOENT;
 
        if (ifs->if_bridge == sc) {
                error = EEXIST;
@@ -807,7 +819,7 @@
                if (bif != NULL)
                        kmem_free(bif, sizeof(*bif));
        }
-       return (error);
+       return error;
 }
 
 static int
@@ -873,7 +885,7 @@
 
        bif = bridge_lookup_member(sc, req->ifbr_ifsname, &psref);
        if (bif == NULL)
-               return (ENOENT);
+               return ENOENT;
 
        req->ifbr_ifsflags = bif->bif_flags;
        req->ifbr_state = bif->bif_state;
@@ -883,7 +895,7 @@
 
        bridge_release_member(sc, bif, &psref);
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -895,7 +907,7 @@
 
        bif = bridge_lookup_member(sc, req->ifbr_ifsname, &psref);
        if (bif == NULL)
-               return (ENOENT);
+               return ENOENT;
 
        if (req->ifbr_ifsflags & IFBIF_STP) {
                switch (bif->bif_ifp->if_type) {
@@ -907,7 +919,7 @@
                default:
                        /* Nothing else can. */
                        bridge_release_member(sc, bif, &psref);
-                       return (EINVAL);
+                       return EINVAL;
                }
        }
 
@@ -918,7 +930,7 @@
        if (sc->sc_if.if_flags & IFF_RUNNING)
                bstp_initialization(sc);
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -929,7 +941,7 @@
        sc->sc_brtmax = param->ifbrp_csize;
        bridge_rttrim(sc);
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -939,7 +951,7 @@
 
        param->ifbrp_csize = sc->sc_brtmax;
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -1023,7 +1035,7 @@
        int count = 0, error = 0, len;
 
        if (bac->ifbac_len == 0)
-               return (0);
+               return 0;
 
        BRIDGE_RT_LOCK(sc);
 
@@ -1051,7 +1063,7 @@
        BRIDGE_RT_UNLOCK(sc);
 
        bac->ifbac_len = sizeof(bareq) * count;
-       return (error);
+       return error;
 }
 
 static int
@@ -1064,14 +1076,14 @@
 
        bif = bridge_lookup_member(sc, req->ifba_ifsname, &psref);
        if (bif == NULL)
-               return (ENOENT);
+               return ENOENT;
 
        error = bridge_rtupdate(sc, req->ifba_dst, bif->bif_ifp, 1,
            req->ifba_flags);
 
        bridge_release_member(sc, bif, &psref);
 
-       return (error);
+       return error;
 }
 
 static int
@@ -1081,7 +1093,7 @@
 
        sc->sc_brttimeout = param->ifbrp_ctime;
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -1091,7 +1103,7 @@
 
        param->ifbrp_ctime = sc->sc_brttimeout;
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -1109,7 +1121,7 @@
 
        bridge_rtflush(sc, req->ifbr_ifsflags);
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -1119,7 +1131,7 @@
 
        param->ifbrp_prio = sc->sc_bridge_priority;
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -1132,7 +1144,7 @@
        if (sc->sc_if.if_flags & IFF_RUNNING)
                bstp_initialization(sc);
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -1142,7 +1154,7 @@
 
        param->ifbrp_hellotime = sc->sc_bridge_hello_time >> 8;
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -1151,13 +1163,13 @@
        struct ifbrparam *param = arg;
 
        if (param->ifbrp_hellotime == 0)
-               return (EINVAL);
+               return EINVAL;
        sc->sc_bridge_hello_time = param->ifbrp_hellotime << 8;
 
        if (sc->sc_if.if_flags & IFF_RUNNING)
                bstp_initialization(sc);
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -1167,7 +1179,7 @@
 
        param->ifbrp_fwddelay = sc->sc_bridge_forward_delay >> 8;
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -1176,13 +1188,13 @@
        struct ifbrparam *param = arg;
 
        if (param->ifbrp_fwddelay == 0)
-               return (EINVAL);
+               return EINVAL;
        sc->sc_bridge_forward_delay = param->ifbrp_fwddelay << 8;
 
        if (sc->sc_if.if_flags & IFF_RUNNING)
                bstp_initialization(sc);
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -1192,7 +1204,7 @@
 
        param->ifbrp_maxage = sc->sc_bridge_max_age >> 8;
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -1201,13 +1213,13 @@



Home | Main Index | Thread Index | Old Index