Module Name:    src
Committed By:   msaitoh
Date:           Fri Aug 23 02:33:16 UTC 2019

Modified Files:
        src/sys/net: if_vlan.c

Log Message:
- 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.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/sys/net/if_vlan.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/net/if_vlan.c
diff -u src/sys/net/if_vlan.c:1.145 src/sys/net/if_vlan.c:1.146
--- src/sys/net/if_vlan.c:1.145	Wed Aug 21 06:00:07 2019
+++ src/sys/net/if_vlan.c	Fri Aug 23 02:33:15 2019
@@ -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 @@ vlan_config(struct ifvlan *ifv, struct i
 		}
 		/* 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 @@ vlan_config(struct ifvlan *ifv, struct i
 			 * 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 @@ vlan_unconfig_locked(struct ifvlan *ifv,
 	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 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd
 			error = ENOENT;
 			break;
 		}
-		
+
 		error = vlan_config(ifv, pr, vlr.vlr_tag);
 		if (error != 0)
 			break;

Reply via email to