Source-Changes-HG archive

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

[src/trunk]: src/sys/net Mostly style, and add a bunch of KASSERTs.



details:   https://anonhg.NetBSD.org/src/rev/9ef6b5d7ad60
branches:  trunk
changeset: 829052:9ef6b5d7ad60
user:      maxv <maxv%NetBSD.org@localhost>
date:      Mon Jan 15 16:36:51 2018 +0000

description:
Mostly style, and add a bunch of KASSERTs.

diffstat:

 sys/net/if_ether.h   |    6 +-
 sys/net/if_vlan.c    |  174 +++++++++++++++++++++++---------------------------
 sys/net/if_vlanvar.h |    4 +-
 3 files changed, 84 insertions(+), 100 deletions(-)

diffs (truncated from 494 to 300 lines):

diff -r d77861950bea -r 9ef6b5d7ad60 sys/net/if_ether.h
--- a/sys/net/if_ether.h        Mon Jan 15 14:38:06 2018 +0000
+++ b/sys/net/if_ether.h        Mon Jan 15 16:36:51 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ether.h,v 1.70 2017/11/22 03:45:15 msaitoh Exp $    */
+/*     $NetBSD: if_ether.h,v 1.71 2018/01/15 16:36:51 maxv Exp $       */
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -301,9 +301,8 @@
 static inline void
 vlan_set_tag(struct mbuf *m, uint16_t vlantag)
 {
-
        /* VLAN tag contains priority, CFI and VLAN ID */
-
+       KASSERT((m->m_flags & M_PKTHDR) != 0);
        m->m_pkthdr.ether_vtag = vlantag;
        m->m_flags |= M_VLANTAG;
        return;
@@ -319,6 +318,7 @@
 static inline uint16_t
 vlan_get_tag(struct mbuf *m)
 {
+       KASSERT((m->m_flags & M_PKTHDR) != 0);
        KASSERT(m->m_flags & M_VLANTAG);
        return m->m_pkthdr.ether_vtag;
 }
diff -r d77861950bea -r 9ef6b5d7ad60 sys/net/if_vlan.c
--- a/sys/net/if_vlan.c Mon Jan 15 14:38:06 2018 +0000
+++ b/sys/net/if_vlan.c Mon Jan 15 16:36:51 2018 +0000
@@ -1,6 +1,6 @@
-/*     $NetBSD: if_vlan.c,v 1.123 2018/01/15 08:45:19 maxv Exp $       */
+/*     $NetBSD: if_vlan.c,v 1.124 2018/01/15 16:36:51 maxv Exp $       */
 
-/*-
+/*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.123 2018/01/15 08:45:19 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.124 2018/01/15 16:36:51 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -250,9 +250,11 @@
 vlan_safe_ifpromisc(struct ifnet *ifp, int pswitch)
 {
        int e;
+
        KERNEL_LOCK_UNLESS_NET_MPSAFE();
        e = ifpromisc(ifp, pswitch);
        KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
+
        return e;
 }
 
@@ -260,9 +262,11 @@
 vlan_safe_ifpromisc_locked(struct ifnet *ifp, int pswitch)
 {
        int e;
+
        KERNEL_LOCK_UNLESS_NET_MPSAFE();
        e = ifpromisc_locked(ifp, pswitch);
        KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
+
        return e;
 }
 
@@ -272,7 +276,7 @@
 
        /*
         * Nothing to do here, initialization is handled by the
-        * module initialization code in vlaninit() below).
+        * module initialization code in vlaninit() below.
         */
 }
 
@@ -293,14 +297,15 @@
 static int
 vlandetach(void)
 {
-       int error = 0;
+       bool is_empty;
+       int error;
 
        mutex_enter(&ifv_list.lock);
-       if (!LIST_EMPTY(&ifv_list.list)) {
-               mutex_exit(&ifv_list.lock);
+       is_empty = LIST_EMPTY(&ifv_list.list);
+       mutex_exit(&ifv_list.lock);
+
+       if (!is_empty)
                return EBUSY;
-       }
-       mutex_exit(&ifv_list.lock);
 
        error = vlan_hash_fini();
        if (error != 0)
@@ -411,7 +416,7 @@
        mutex_destroy(&ifv->ifv_lock);
        free(ifv, M_DEVBUF);
 
-       return (0);
+       return 0;
 }
 
 /*
@@ -423,9 +428,9 @@
        struct ifnet *ifp = &ifv->ifv_if;
        struct ifvlan_linkmib *nmib = NULL;
        struct ifvlan_linkmib *omib = NULL;
-       struct ifvlan_linkmib *checkmib = NULL;
+       struct ifvlan_linkmib *checkmib;
        struct psref_target *nmib_psref = NULL;
-       uint16_t vid = EVL_VLANOFTAG(tag);
+       const uint16_t vid = EVL_VLANOFTAG(tag);
        int error = 0;
        int idx;
        bool omib_cleanup = false;
@@ -436,7 +441,6 @@
                return EINVAL;
 
        nmib = kmem_alloc(sizeof(*nmib), KM_SLEEP);
-
        mutex_enter(&ifv->ifv_lock);
        omib = ifv->ifv_mib;
 
@@ -461,7 +465,7 @@
        switch (p->if_type) {
        case IFT_ETHER:
            {
-               struct ethercom *ec = (void *) p;
+               struct ethercom *ec = (void *)p;
                nmib->ifvm_msw = &vlan_ether_multisw;
                nmib->ifvm_encaplen = ETHER_VLAN_ENCAP_LEN;
                nmib->ifvm_mintu = ETHERMIN;
@@ -496,7 +500,7 @@
                 * offload.
                 */
                if (ec->ec_capabilities & ETHERCAP_VLAN_HWTAGGING) {
-                       ec->ec_capenable |= ETHERCAP_VLAN_HWTAGGING;
+                       ec->ec_capenable |= ETHERCAP_VLAN_HWTAGGING;
                        ifp->if_capabilities = p->if_capabilities &
                            (IFCAP_TSOv4 | IFCAP_TSOv6 |
                             IFCAP_CSUM_IPv4_Tx|IFCAP_CSUM_IPv4_Rx|
@@ -504,7 +508,8 @@
                             IFCAP_CSUM_UDPv4_Tx|IFCAP_CSUM_UDPv4_Rx|
                             IFCAP_CSUM_TCPv6_Tx|IFCAP_CSUM_TCPv6_Rx|
                             IFCAP_CSUM_UDPv6_Tx|IFCAP_CSUM_UDPv6_Rx);
-                }
+               }
+
                /*
                 * We inherit the parent's Ethernet address.
                 */
@@ -547,10 +552,8 @@
 
        if (nmib_psref)
                psref_target_destroy(nmib_psref, ifvm_psref_class);
-
        if (nmib)
                kmem_free(nmib, sizeof(*nmib));
-
        if (omib_cleanup)
                kmem_free(omib, sizeof(*omib));
 
@@ -629,10 +632,8 @@
                break;
            }
 
-#ifdef DIAGNOSTIC
        default:
-               panic("vlan_unconfig: impossible");
-#endif
+               panic("%s: impossible", __func__);
        }
 
        nmib->ifvm_p = NULL;
@@ -839,9 +840,11 @@
        LIST_FOREACH(ifv, &ifv_list.list, ifv_list) {
                struct ifnet *ifp = &ifv->ifv_if;
 
-               /* Need IFNET_LOCK that must be held before ifv_lock. */
+               /* IFNET_LOCK must be held before ifv_lock. */
                IFNET_LOCK(ifp);
                mutex_enter(&ifv->ifv_lock);
+
+               /* XXX ifv_mib = NULL? */
                if (ifv->ifv_mib->ifvm_p == p) {
                        KASSERTMSG(i < cnt, "no memory for unconfig, parent=%s",
                            p->if_xname);
@@ -852,6 +855,7 @@
                        }
 
                }
+
                mutex_exit(&ifv->ifv_lock);
                IFNET_UNLOCK(ifp);
        }
@@ -902,13 +906,13 @@
        vlan_putref_linkmib(mib, &psref);
        curlwp_bindx(bound);
 
-       return (error);
+       return error;
 }
 
 static int
 vlan_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
-       struct lwp *l = curlwp; /* XXX */
+       struct lwp *l = curlwp;
        struct ifvlan *ifv = ifp->if_softc;
        struct ifaddr *ifa = (struct ifaddr *) data;
        struct ifreq *ifr = (struct ifreq *) data;
@@ -946,7 +950,7 @@
 
                        error = ifioctl_common(ifp, cmd, data);
                        if (error == ENETRESET)
-                                       error = 0;
+                               error = 0;
                }
 
                break;
@@ -1127,7 +1131,7 @@
                error = ether_ioctl(ifp, cmd, data);
        }
 
-       return (error);
+       return error;
 }
 
 static int
@@ -1142,16 +1146,16 @@
        KASSERT(mutex_owned(&ifv->ifv_lock));
 
        if (sa->sa_len > sizeof(struct sockaddr_storage))
-               return (EINVAL);
+               return EINVAL;
 
        error = ether_addmulti(sa, &ifv->ifv_ec);
        if (error != ENETRESET)
-               return (error);
+               return error;
 
        /*
-        * This is new multicast address.  We have to tell parent
+        * This is a new multicast address.  We have to tell parent
         * about it.  Also, remember this multicast address so that
-        * we can delete them on unconfigure.
+        * we can delete it on unconfigure.
         */
        mc = malloc(sizeof(struct vlan_mc_entry), M_DEVBUF, M_NOWAIT);
        if (mc == NULL) {
@@ -1160,7 +1164,7 @@
        }
 
        /*
-        * Since ether_addmulti() returns ENETRESET, the following two
+        * Since ether_addmulti() returned ENETRESET, the following two
         * statements shouldn't fail. Here ifv_ec is implicitly protected
         * by the ifv_lock lock.
         */
@@ -1182,14 +1186,15 @@
 
        if (error != 0)
                goto ioctl_failed;
-       return (error);
+       return error;
 
- ioctl_failed:
+ioctl_failed:
        LIST_REMOVE(mc, mc_entries);
        free(mc, M_DEVBUF);
- alloc_failed:
+
+alloc_failed:
        (void)ether_delmulti(sa, &ifv->ifv_ec);
-       return (error);
+       return error;
 }
 
 static int
@@ -1206,15 +1211,15 @@
 
        /*
         * Find a key to lookup vlan_mc_entry.  We have to do this
-        * before calling ether_delmulti for obvious reason.
+        * before calling ether_delmulti for obvious reasons.
         */
        if ((error = ether_multiaddr(sa, addrlo, addrhi)) != 0)
-               return (error);
+               return error;
        ETHER_LOOKUP_MULTI(addrlo, addrhi, &ifv->ifv_ec, enm);
 



Home | Main Index | Thread Index | Old Index