From bradley@dunn.org  Mon Nov 23 05:39:00 1998
Received: from dunn.org (london-7.slip.uiuc.edu [130.126.26.67])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id FAA15264
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 23 Nov 1998 05:38:56 -0800 (PST)
          (envelope-from bradley@dunn.org)
Received: (from root@localhost)
	by magnate.dunn.org (8.9.1/8.9.1) id HAA12196;
	Mon, 23 Nov 1998 07:36:13 -0600 (CST)
	(envelope-from bradley)
Message-Id: <199811231336.HAA12196@magnate.dunn.org>
Date: Mon, 23 Nov 1998 07:36:13 -0600 (CST)
From: bradley@dunn.org
Reply-To: bradley@dunn.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: "warning: suggest parentheses" fixes
X-Send-Pr-Version: 3.2

>Number:         8821
>Category:       kern
>Synopsis:       "warning: suggest parentheses" fixes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 23 05:40:00 PST 1998
>Closed-Date:    Mon Nov 30 10:01:38 PST 1998
>Last-Modified:  Mon Nov 30 10:03:05 PST 1998
>Originator:     Bradley Dunn
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
>Environment:
>Description:

	The attached patches fix all "warning: suggest parentheses"
	in src/sys/dev

>How-To-Repeat:
>Fix:

--- src/sys/dev/ccd/ccd.c.old	Mon Nov 23 06:41:47 1998
+++ src/sys/dev/ccd/ccd.c	Mon Nov 23 06:48:26 1998
@@ -316,8 +316,8 @@
 		 * Copy in the pathname of the component.
 		 */
 		bzero(tmppath, sizeof(tmppath));	/* sanity */
-		if (error = copyinstr(cpaths[ix], tmppath,
-		    MAXPATHLEN, &ci->ci_pathlen)) {
+		if ((error = copyinstr(cpaths[ix], tmppath,
+		    MAXPATHLEN, &ci->ci_pathlen))) {
 #ifdef DEBUG
 			if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
 				printf("ccd%d: can't copy path, error = %d\n",
@@ -336,7 +336,7 @@
 		/*
 		 * XXX: Cache the component's dev_t.
 		 */
-		if (error = VOP_GETATTR(vp, &va, p->p_ucred, p)) {
+		if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p))) {
 #ifdef DEBUG
 			if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
 				printf("ccd%d: %s: getattr failed %s = %d\n",
@@ -355,8 +355,8 @@
 		/*
 		 * Get partition information for the component.
 		 */
-		if (error = VOP_IOCTL(vp, DIOCGPART, (caddr_t)&dpart,
-		    FREAD, p->p_ucred, p)) {
+		if ((error = VOP_IOCTL(vp, DIOCGPART, (caddr_t)&dpart,
+		    FREAD, p->p_ucred, p))) {
 #ifdef DEBUG
 			if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
 				 printf("ccd%d: %s: ioctl failed, error = %d\n",
@@ -616,7 +616,7 @@
 		return (ENXIO);
 	cs = &ccd_softc[unit];
 
-	if (error = ccdlock(cs))
+	if ((error = ccdlock(cs)))
 		return (error);
 
 	lp = &cs->sc_dkdev.dk_label;
@@ -677,7 +677,7 @@
 		return (ENXIO);
 	cs = &ccd_softc[unit];
 
-	if (error = ccdlock(cs))
+	if ((error = ccdlock(cs)))
 		return (error);
 
 	part = ccdpart(dev);
@@ -1060,7 +1060,7 @@
 		if ((flag & FWRITE) == 0)
 			return (EBADF);
 
-		if (error = ccdlock(cs))
+		if ((error = ccdlock(cs)))
 			return (error);
 
 		/* Fill in some important bits. */
@@ -1115,7 +1115,7 @@
 			if (ccddebug & CCDB_INIT)
 				printf("ccdioctl: lookedup = %d\n", lookedup);
 #endif
-			if (error = ccdlookup(cpp[i], p, &vpp[i])) {
+			if ((error = ccdlookup(cpp[i], p, &vpp[i]))) {
 				for (j = 0; j < lookedup; ++j)
 					(void)vn_close(vpp[j], FREAD|FWRITE,
 					    p->p_ucred, p);
@@ -1133,7 +1133,7 @@
 		/*
 		 * Initialize the ccd.  Fills in the softc for us.
 		 */
-		if (error = ccdinit(&ccd, cpp, p)) {
+		if ((error = ccdinit(&ccd, cpp, p))) {
 			for (j = 0; j < lookedup; ++j)
 				(void)vn_close(vpp[j], FREAD|FWRITE,
 				    p->p_ucred, p);
@@ -1164,7 +1164,7 @@
 		if ((flag & FWRITE) == 0)
 			return (EBADF);
 
-		if (error = ccdlock(cs))
+		if ((error = ccdlock(cs)))
 			return (error);
 
 		/*
@@ -1251,7 +1251,7 @@
 		if ((flag & FWRITE) == 0)
 			return (EBADF);
 
-		if (error = ccdlock(cs))
+		if ((error = ccdlock(cs)))
 			return (error);
 
 		cs->sc_flags |= CCDF_LABELLING;
@@ -1347,7 +1347,7 @@
 	int error;
 
 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, path, p);
-	if (error = vn_open(&nd, FREAD|FWRITE, 0)) {
+	if ((error = vn_open(&nd, FREAD|FWRITE, 0))) {
 #ifdef DEBUG
 		if (ccddebug & CCDB_FOLLOW|CCDB_INIT)
 			printf("ccdlookup: vn_open error = %d\n", error);
@@ -1362,7 +1362,7 @@
 		return (EBUSY);
 	}
 
-	if (error = VOP_GETATTR(vp, &va, p->p_ucred, p)) {
+	if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p))) {
 #ifdef DEBUG
 		if (ccddebug & CCDB_FOLLOW|CCDB_INIT)
 			printf("ccdlookup: getattr error = %d\n", error);
@@ -1434,8 +1434,8 @@
 	/*
 	 * Call the generic disklabel extraction routine.
 	 */
-	if (errstring = readdisklabel(CCDLABELDEV(dev), ccdstrategy,
-	    &cs->sc_dkdev.dk_label))
+	if ((errstring = readdisklabel(CCDLABELDEV(dev), ccdstrategy,
+	    &cs->sc_dkdev.dk_label)))
 		ccdmakedisklabel(cs);
 
 #ifdef DEBUG
--- src/sys/dev/en/midway.c.old	Mon Nov 23 06:48:53 1998
+++ src/sys/dev/en/midway.c	Mon Nov 23 06:49:55 1998
@@ -1274,7 +1274,7 @@
 		do {
 			struct ifnet *shadow;
 		    
-			if (error = suser(curproc->p_ucred, &curproc->p_acflag))
+			if ((error = suser(curproc->p_ucred, &curproc->p_acflag)))
 				break;
 		    
 			if ((shadow = pvc_attach(ifp)) != NULL) {
--- src/sys/dev/hea/eni_if.c.old	Mon Nov 23 06:50:30 1998
+++ src/sys/dev/hea/eni_if.c	Mon Nov 23 06:53:21 1998
@@ -215,7 +215,7 @@
 		/*
 		 * Copy interface name into response structure
 		 */
-		if ( err = copyout ( ifname, avr->avsp_intf, IFNAMSIZ ) )
+		if ( (err = copyout ( ifname, avr->avsp_intf, IFNAMSIZ )) )
 			break;
 
 		/*
@@ -238,8 +238,8 @@
 		 * Copy stats into user's buffer. Return value is
 		 * amount of data copied.
 		 */
-		if ( err = copyout ((void *)&eup->eu_stats, buf,
-			count))
+		if ( (err = copyout ((void *)&eup->eu_stats, buf,
+			count)))
 				break;
 		buf += count;
 		buf_len -= count;
@@ -249,7 +249,7 @@
 		/*
 		 * Record amount we're returning as vendor info...
 		 */
-		if (err = copyout(&count, &avr->avsp_len, sizeof(int)))
+		if ((err = copyout(&count, &avr->avsp_len, sizeof(int))))
 			break;
 
 		/*
--- src/sys/dev/hea/eni_receive.c.old	Mon Nov 23 06:53:51 1998
+++ src/sys/dev/hea/eni_receive.c	Mon Nov 23 07:20:39 1998
@@ -114,8 +114,8 @@
 		 * VCC into TRASH mode.
 		 */
 		if ( ( vci_hdr & VCI_IN_SERVICE ) == 0 ||
-		    ( vci_hdr & ~VCI_MODE_MASK ==
-			VCI_MODE_TRASH << VCI_MODE_SHIFT ) )
+		    ( vci_hdr & (~VCI_MODE_MASK ==
+			VCI_MODE_TRASH << VCI_MODE_SHIFT) ) )
 			    goto next_vcc;
 
 		/*
--- src/sys/dev/hea/eni_transmit.c.old	Mon Nov 23 06:56:03 1998
+++ src/sys/dev/hea/eni_transmit.c	Mon Nov 23 06:57:45 1998
@@ -463,7 +463,7 @@
 		 * Get start of data onto full-word alignment
 		 */
 		KB_DATASTART ( m, cp, caddr_t );
-		if ( align = ((u_int)cp) & (sizeof(u_long)-1)) {
+		if ( (align = ((u_int)cp) & (sizeof(u_long)-1))) {
 			/*
 			 * Gotta slide the data up
 			 */
@@ -622,7 +622,7 @@
 	 * AAL5 PDUs need an extra two words for control/length and
 	 * CRC. Check for AAL5 and add requirements here.
 	 */
-	if (aal5 = (evp->ev_connvc->cvc_attr.aal.type == ATM_AAL5))
+	if ((aal5 = (evp->ev_connvc->cvc_attr.aal.type == ATM_AAL5)))
 		size = pdulen + 2 * sizeof(long);
 	else
 		size = pdulen;
--- src/sys/dev/hfa/fore_buffer.c.old	Mon Nov 23 06:58:20 1998
+++ src/sys/dev/hfa/fore_buffer.c	Mon Nov 23 06:59:19 1998
@@ -690,7 +690,7 @@
 		/*
 		 * Run through Strategy 1 Small queue
 		 */
-		while (bhp = Q_HEAD(fup->fu_buf1s_bq, Buf_handle)) {
+		while ((bhp = Q_HEAD(fup->fu_buf1s_bq, Buf_handle))) {
 			caddr_t		cp;
 
 			/*
@@ -712,7 +712,7 @@
 		/*
 		 * Run through Strategy 1 Large queue
 		 */
-		while (bhp = Q_HEAD(fup->fu_buf1l_bq, Buf_handle)) {
+		while ((bhp = Q_HEAD(fup->fu_buf1l_bq, Buf_handle))) {
 			caddr_t		cp;
 
 			/*
--- src/sys/dev/hfa/fore_if.c.old	Mon Nov 23 06:59:58 1998
+++ src/sys/dev/hfa/fore_if.c	Mon Nov 23 07:01:19 1998
@@ -106,7 +106,7 @@
 		/*
 		 * Copy interface name into response structure
 		 */
-		if ( err = copyout ( ifname, avr->avsp_intf, IFNAMSIZ ) )
+		if ( (err = copyout ( ifname, avr->avsp_intf, IFNAMSIZ )) )
 			break;
 
 		/*
@@ -131,7 +131,7 @@
 			 * Copy stats into user's buffer. Return value is
 			 * amount of data copied.
 			 */
-			if (err = copyout((caddr_t)fup->fu_stats, buf, count))
+			if ((err = copyout((caddr_t)fup->fu_stats, buf, count)))
 				break;
 			buf += count;
 			buf_len -= count;
@@ -142,7 +142,7 @@
 		/*
 		 * Record amount we're returning as vendor info...
 		 */
-		if (err = copyout(&count, &avr->avsp_len, sizeof(int)))
+		if ((err = copyout(&count, &avr->avsp_len, sizeof(int))))
 			break;
 
 		/*
--- src/sys/dev/hfa/fore_output.c.old	Mon Nov 23 07:01:43 1998
+++ src/sys/dev/hfa/fore_output.c	Mon Nov 23 07:02:15 1998
@@ -301,7 +301,7 @@
 		 * Get start of data onto full-word alignment
 		 */
 		KB_DATASTART(m, cp, caddr_t);
-		if (align = ((u_int)cp) & (XMIT_SEG_ALIGN - 1)) {
+		if ((align = ((u_int)cp) & (XMIT_SEG_ALIGN - 1))) {
 			/*
 			 * Gotta slide the data up
 			 */
--- src/sys/dev/pdq/pdq.c.old	Mon Nov 23 07:02:38 1998
+++ src/sys/dev/pdq/pdq.c	Mon Nov 23 07:05:54 1998
@@ -764,7 +764,7 @@
 		       dataptr[PDQ_RX_FC_OFFSET+5],
 		       dataptr[PDQ_RX_FC_OFFSET+6]);
 		/* rx->rx_badcrc++; */
-	    } else if (status.rxs_fsc == 0 | status.rxs_fsb_e == 1) {
+	    } else if ((status.rxs_fsc == 0) | (status.rxs_fsb_e == 1)) {
 		/* rx->rx_frame_status_errors++; */
 	    } else {
 		/* hardware fault */
--- src/sys/dev/ppbus/ppb_base.c.old	Mon Nov 23 07:06:42 1998
+++ src/sys/dev/ppbus/ppb_base.c	Mon Nov 23 07:07:29 1998
@@ -87,7 +87,7 @@
 		case PPB_INTR:
 		default:
 			/* wait 10 ms */
-			if ((error = tsleep((caddr_t)dev, PPBPRI | PCATCH,
+			if ((error = tsleep((caddr_t)dev, (PPBPRI | PCATCH),
 						"ppbpoll", hz/100)))
 				return (error);
 			break;
--- src/sys/dev/ppbus/ppbconf.c.old	Mon Nov 23 07:08:15 1998
+++ src/sys/dev/ppbus/ppbconf.c	Mon Nov 23 07:08:53 1998
@@ -390,7 +390,7 @@
 
 			switch (how) {
 			case (PPB_WAIT | PPB_INTR):
-				error = tsleep(ppb, PPBPRI|PCATCH, "ppbreq", 0);
+				error = tsleep(ppb, (PPBPRI|PCATCH), "ppbreq", 0);
 				break;
 
 			case (PPB_WAIT | PPB_NOINTR):
--- src/sys/dev/smbus/smbconf.c.old	Mon Nov 23 07:09:35 1998
+++ src/sys/dev/smbus/smbconf.c	Mon Nov 23 07:10:03 1998
@@ -78,7 +78,7 @@
 
 	switch (how) {
 	case (SMB_WAIT | SMB_INTR):
-		error = tsleep(sc, SMBPRI|PCATCH, "smbreq", 0);
+		error = tsleep(sc, (SMBPRI|PCATCH), "smbreq", 0);
 		break;
 
 	case (SMB_WAIT | SMB_NOINTR):
--- src/sys/dev/iicbus/iiconf.c.old	Mon Nov 23 07:10:51 1998
+++ src/sys/dev/iicbus/iiconf.c	Mon Nov 23 07:11:07 1998
@@ -78,7 +78,7 @@
 
 	switch (how) {
 	case (IIC_WAIT | IIC_INTR):
-		error = tsleep(sc, IICPRI|PCATCH, "iicreq", 0);
+		error = tsleep(sc, (IICPRI|PCATCH), "iicreq", 0);
 		break;
 
 	case (IIC_WAIT | IIC_NOINTR):
>Release-Note:
>Audit-Trail:

From: Robert Nordier <rnordier@nordier.com>
To: bradley@dunn.org
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/8821: "warning: suggest parentheses" fixes
Date: Mon, 23 Nov 1998 19:49:24 +0200 (SAT)

 bradley@dunn.org wrote:
  
 > >Number:         8821
 > >Category:       kern
 > >Synopsis:       "warning: suggest parentheses" fixes
  
 >       The attached patches fix all "warning: suggest parentheses"
 >       in src/sys/dev
 
 Of the various warnings issued by gcc, these are probably the most
 questionable because (being purely stylistic suggestions) they may be
 issued against code which is technically correct in every respect.
 
 As applied to FreeBSD, the stylistic issue is not really whether the
 gcc-suggested style is superior to the present one (it is certainly
 arguable that it is).  Rather, it is a matter of consistency with
 existing practice.
 
 The man page style(9) is an attempt to describe the preferred form
 for FreeBSD kernel source files.  An extract says:
 
 |    No spaces after function names.  Commas have a space after them.
 |    No spaces after `(' or `[' or preceding `]' or `)' characters.
 |
 |            if (error = function(a1, a2))
 |                    exit(error);
 |
 |    Unary operators don't require spaces, binary operators do.
 |    Don't use parentheses unless they're required for precedence,
 |    or the statement is really confusing without them.
 
 The majority of the supplied fixes are, in fact, applied to
 statements very similar to the quoted style(9) example; and are
 therefore clearly not in accordance with the guidelines.
 
 In other cases, an extra level of parentheses is added to '&' and
 '|' operands.  For example, one of the more complex cases has the
 logical form
 
     p & ~q == r << s
 
 which is changed to
 
     p & (~q == r << s)
 
 It is doubtful that such as statement, in either form, qualifies
 as "really confusing"; and this essentially disposes of the
 other suggested changes.
 
 Unfortunately, in a few cases, you have missed instances where
 the warning may have prompted a worthwhile fix.
 
 One example:
 
 > --- src/sys/dev/ppbus/ppb_base.c.old  Mon Nov 23 07:06:42 1998
 > +++ src/sys/dev/ppbus/ppb_base.c      Mon Nov 23 07:07:29 1998
 > @@ -87,7 +87,7 @@
 >               case PPB_INTR:
 >               default:
 >                       /* wait 10 ms */
 > -                     if ((error = tsleep((caddr_t)dev, PPBPRI | PCATCH,
 > +                     if ((error = tsleep((caddr_t)dev, (PPBPRI | PCATCH),
 >                                               "ppbpoll", hz/100)))
 >                               return (error);
 >                       break;
 
 The real "problem" here is in src/sys/dev/ppbus/ppbconf.h, where
 
     #define PPBPRI  PZERO+8
 
 should probably be changed to
 
     #define PPBPRI  (PZERO + 8)
 
 since #defines in header files are almost always better off
 fully-parenthesized.
 
 But just sliding an extra layer of parentheses around the '|' (as in
 the patch) achieves nothing, and should not even inhibit the compiler
 from continuing to make its original "suggestion".
 
 Apologies if this seems unduly negative.  You just happen to have
 chosen a category of warnings where it is almost certainly better to
 ignore the compiler, rather than make substantial non-functional
 source changes to quiet it.
 
 -- 
 Robert Nordier
State-Changed-From-To: open->closed 
State-Changed-By: rnordier 
State-Changed-When: Mon Nov 30 10:01:38 PST 1998 
State-Changed-Why:  
Fixes break style(9) guidelines. 
>Unformatted:
