PERFORCE change 49935 for review

Robert Watson rwatson at FreeBSD.org
Mon Mar 29 18:44:06 PST 2004


http://perforce.freebsd.org/chv.cgi?CH=49935

Change 49935 by rwatson at rwatson_paprika on 2004/03/29 18:43:30

	Integrate netperf_socket:
	
	Prefer NULL to 0 in pointer comparison and assignment.

Affected files ...

.. //depot/projects/netperf_socket/sys/kern/uipc_usrreq.c#5 integrate

Differences ...

==== //depot/projects/netperf_socket/sys/kern/uipc_usrreq.c#5 (text+ko) ====

@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/kern/uipc_usrreq.c,v 1.117 2004/03/01 03:14:21 rwatson Exp $");
+__FBSDID("$FreeBSD: src/sys/kern/uipc_usrreq.c,v 1.118 2004/03/30 02:16:25 rwatson Exp $");
 
 #include "opt_mac.h"
 
@@ -138,7 +138,7 @@
 {
 	struct unpcb *unp = sotounpcb(so);
 
-	if (unp == 0)
+	if (unp == NULL)
 		return (EINVAL);
 	UNP_ENTER(unp);
 	unp_drop(unp, ECONNABORTED);
@@ -154,7 +154,7 @@
 	struct unpcb *unp = sotounpcb(so);
 	struct sockaddr *sa;
 
-	if (unp == 0)
+	if (unp == NULL)
 		return (EINVAL);
 
 	/*
@@ -164,7 +164,7 @@
 	 */
 	*nam = malloc(sizeof(struct sockaddr_un), M_SONAME, M_WAITOK);
 	UNP_ENTER(unp);
-	if (unp->unp_conn && unp->unp_conn->unp_addr)
+	if (unp->unp_conn != NULL && unp->unp_conn->unp_addr != NULL)
 		sa = (struct sockaddr *) unp->unp_conn->unp_addr;
 	else
 		sa = &sun_noname;
@@ -178,7 +178,7 @@
 {
 	struct unpcb *unp = sotounpcb(so);
 
-	if (unp != 0)
+	if (unp != NULL)
 		return (EISCONN);
 	return (unp_attach(so));
 }
@@ -188,7 +188,7 @@
 {
 	struct unpcb *unp = sotounpcb(so);
 
-	if (unp == 0)
+	if (unp == NULL)
 		return (EINVAL);
 	return (unp_bind(unp, nam, td));
 }
@@ -199,7 +199,7 @@
 	struct unpcb *unp = sotounpcb(so);
 	int retval;
 
-	if (unp != 0) {
+	if (unp != NULL) {
 		UNP_ENTER(unp);
 		retval = unp_connect(so, nam, curthread);
 		UNP_EXIT(unp);
@@ -214,7 +214,7 @@
 	struct unpcb *unp = sotounpcb(so1);
 	int retval;
 
-	if (unp != 0) {
+	if (unp != NULL) {
 		UNP_ENTER(unp);
 		retval = unp_connect2(so1, so2);
 		UNP_EXIT(unp);
@@ -230,7 +230,7 @@
 {
 	struct unpcb *unp = sotounpcb(so);
 
-	if (unp == 0)
+	if (unp == NULL)
 		return (EINVAL);
 	UNP_ENTER(unp);
 	unp_detach(unp);	/* NB: unlocks unp + head */
@@ -242,7 +242,7 @@
 {
 	struct unpcb *unp = sotounpcb(so);
 
-	if (unp != 0) {
+	if (unp != NULL) {
 		UNP_ENTER(unp);
 		unp_disconnect(unp);
 		UNP_EXIT(unp);
@@ -257,7 +257,7 @@
 	struct unpcb *unp = sotounpcb(so);
 	int retval;
 
-	if (unp != 0 && unp->unp_vnode != 0) {
+	if (unp != NULL && unp->unp_vnode != NULL) {
 		UNP_ENTER(unp);
 		retval = unp_listen(unp, td);
 		UNP_EXIT(unp);
@@ -272,11 +272,11 @@
 	struct unpcb *unp = sotounpcb(so);
 	struct sockaddr *sa;
 
-	if (unp == 0)
+	if (unp == NULL)
 		return (EINVAL);
 	*nam = malloc(sizeof(struct sockaddr_un), M_SONAME, M_WAITOK);
 	UNP_ENTER(unp);
-	if (unp->unp_conn && unp->unp_conn->unp_addr)
+	if (unp->unp_conn != NULL && unp->unp_conn->unp_addr!= NULL)
 		sa = (struct sockaddr *) unp->unp_conn->unp_addr;
 	else {
 		/*
@@ -298,7 +298,7 @@
 	struct socket *so2;
 	u_long newhiwat;
 
-	if (unp == 0)
+	if (unp == NULL)
 		return (EINVAL);
 	/*
 	 * Reorder locks to avoid LORs.  Note that we
@@ -313,7 +313,7 @@
 		/*NOTREACHED*/
 
 	case SOCK_STREAM:
-		if (unp->unp_conn == 0) {
+		if (unp->unp_conn == NULL) {
 			SOCKBUF_LOCK(&so->so_rcv);
 			break;
 		}
@@ -354,7 +354,7 @@
 	struct socket *so2;
 	u_long newhiwat;
 
-	if (unp == 0) {
+	if (unp == NULL) {
 		error = EINVAL;
 		goto release;
 	}
@@ -363,7 +363,7 @@
 		goto release;
 	}
 
-	if (control && (error = unp_internalize(&control, td)))
+	if (control != NULL && (error = unp_internalize(&control, td)))
 		goto release;
 
 	/*
@@ -378,8 +378,8 @@
 	{
 		struct sockaddr *from;
 
-		if (nam) {
-			if (unp->unp_conn) {
+		if (nam != NULL) {
+			if (unp->unp_conn != NULL) {
 				error = EISCONN;
 				break;
 			}
@@ -389,25 +389,25 @@
 			if (error)
 				break;
 		} else {
-			if (unp->unp_conn == 0) {
+			if (unp->unp_conn == NULL) {
 				error = ENOTCONN;
 				break;
 			}
 		}
 		so2 = unp->unp_conn->unp_socket;
-		if (unp->unp_addr)
+		if (unp->unp_addr != NULL)
 			from = (struct sockaddr *)unp->unp_addr;
 		else
 			from = &sun_noname;
 		SOCKBUF_LOCK(&so2->so_rcv);
 		if (sbappendaddr_locked(&so2->so_rcv, from, m, control)) {
 			sorwakeup_locked(so2);
-			m = 0;
-			control = 0;
+			m = NULL;
+			control = NULL;
 		} else
 			error = ENOBUFS;
 		SOCKBUF_UNLOCK(&so2->so_rcv);
-		if (nam)
+		if (nam != NULL)
 			unp_disconnect(unp);
 		break;
 	}
@@ -419,7 +419,7 @@
 		 * if not equal to the peer's address.
 		 */
 		if ((so->so_state & SS_ISCONNECTED) == 0) {
-			if (nam) {
+			if (nam != NULL) {
 				SOCKBUF_UNLOCK(&so->so_snd);
 				error = unp_connect(so, nam, td);
 				SOCKBUF_LOCK(&so->so_snd);
@@ -435,7 +435,7 @@
 			error = EPIPE;
 			break;
 		}
-		if (unp->unp_conn == 0)
+		if (unp->unp_conn == NULL)
 			panic("uipc_send connected but no connection?");
 		so2 = unp->unp_conn->unp_socket;
 		SOCKBUF_LOCK(&so2->so_rcv);
@@ -444,9 +444,9 @@
 		 * send buffer hiwater marks to maintain backpressure.
 		 * Wake up readers.
 		 */
-		if (control) {
+		if (control != NULL) {
 			if (sbappendcontrol_locked(&so2->so_rcv, m, control))
-				control = 0;
+				control = NULL;
 		} else
 			sbappend_locked(&so2->so_rcv, m);
 		so->so_snd.sb_mbmax -=
@@ -459,7 +459,7 @@
 		unp->unp_conn->unp_cc = so2->so_rcv.sb_cc;
 		sorwakeup_locked(so2);
 		SOCKBUF_UNLOCK(&so2->so_rcv);
-		m = 0;
+		m = NULL;
 		break;
 
 	default:
@@ -476,12 +476,12 @@
 	}
 	UNP_EXIT(unp);
 
-	if (control && error != 0)
+	if (control != NULL && error != 0)
 		unp_dispose(control);		/* XXX need head lock? */
 release:
-	if (control)
+	if (control != NULL)
 		m_freem(control);
-	if (m)
+	if (m != NULL)
 		m_freem(m);
 	return (error);
 }
@@ -492,11 +492,11 @@
 	struct unpcb *unp = sotounpcb(so);
 	struct socket *so2;
 
-	if (unp == 0)
+	if (unp == NULL)
 		return (EINVAL);
 	UNP_ENTER(unp);
 	sb->st_blksize = so->so_snd.sb_hiwat;
-	if (so->so_type == SOCK_STREAM && unp->unp_conn != 0) {
+	if (so->so_type == SOCK_STREAM && unp->unp_conn != NULL) {
 		so2 = unp->unp_conn->unp_socket;
 		sb->st_blksize += so2->so_rcv.sb_cc;
 	}
@@ -513,7 +513,7 @@
 {
 	struct unpcb *unp = sotounpcb(so);
 
-	if (unp == 0)
+	if (unp == NULL)
 		return (EINVAL);
 	UNP_ENTER(unp);
 	/* XXX socket lock? */
@@ -529,11 +529,11 @@
 	struct unpcb *unp = sotounpcb(so);
 	struct sockaddr *sa;
 
-	if (unp == 0)
+	if (unp == NULL)
 		return (EINVAL);
 	*nam = malloc(sizeof(struct sockaddr_un), M_SONAME, M_WAITOK);
 	UNP_ENTER(unp);
-	if (unp->unp_addr)
+	if (unp->unp_addr != NULL)
 		sa = (struct sockaddr *) unp->unp_addr;
 	else
 		sa = &sun_noname;
@@ -672,11 +672,11 @@
 	LIST_REMOVE(unp, unp_link);
 	unp->unp_gencnt = ++unp_gencnt;
 	--unp_count;
-	if ((vp = unp->unp_vnode)) {
-		unp->unp_vnode->v_socket = 0;
-		unp->unp_vnode = 0;
+	if ((vp = unp->unp_vnode) != NULL) {
+		unp->unp_vnode->v_socket = NULL;
+		unp->unp_vnode = NULL;
 	}
-	if (unp->unp_conn)
+	if (unp->unp_conn != NULL)
 		unp_disconnect(unp);
 	while (!LIST_EMPTY(&unp->unp_refs)) {
 		struct unpcb *ref = LIST_FIRST(&unp->unp_refs);
@@ -685,7 +685,7 @@
 		UNP_UNLOCK(ref);
 	}
 	soisdisconnected(unp->unp_socket);
-	unp->unp_socket->so_pcb = 0;
+	unp->unp_socket->so_pcb = NULL;
 	if (unp_rights) {
 		/*
 		 * Normally the receive buffer is flushed later,
@@ -697,7 +697,7 @@
 		sorflush(unp->unp_socket);
 		unp_gc();
 	}
-	if (unp->unp_addr)
+	if (unp->unp_addr != NULL)
 		FREE(unp->unp_addr, M_SONAME);
 	UNP_LOCK_DESTROY(unp);
 	UNP_HEAD_UNLOCK();
@@ -830,7 +830,7 @@
 	if (error)
 		goto bad;
 	so2 = vp->v_socket;
-	if (so2 == 0) {
+	if (so2 == NULL) {
 		error = ECONNREFUSED;
 		goto bad;
 	}
@@ -850,15 +850,15 @@
 			so3 = sonewconn(so2, 0);
 			UNP_ENTER(unp);
 		} else
-			so3 = 0;
-		if (so3 == 0) {
+			so3 = NULL;
+		if (so3 == NULL) {
 			error = ECONNREFUSED;
 			goto bad;
 		}
 		unp = sotounpcb(so);
 		unp2 = sotounpcb(so2);
 		unp3 = sotounpcb(so3);
-		if (unp2->unp_addr) {
+		if (unp2->unp_addr != NULL) {
 			bcopy(unp2->unp_addr, sa, unp2->unp_addr->sun_len);
 			unp3->unp_addr = (struct sockaddr_un *) sa;
 			sa = NULL;
@@ -944,9 +944,9 @@
 
 	UNP_ASSERT(unp);
 
-	if (unp2 == 0)
+	if (unp2 == NULL)
 		return;
-	unp->unp_conn = 0;
+	unp->unp_conn = NULL;
 	switch (unp->unp_socket->so_type) {
 
 	case SOCK_DGRAM:
@@ -957,7 +957,7 @@
 	case SOCK_STREAM:
 		soisdisconnected(unp->unp_socket);
 		UNP_LOCK(unp2);
-		unp2->unp_conn = 0;
+		unp2->unp_conn = NULL;
 		soisdisconnected(unp2->unp_socket);
 		UNP_UNLOCK(unp2);
 		break;
@@ -991,14 +991,14 @@
 	 * The process of preparing the PCB list is too time-consuming and
 	 * resource-intensive to repeat twice on every request.
 	 */
-	if (req->oldptr == 0) {
+	if (req->oldptr == NULL) {
 		n = unp_count;
 		req->oldidx = 2 * (sizeof *xug)
 			+ (n + n/8) * sizeof(struct xunpcb);
 		return (0);
 	}
 
-	if (req->newptr != 0)
+	if (req->newptr != NULL)
 		return (EPERM);
 
 	/*
@@ -1046,10 +1046,11 @@
 			 * XXX - need more locking here to protect against
 			 * connect/disconnect races for SMP.
 			 */
-			if (unp->unp_addr)
+			if (unp->unp_addr != NULL)
 				bcopy(unp->unp_addr, &xu->xu_addr,
 				      unp->unp_addr->sun_len);
-			if (unp->unp_conn && unp->unp_conn->unp_addr)
+			if (unp->unp_conn != NULL &&
+			    unp->unp_conn->unp_addr != NULL)
 				bcopy(unp->unp_conn->unp_addr,
 				      &xu->xu_caddr,
 				      unp->unp_conn->unp_addr->sun_len);
@@ -1252,7 +1253,7 @@
 {
 	unp_zone = uma_zcreate("unpcb", sizeof(struct unpcb), NULL, NULL,
 	    NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
-	if (unp_zone == 0)
+	if (unp_zone == NULL)
 		panic("unp_init");
 	uma_zone_set_max(unp_zone, nmbclusters);
 	LIST_INIT(&unp_dhead);
@@ -1552,8 +1553,8 @@
 	 */
 	extra_ref = malloc(nfiles * sizeof(struct file *), M_TEMP, M_WAITOK);
 	sx_slock(&filelist_lock);
-	for (nunref = 0, fp = LIST_FIRST(&filehead), fpp = extra_ref; fp != 0;
-	    fp = nextfp) {
+	for (nunref = 0, fp = LIST_FIRST(&filehead), fpp = extra_ref;
+	    fp != NULL; fp = nextfp) {
 		nextfp = LIST_NEXT(fp, f_list);
 		FILE_LOCK(fp);
 		/*
@@ -1631,7 +1632,7 @@
 	socklen_t clen, datalen;
 	int qfds;
 
-	while (m0) {
+	while (m0 != NULL) {
 		for (m = m0; m; m = m->m_next) {
 			if (m->m_type != MT_CONTROL)
 				continue;


More information about the p4-projects mailing list