Source-Changes-HG archive

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

[src/trunk]: src/sys/net - kmem_alloc(, KM_SLEEP) never return NULL, so remove...



details:   https://anonhg.NetBSD.org/src/rev/9076840c3062
branches:  trunk
changeset: 459070:9076840c3062
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Fri Aug 23 02:33:15 2019 +0000

description:
- kmem_alloc(,KM_SLEEP) never return NULL, so remove NULL check.
- VLAN ID is never duplicated, so break the loop when found. Also move
  kmen_free() outside of ETHER_LOCK(ec)/ETHER_UNLOCK(ec) to reduce the hold
  time. suggested by ozaki-r.
- Whitespace fix.

diffstat:

 sys/net/if_vlan.c |  20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)

diffs (71 lines):

diff -r 4716fc7234f7 -r 9076840c3062 sys/net/if_vlan.c
--- a/sys/net/if_vlan.c Thu Aug 22 22:51:47 2019 +0000
+++ b/sys/net/if_vlan.c Fri Aug 23 02:33:15 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_vlan.c,v 1.145 2019/08/21 06:00:07 msaitoh Exp $    */
+/*     $NetBSD: if_vlan.c,v 1.146 2019/08/23 02:33:15 msaitoh Exp $    */
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.145 2019/08/21 06:00:07 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.146 2019/08/23 02:33:15 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -487,10 +487,6 @@
                }
                /* Add a vid to the list */
                vidmem = kmem_alloc(sizeof(struct vlanid_list), KM_SLEEP);
-               if (vidmem == NULL) {
-                       error = ENOMEM;
-                       goto viderr;
-               }
                vidmem->vid = vid;
                ETHER_LOCK(ec);
                SIMPLEQ_INSERT_TAIL(&ec->ec_vids, vidmem, vid_list);
@@ -502,7 +498,6 @@
                         * HW tagging function.
                         */
                        error = (*ec->ec_vlan_cb)(ec, vid, true);
-viderr:
                        if (error) {
                                ec->ec_nvlans--;
                                if (ec->ec_nvlans == 0) {
@@ -638,18 +633,21 @@
        case IFT_ETHER:
            {
                struct ethercom *ec = (void *)p;
-               struct vlanid_list *vlanidp, *tmpp;
+               struct vlanid_list *vlanidp;
                uint16_t vid = EVL_VLANOFTAG(nmib->ifvm_tag);
 
                ETHER_LOCK(ec);
-               SIMPLEQ_FOREACH_SAFE(vlanidp, &ec->ec_vids, vid_list, tmpp) {
+               SIMPLEQ_FOREACH(vlanidp, &ec->ec_vids, vid_list) {
                        if (vlanidp->vid == vid) {
                                SIMPLEQ_REMOVE(&ec->ec_vids, vlanidp,
                                    vlanid_list, vid_list);
-                               kmem_free(vlanidp, sizeof(*vlanidp));
+                               break;
                        }
                }
                ETHER_UNLOCK(ec);
+               if (vlanidp != NULL)
+                       kmem_free(vlanidp, sizeof(*vlanidp));
+
                if (ec->ec_vlan_cb != NULL) {
                        /*
                         * Call ec_vlan_cb(). It will setup VLAN HW filter or
@@ -1038,7 +1036,7 @@
                        error = ENOENT;
                        break;
                }
-               
+
                error = vlan_config(ifv, pr, vlr.vlr_tag);
                if (error != 0)
                        break;



Home | Main Index | Thread Index | Old Index