From nobody@FreeBSD.org  Wed Apr 10 17:53:43 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id 16259339
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Apr 2013 17:53:43 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id E9D6EE5E
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Apr 2013 17:53:42 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r3AHrdvm087811
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Apr 2013 17:53:39 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r3AHrdAg087810;
	Wed, 10 Apr 2013 17:53:39 GMT
	(envelope-from nobody)
Message-Id: <201304101753.r3AHrdAg087810@red.freebsd.org>
Date: Wed, 10 Apr 2013 17:53:39 GMT
From: Luiz Otavio O Souza <loos.br@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [gpio] wrong check for unwanted flags
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         177759
>Category:       kern
>Synopsis:       [gpio] [patch] wrong check for unwanted flags
>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:   Wed Apr 10 18:00:00 UTC 2013
>Closed-Date:    Tue Apr 16 17:50:56 UTC 2013
>Last-Modified:  Tue Apr 16 18:00:00 UTC 2013
>Originator:     Luiz Otavio O Souza
>Release:        HEAD r247891
>Organization:
>Environment:
FreeBSD devel 10.0-CURRENT FreeBSD 10.0-CURRENT #7 r247891M: Wed Mar  6 10:16:45 BRT 2013     root@devel:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
clang warns about this badly written code (which got copied all over the tree):

11:47 <@dim> sys/arm/allwinner/a10_gpio.c:304:13: error: unsequenced modification and access to 'flags' [-Werror,-Wunsequenced]
11:47 <@dim>         if ((flags &= sc->sc_gpio_pins[i].gp_caps) != flags)
11:47 <@dim>                    ^                                  ~~~~~


>How-To-Repeat:

>Fix:
Apply the attached patch. It changes the check to not modify the flags variable (which isn't really needed since the function will return if flags has any invalid bit set).

Patch attached with submission follows:

Index: arm/allwinner/a10_gpio.c
===================================================================
--- arm/allwinner/a10_gpio.c	(revision 248943)
+++ arm/allwinner/a10_gpio.c	(working copy)
@@ -300,8 +300,8 @@
 	if (i >= sc->sc_gpio_npins)
 		return (EINVAL);
 
-	/* Filter out unwanted flags. */
-	if ((flags &= sc->sc_gpio_pins[i].gp_caps) != flags)
+	/* Check out for unwanted flags. */
+	if ((flags & sc->sc_gpio_pins[i].gp_caps) != flags)
 		return (EINVAL);
 
 	/* Can't mix input/output together. */
Index: arm/broadcom/bcm2835/bcm2835_gpio.c
===================================================================
--- arm/broadcom/bcm2835/bcm2835_gpio.c	(revision 248943)
+++ arm/broadcom/bcm2835/bcm2835_gpio.c	(working copy)
@@ -385,8 +385,8 @@
 	if (bcm_gpio_pin_is_ro(sc, pin))
 		return (EINVAL);
 
-	/* Filter out unwanted flags. */
-	if ((flags &= sc->sc_gpio_pins[i].gp_caps) != flags)
+	/* Check out for unwanted flags. */
+	if ((flags & sc->sc_gpio_pins[i].gp_caps) != flags)
 		return (EINVAL);
 
 	/* Can't mix input/output together. */
Index: arm/freescale/imx/imx51_gpio.c
===================================================================
--- arm/freescale/imx/imx51_gpio.c	(revision 248943)
+++ arm/freescale/imx/imx51_gpio.c	(working copy)
@@ -261,8 +261,8 @@
 	if (i >= sc->gpio_npins)
 		return (EINVAL);
 
-	/* Filter out unwanted flags */
-	if ((flags &= sc->gpio_pins[i].gp_caps) != flags)
+	/* Check out for unwanted flags. */
+	if ((flags & sc->gpio_pins[i].gp_caps) != flags)
 		return (EINVAL);
 
 	/* Can't mix input/output together */
Index: arm/xscale/ixp425/avila_gpio.c
===================================================================
--- arm/xscale/ixp425/avila_gpio.c	(revision 248943)
+++ arm/xscale/ixp425/avila_gpio.c	(working copy)
@@ -220,8 +220,8 @@
 	if (pin >= IXP4XX_GPIO_PINS || !(sc->sc_valid & mask))
 		return (EINVAL);
 
-	/* Filter out unwanted flags */
-	if ((flags &= sc->sc_pins[pin].gp_caps) != flags)
+	/* Check out for unwanted flags. */
+	if ((flags & sc->sc_pins[pin].gp_caps) != flags)
 		return (EINVAL);
 
 	/* Can't mix input/output together */
Index: arm/xscale/ixp425/cambria_gpio.c
===================================================================
--- arm/xscale/ixp425/cambria_gpio.c	(revision 248943)
+++ arm/xscale/ixp425/cambria_gpio.c	(working copy)
@@ -317,8 +317,8 @@
 	if (pin >= GPIO_PINS)
 		return (EINVAL);
 
-	/* Filter out unwanted flags */
-	if ((flags &= sc->sc_pins[pin].gp_caps) != flags)
+	/* Check out for unwanted flags. */
+	if ((flags & sc->sc_pins[pin].gp_caps) != flags)
 		return (EINVAL);
 
 	/* Can't mix input/output together */
Index: mips/atheros/ar71xx_gpio.c
===================================================================
--- mips/atheros/ar71xx_gpio.c	(revision 248950)
+++ mips/atheros/ar71xx_gpio.c	(working copy)
@@ -219,8 +219,8 @@
 	if (i >= sc->gpio_npins)
 		return (EINVAL);
 
-	/* Filter out unwanted flags */
-	if ((flags &= sc->gpio_pins[i].gp_caps) != flags)
+	/* Check out for unwanted flags. */
+	if ((flags & sc->gpio_pins[i].gp_caps) != flags)
 		return (EINVAL);
 
 	/* Can't mix input/output together */
Index: mips/cavium/octeon_gpio.c
===================================================================
--- mips/cavium/octeon_gpio.c	(revision 248943)
+++ mips/cavium/octeon_gpio.c	(working copy)
@@ -219,8 +219,8 @@
 	if (i >= sc->gpio_npins)
 		return (EINVAL);
 
-	/* Filter out unwanted flags */
-	if ((flags &= sc->gpio_pins[i].gp_caps) != flags)
+	/* Check out for unwanted flags. */
+	if ((flags & sc->gpio_pins[i].gp_caps) != flags)
 		return (EINVAL);
 
 	/* Can't mix input/output together */
Index: mips/rt305x/rt305x_gpio.c
===================================================================
--- mips/rt305x/rt305x_gpio.c	(revision 248943)
+++ mips/rt305x/rt305x_gpio.c	(working copy)
@@ -242,8 +242,8 @@
 	if (i >= sc->gpio_npins)
 		return (EINVAL);
 
-	/* Filter out unwanted flags */
-	if ((flags &= sc->gpio_pins[i].gp_caps) != flags)
+	/* Check out for unwanted flags. */
+	if ((flags & sc->gpio_pins[i].gp_caps) != flags)
 		return (EINVAL);
 
 	/* Can't mix input/output together */


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: dim 
State-Changed-When: Sat Apr 13 21:23:51 UTC 2013 
State-Changed-Why:  
Patch committed to head, with slighty changed comments. 
It will be MFCd after 3 days. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=177759 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/177759: commit references a PR
Date: Sat, 13 Apr 2013 21:21:27 +0000 (UTC)

 Author: dim
 Date: Sat Apr 13 21:21:13 2013
 New Revision: 249449
 URL: http://svnweb.freebsd.org/changeset/base/249449
 
 Log:
   Fix undefined behaviour in several gpio_pin_setflags() routines (under
   sys/arm and sys/mips), squelching the clang 3.3 warnings about this.
   
   Noticed by:	tinderbox and many irate spectators
   Submitted by:	Luiz Otavio O Souza <loos.br@gmail.com>
   PR:		kern/177759
   MFC after:	3 days
 
 Modified:
   head/sys/arm/allwinner/a10_gpio.c
   head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c
   head/sys/arm/freescale/imx/imx51_gpio.c
   head/sys/arm/xscale/ixp425/avila_gpio.c
   head/sys/arm/xscale/ixp425/cambria_gpio.c
   head/sys/mips/atheros/ar71xx_gpio.c
   head/sys/mips/cavium/octeon_gpio.c
   head/sys/mips/rt305x/rt305x_gpio.c
 
 Modified: head/sys/arm/allwinner/a10_gpio.c
 ==============================================================================
 --- head/sys/arm/allwinner/a10_gpio.c	Sat Apr 13 21:17:43 2013	(r249448)
 +++ head/sys/arm/allwinner/a10_gpio.c	Sat Apr 13 21:21:13 2013	(r249449)
 @@ -300,8 +300,8 @@ a10_gpio_pin_setflags(device_t dev, uint
  	if (i >= sc->sc_gpio_npins)
  		return (EINVAL);
  
 -	/* Filter out unwanted flags. */
 -	if ((flags &= sc->sc_gpio_pins[i].gp_caps) != flags)
 +	/* Check for unwanted flags. */
 +	if ((flags & sc->sc_gpio_pins[i].gp_caps) != flags)
  		return (EINVAL);
  
  	/* Can't mix input/output together. */
 
 Modified: head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c
 ==============================================================================
 --- head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c	Sat Apr 13 21:17:43 2013	(r249448)
 +++ head/sys/arm/broadcom/bcm2835/bcm2835_gpio.c	Sat Apr 13 21:21:13 2013	(r249449)
 @@ -385,8 +385,8 @@ bcm_gpio_pin_setflags(device_t dev, uint
  	if (bcm_gpio_pin_is_ro(sc, pin))
  		return (EINVAL);
  
 -	/* Filter out unwanted flags. */
 -	if ((flags &= sc->sc_gpio_pins[i].gp_caps) != flags)
 +	/* Check for unwanted flags. */
 +	if ((flags & sc->sc_gpio_pins[i].gp_caps) != flags)
  		return (EINVAL);
  
  	/* Can't mix input/output together. */
 
 Modified: head/sys/arm/freescale/imx/imx51_gpio.c
 ==============================================================================
 --- head/sys/arm/freescale/imx/imx51_gpio.c	Sat Apr 13 21:17:43 2013	(r249448)
 +++ head/sys/arm/freescale/imx/imx51_gpio.c	Sat Apr 13 21:21:13 2013	(r249449)
 @@ -261,8 +261,8 @@ imx51_gpio_pin_setflags(device_t dev, ui
  	if (i >= sc->gpio_npins)
  		return (EINVAL);
  
 -	/* Filter out unwanted flags */
 -	if ((flags &= sc->gpio_pins[i].gp_caps) != flags)
 +	/* Check for unwanted flags. */
 +	if ((flags & sc->gpio_pins[i].gp_caps) != flags)
  		return (EINVAL);
  
  	/* Can't mix input/output together */
 
 Modified: head/sys/arm/xscale/ixp425/avila_gpio.c
 ==============================================================================
 --- head/sys/arm/xscale/ixp425/avila_gpio.c	Sat Apr 13 21:17:43 2013	(r249448)
 +++ head/sys/arm/xscale/ixp425/avila_gpio.c	Sat Apr 13 21:21:13 2013	(r249449)
 @@ -220,8 +220,8 @@ avila_gpio_pin_setflags(device_t dev, ui
  	if (pin >= IXP4XX_GPIO_PINS || !(sc->sc_valid & mask))
  		return (EINVAL);
  
 -	/* Filter out unwanted flags */
 -	if ((flags &= sc->sc_pins[pin].gp_caps) != flags)
 +	/* Check for unwanted flags. */
 +	if ((flags & sc->sc_pins[pin].gp_caps) != flags)
  		return (EINVAL);
  
  	/* Can't mix input/output together */
 
 Modified: head/sys/arm/xscale/ixp425/cambria_gpio.c
 ==============================================================================
 --- head/sys/arm/xscale/ixp425/cambria_gpio.c	Sat Apr 13 21:17:43 2013	(r249448)
 +++ head/sys/arm/xscale/ixp425/cambria_gpio.c	Sat Apr 13 21:21:13 2013	(r249449)
 @@ -317,8 +317,8 @@ cambria_gpio_pin_setflags(device_t dev, 
  	if (pin >= GPIO_PINS)
  		return (EINVAL);
  
 -	/* Filter out unwanted flags */
 -	if ((flags &= sc->sc_pins[pin].gp_caps) != flags)
 +	/* Check for unwanted flags. */
 +	if ((flags & sc->sc_pins[pin].gp_caps) != flags)
  		return (EINVAL);
  
  	/* Can't mix input/output together */
 
 Modified: head/sys/mips/atheros/ar71xx_gpio.c
 ==============================================================================
 --- head/sys/mips/atheros/ar71xx_gpio.c	Sat Apr 13 21:17:43 2013	(r249448)
 +++ head/sys/mips/atheros/ar71xx_gpio.c	Sat Apr 13 21:21:13 2013	(r249449)
 @@ -219,8 +219,8 @@ ar71xx_gpio_pin_setflags(device_t dev, u
  	if (i >= sc->gpio_npins)
  		return (EINVAL);
  
 -	/* Filter out unwanted flags */
 -	if ((flags &= sc->gpio_pins[i].gp_caps) != flags)
 +	/* Check for unwanted flags. */
 +	if ((flags & sc->gpio_pins[i].gp_caps) != flags)
  		return (EINVAL);
  
  	/* Can't mix input/output together */
 
 Modified: head/sys/mips/cavium/octeon_gpio.c
 ==============================================================================
 --- head/sys/mips/cavium/octeon_gpio.c	Sat Apr 13 21:17:43 2013	(r249448)
 +++ head/sys/mips/cavium/octeon_gpio.c	Sat Apr 13 21:21:13 2013	(r249449)
 @@ -219,8 +219,8 @@ octeon_gpio_pin_setflags(device_t dev, u
  	if (i >= sc->gpio_npins)
  		return (EINVAL);
  
 -	/* Filter out unwanted flags */
 -	if ((flags &= sc->gpio_pins[i].gp_caps) != flags)
 +	/* Check for unwanted flags. */
 +	if ((flags & sc->gpio_pins[i].gp_caps) != flags)
  		return (EINVAL);
  
  	/* Can't mix input/output together */
 
 Modified: head/sys/mips/rt305x/rt305x_gpio.c
 ==============================================================================
 --- head/sys/mips/rt305x/rt305x_gpio.c	Sat Apr 13 21:17:43 2013	(r249448)
 +++ head/sys/mips/rt305x/rt305x_gpio.c	Sat Apr 13 21:21:13 2013	(r249449)
 @@ -242,8 +242,8 @@ rt305x_gpio_pin_setflags(device_t dev, u
  	if (i >= sc->gpio_npins)
  		return (EINVAL);
  
 -	/* Filter out unwanted flags */
 -	if ((flags &= sc->gpio_pins[i].gp_caps) != flags)
 +	/* Check for unwanted flags. */
 +	if ((flags & sc->gpio_pins[i].gp_caps) != flags)
  		return (EINVAL);
  
  	/* Can't mix input/output together */
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/177759: commit references a PR
Date: Tue, 16 Apr 2013 16:36:06 +0000 (UTC)

 Author: dim
 Date: Tue Apr 16 16:35:48 2013
 New Revision: 249550
 URL: http://svnweb.freebsd.org/changeset/base/249550
 
 Log:
   MFC r249449:
   
   Fix undefined behaviour in several gpio_pin_setflags() routines (under
   sys/arm and sys/mips), squelching the clang 3.3 warnings about this.
   
   Noticed by:	tinderbox and many irate spectators
   Submitted by:	Luiz Otavio O Souza <loos.br@gmail.com>
   PR:		kern/177759
 
 Modified:
   stable/9/sys/arm/xscale/ixp425/avila_gpio.c
   stable/9/sys/arm/xscale/ixp425/cambria_gpio.c
   stable/9/sys/mips/atheros/ar71xx_gpio.c
   stable/9/sys/mips/rt305x/rt305x_gpio.c
 Directory Properties:
   stable/9/sys/   (props changed)
 
 Modified: stable/9/sys/arm/xscale/ixp425/avila_gpio.c
 ==============================================================================
 --- stable/9/sys/arm/xscale/ixp425/avila_gpio.c	Tue Apr 16 16:09:27 2013	(r249549)
 +++ stable/9/sys/arm/xscale/ixp425/avila_gpio.c	Tue Apr 16 16:35:48 2013	(r249550)
 @@ -220,8 +220,8 @@ avila_gpio_pin_setflags(device_t dev, ui
  	if (pin >= IXP4XX_GPIO_PINS || !(sc->sc_valid & mask))
  		return (EINVAL);
  
 -	/* Filter out unwanted flags */
 -	if ((flags &= sc->sc_pins[pin].gp_caps) != flags)
 +	/* Check for unwanted flags. */
 +	if ((flags & sc->sc_pins[pin].gp_caps) != flags)
  		return (EINVAL);
  
  	/* Can't mix input/output together */
 
 Modified: stable/9/sys/arm/xscale/ixp425/cambria_gpio.c
 ==============================================================================
 --- stable/9/sys/arm/xscale/ixp425/cambria_gpio.c	Tue Apr 16 16:09:27 2013	(r249549)
 +++ stable/9/sys/arm/xscale/ixp425/cambria_gpio.c	Tue Apr 16 16:35:48 2013	(r249550)
 @@ -317,8 +317,8 @@ cambria_gpio_pin_setflags(device_t dev, 
  	if (pin >= GPIO_PINS)
  		return (EINVAL);
  
 -	/* Filter out unwanted flags */
 -	if ((flags &= sc->sc_pins[pin].gp_caps) != flags)
 +	/* Check for unwanted flags. */
 +	if ((flags & sc->sc_pins[pin].gp_caps) != flags)
  		return (EINVAL);
  
  	/* Can't mix input/output together */
 
 Modified: stable/9/sys/mips/atheros/ar71xx_gpio.c
 ==============================================================================
 --- stable/9/sys/mips/atheros/ar71xx_gpio.c	Tue Apr 16 16:09:27 2013	(r249549)
 +++ stable/9/sys/mips/atheros/ar71xx_gpio.c	Tue Apr 16 16:35:48 2013	(r249550)
 @@ -238,8 +238,8 @@ ar71xx_gpio_pin_setflags(device_t dev, u
  	if (i >= sc->gpio_npins)
  		return (EINVAL);
  
 -	/* Filter out unwanted flags */
 -	if ((flags &= sc->gpio_pins[i].gp_caps) != flags)
 +	/* Check for unwanted flags. */
 +	if ((flags & sc->gpio_pins[i].gp_caps) != flags)
  		return (EINVAL);
  
  	/* Can't mix input/output together */
 
 Modified: stable/9/sys/mips/rt305x/rt305x_gpio.c
 ==============================================================================
 --- stable/9/sys/mips/rt305x/rt305x_gpio.c	Tue Apr 16 16:09:27 2013	(r249549)
 +++ stable/9/sys/mips/rt305x/rt305x_gpio.c	Tue Apr 16 16:35:48 2013	(r249550)
 @@ -242,8 +242,8 @@ rt305x_gpio_pin_setflags(device_t dev, u
  	if (i >= sc->gpio_npins)
  		return (EINVAL);
  
 -	/* Filter out unwanted flags */
 -	if ((flags &= sc->gpio_pins[i].gp_caps) != flags)
 +	/* Check for unwanted flags. */
 +	if ((flags & sc->gpio_pins[i].gp_caps) != flags)
  		return (EINVAL);
  
  	/* Can't mix input/output together */
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: dim 
State-Changed-When: Tue Apr 16 17:50:25 UTC 2013 
State-Changed-Why:  
Fix merged to stable/9 and stable/8, where applicable. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=177759 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/177759: commit references a PR
Date: Tue, 16 Apr 2013 17:50:40 +0000 (UTC)

 Author: dim
 Date: Tue Apr 16 17:50:20 2013
 New Revision: 249557
 URL: http://svnweb.freebsd.org/changeset/base/249557
 
 Log:
   MFC r249449:
   
   Fix undefined behaviour in several gpio_pin_setflags() routines (under
   sys/arm and sys/mips), squelching the clang 3.3 warnings about this.
   
   Noticed by:	tinderbox and many irate spectators
   Submitted by:	Luiz Otavio O Souza <loos.br@gmail.com>
   PR:		kern/177759
 
 Modified:
   stable/8/sys/mips/atheros/ar71xx_gpio.c
 Directory Properties:
   stable/8/sys/   (props changed)
   stable/8/sys/mips/   (props changed)
 
 Modified: stable/8/sys/mips/atheros/ar71xx_gpio.c
 ==============================================================================
 --- stable/8/sys/mips/atheros/ar71xx_gpio.c	Tue Apr 16 17:47:13 2013	(r249556)
 +++ stable/8/sys/mips/atheros/ar71xx_gpio.c	Tue Apr 16 17:50:20 2013	(r249557)
 @@ -225,8 +225,8 @@ ar71xx_gpio_pin_setflags(device_t dev, u
  	if (i >= sc->gpio_npins)
  		return (EINVAL);
  
 -	/* Filter out unwanted flags */
 -	if ((flags &= sc->gpio_pins[i].gp_caps) != flags)
 +	/* Check for unwanted flags. */
 +	if ((flags & sc->gpio_pins[i].gp_caps) != flags)
  		return (EINVAL);
  
  	/* Can't mix input/output together */
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
