Module Name:    src
Committed By:   ozaki-r
Date:           Wed Nov 22 10:19:14 UTC 2017

Modified Files:
        src/sys/compat/common: uipc_syscalls_40.c
        src/sys/compat/linux/common: linux_socket.c
        src/sys/compat/linux32/common: linux32_socket.c
        src/sys/net: if.c

Log Message:
Fix and make consistent of usages of psz/psref in ifconf variants


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/compat/common/uipc_syscalls_40.c
cvs rdiff -u -r1.138 -r1.139 src/sys/compat/linux/common/linux_socket.c
cvs rdiff -u -r1.27 -r1.28 src/sys/compat/linux32/common/linux32_socket.c
cvs rdiff -u -r1.399 -r1.400 src/sys/net/if.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/compat/common/uipc_syscalls_40.c
diff -u src/sys/compat/common/uipc_syscalls_40.c:1.13 src/sys/compat/common/uipc_syscalls_40.c:1.14
--- src/sys/compat/common/uipc_syscalls_40.c:1.13	Tue Mar 14 09:03:08 2017
+++ src/sys/compat/common/uipc_syscalls_40.c	Wed Nov 22 10:19:14 2017
@@ -1,9 +1,9 @@
-/*	$NetBSD: uipc_syscalls_40.c,v 1.13 2017/03/14 09:03:08 ozaki-r Exp $	*/
+/*	$NetBSD: uipc_syscalls_40.c,v 1.14 2017/11/22 10:19:14 ozaki-r Exp $	*/
 
 /* written by Pavel Cahyna, 2006. Public domain. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.13 2017/03/14 09:03:08 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.14 2017/11/22 10:19:14 ozaki-r Exp $");
 
 /*
  * System call interface to the socket abstraction.
@@ -53,6 +53,7 @@ compat_ifconf(u_long cmd, void *data)
 		struct ifaddr *ifa;
 
 		if_acquire(ifp, &psref);
+		pserialize_read_exit(s);
 
 		(void)strncpy(ifr.ifr_name, ifp->if_xname,
 		    sizeof(ifr.ifr_name));
@@ -69,9 +70,10 @@ compat_ifconf(u_long cmd, void *data)
 				ifrp++;
 			}
 			space -= sizeof(ifr);
-			continue;
+			goto next;
 		}
 
+		s = pserialize_read_enter();
 		IFADDR_READER_FOREACH(ifa, ifp) {
 			struct sockaddr *sa = ifa->ifa_addr;
 			struct psref psref_ifa;
@@ -85,11 +87,8 @@ compat_ifconf(u_long cmd, void *data)
 				/*
 				 * If it does not fit, we don't bother with it
 				 */
-				if (sa->sa_len > sizeof(*osa)) {
-					s = pserialize_read_enter();
-					ifa_release(ifa, &psref_ifa);
-					continue;
-				}
+				if (sa->sa_len > sizeof(*osa))
+					goto next_ifa;
 				memcpy(&ifr.ifr_addr, sa, sa->sa_len);
 				osa->sa_family = sa->sa_family;
 				if (space >= sz) {
@@ -119,13 +118,20 @@ compat_ifconf(u_long cmd, void *data)
 						 (char *)&ifrp->ifr_addr);
 				}
 			}
-			s = pserialize_read_enter();
-			ifa_release(ifa, &psref_ifa);
-			if (error != 0)
+			if (error != 0) {
+				ifa_release(ifa, &psref_ifa);
 				goto release_exit;
+			}
 			space -= sz;
+
+		next_ifa:
+			s = pserialize_read_enter();
+			ifa_release(ifa, &psref_ifa);
 		}
+		pserialize_read_exit(s);
 
+	next:
+		s = pserialize_read_enter();
 		if_release(ifp, &psref);
 	}
 	pserialize_read_exit(s);
@@ -138,7 +144,6 @@ compat_ifconf(u_long cmd, void *data)
 	return (0);
 
 release_exit:
-	pserialize_read_exit(s);
 	if_release(ifp, &psref);
 	curlwp_bindx(bound);
 	return error;

Index: src/sys/compat/linux/common/linux_socket.c
diff -u src/sys/compat/linux/common/linux_socket.c:1.138 src/sys/compat/linux/common/linux_socket.c:1.139
--- src/sys/compat/linux/common/linux_socket.c:1.138	Tue Mar 14 09:03:08 2017
+++ src/sys/compat/linux/common/linux_socket.c	Wed Nov 22 10:19:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_socket.c,v 1.138 2017/03/14 09:03:08 ozaki-r Exp $	*/
+/*	$NetBSD: linux_socket.c,v 1.139 2017/11/22 10:19:14 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.138 2017/03/14 09:03:08 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.139 2017/11/22 10:19:14 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1144,6 +1144,7 @@ linux_getifconf(struct lwp *l, register_
 	IFNET_READER_FOREACH(ifp) {
 		struct ifaddr *ifa;
 		if_acquire(ifp, &psref);
+		pserialize_read_exit(s);
 
 		(void)strncpy(ifr.ifr_name, ifp->if_xname,
 		    sizeof(ifr.ifr_name));
@@ -1152,6 +1153,7 @@ linux_getifconf(struct lwp *l, register_
 			goto release_exit;
 		}
 
+		s = pserialize_read_enter();
 		IFADDR_READER_FOREACH(ifa, ifp) {
 			struct psref psref_ifa;
 			ifa_acquire(ifa, &psref_ifa);
@@ -1167,7 +1169,6 @@ linux_getifconf(struct lwp *l, register_
 			if (space >= sz) {
 				error = copyout(&ifr, ifrp, sz);
 				if (error != 0) {
-					s = pserialize_read_enter();
 					ifa_release(ifa, &psref_ifa);
 					goto release_exit;
 				}
@@ -1179,6 +1180,7 @@ linux_getifconf(struct lwp *l, register_
 			ifa_release(ifa, &psref_ifa);
 		}
 
+		s = pserialize_read_enter();
 		if_release(ifp, &psref);
 	}
 	pserialize_read_exit(s);
@@ -1192,7 +1194,6 @@ linux_getifconf(struct lwp *l, register_
 	return copyout(&ifc, data, sizeof(ifc));
 
 release_exit:
-	pserialize_read_exit(s);
 	if_release(ifp, &psref);
 	curlwp_bindx(bound);
 	return error;

Index: src/sys/compat/linux32/common/linux32_socket.c
diff -u src/sys/compat/linux32/common/linux32_socket.c:1.27 src/sys/compat/linux32/common/linux32_socket.c:1.28
--- src/sys/compat/linux32/common/linux32_socket.c:1.27	Tue Mar 14 09:03:08 2017
+++ src/sys/compat/linux32/common/linux32_socket.c	Wed Nov 22 10:19:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_socket.c,v 1.27 2017/03/14 09:03:08 ozaki-r Exp $ */
+/*	$NetBSD: linux32_socket.c,v 1.28 2017/11/22 10:19:14 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.27 2017/03/14 09:03:08 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.28 2017/11/22 10:19:14 ozaki-r Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -442,6 +442,7 @@ linux32_getifconf(struct lwp *l, registe
 	IFNET_READER_FOREACH(ifp) {
 		struct ifaddr *ifa;
 		if_acquire(ifp, &psref);
+		pserialize_read_exit(s);
 
 		(void)strncpy(ifr.ifr_name, ifp->if_xname,
 		    sizeof(ifr.ifr_name));
@@ -450,6 +451,7 @@ linux32_getifconf(struct lwp *l, registe
 			goto release_exit;
 		}
 
+		s = pserialize_read_enter();
 		IFADDR_READER_FOREACH(ifa, ifp) {
 			struct psref psref_ifa;
 			ifa_acquire(ifa, &psref_ifa);
@@ -465,7 +467,6 @@ linux32_getifconf(struct lwp *l, registe
 			if (space >= sz) {
 				error = copyout(&ifr, ifrp, sz);
 				if (error != 0) {
-					s = pserialize_read_enter();
 					ifa_release(ifa, &psref_ifa);
 					goto release_exit;
 				}
@@ -477,6 +478,7 @@ linux32_getifconf(struct lwp *l, registe
 			ifa_release(ifa, &psref_ifa);
 		}
 
+		s = pserialize_read_enter();
 		if_release(ifp, &psref);
 	}
 	pserialize_read_exit(s);
@@ -490,7 +492,6 @@ linux32_getifconf(struct lwp *l, registe
 	return copyout(&ifc, data, sizeof(ifc));
 
 release_exit:
-	pserialize_read_exit(s);
 	if_release(ifp, &psref);
 	curlwp_bindx(bound);
 	return error;

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.399 src/sys/net/if.c:1.400
--- src/sys/net/if.c:1.399	Wed Nov 22 03:03:18 2017
+++ src/sys/net/if.c	Wed Nov 22 10:19:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.399 2017/11/22 03:03:18 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.400 2017/11/22 10:19:14 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.399 2017/11/22 03:03:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.400 2017/11/22 10:19:14 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -3169,7 +3169,7 @@ ifconf(u_long cmd, void *data)
 			memset(&ifr.ifr_addr, 0, sizeof(ifr.ifr_addr));
 			if (!docopy) {
 				space += sz;
-				continue;
+				goto next;
 			}
 			if (space >= sz) {
 				error = copyout(&ifr, ifrp, sz);
@@ -3180,6 +3180,7 @@ ifconf(u_long cmd, void *data)
 			}
 		}
 
+		s = pserialize_read_enter();
 		IFADDR_READER_FOREACH(ifa, ifp) {
 			struct sockaddr *sa = ifa->ifa_addr;
 			/* all sockaddrs must fit in sockaddr_storage */
@@ -3190,14 +3191,19 @@ ifconf(u_long cmd, void *data)
 				continue;
 			}
 			memcpy(&ifr.ifr_space, sa, sa->sa_len);
+			pserialize_read_exit(s);
+
 			if (space >= sz) {
 				error = copyout(&ifr, ifrp, sz);
 				if (error != 0)
 					goto release_exit;
 				ifrp++; space -= sz;
 			}
+			s = pserialize_read_enter();
 		}
+		pserialize_read_exit(s);
 
+        next:
 		s = pserialize_read_enter();
 		psref_release(&psref, &ifp->if_psref, ifnet_psref_class);
 	}

Reply via email to