All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/9] ppc4xx: Fix strict-aliasing warnings in usb_ohci.c
Date: Thu,  5 Jan 2012 19:54:52 -0800	[thread overview]
Message-ID: <1325822097-15227-5-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1325822097-15227-1-git-send-email-sjg@chromium.org>

This fixes warnings seen with my gcc 4.6.

usb_ohci.c: In function 'submit_control_msg':
usb_ohci.c:1046: warning: dereferencing pointer 'data_buf.70' does break
strict-aliasing rules
usb_ohci.c:1046: note: initialized from here
usb_ohci.c:1048: warning: dereferencing pointer 'data_buf.70' does break
strict-aliasing rules
usb_ohci.c:1048: note: initialized from here
usb_ohci.c:1050: warning: dereferencing pointer 'data_buf.70' does break
strict-aliasing rules

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 arch/powerpc/cpu/ppc4xx/usb_ohci.c |   81 +++++++++++++++++++++---------------
 1 files changed, 48 insertions(+), 33 deletions(-)

diff --git a/arch/powerpc/cpu/ppc4xx/usb_ohci.c b/arch/powerpc/cpu/ppc4xx/usb_ohci.c
index 4fb7031..57fa24f 100644
--- a/arch/powerpc/cpu/ppc4xx/usb_ohci.c
+++ b/arch/powerpc/cpu/ppc4xx/usb_ohci.c
@@ -1010,12 +1010,19 @@ static int ohci_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
 	int len = 0;
 	int stat = 0;
 	__u32 datab[4];
-	__u8 *data_buf = (__u8 *)datab;
+	union {
+		void *ptr;
+		__u8 *u8;
+		__u16 *u16;
+		__u32 *u32;
+	} databuf;
 	__u16 bmRType_bReq;
 	__u16 wValue;
 	__u16 wIndex;
 	__u16 wLength;
 
+	databuf.u32 = (__u32 *)datab;
+
 #ifdef DEBUG
 urb_priv.actual_length = 0;
 pkt_print(dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe));
@@ -1043,17 +1050,21 @@ pkt_print(dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe));
 	*/
 
 	case RH_GET_STATUS:
-			*(__u16 *) data_buf = m16_swap (1); OK (2);
+		databuf.u16[0] = m16_swap(1);
+		OK(2);
 	case RH_GET_STATUS | RH_INTERFACE:
-			*(__u16 *) data_buf = m16_swap (0); OK (2);
+		databuf.u16[0] = m16_swap(0);
+		OK(2);
 	case RH_GET_STATUS | RH_ENDPOINT:
-			*(__u16 *) data_buf = m16_swap (0); OK (2);
+		databuf.u16[0] = m16_swap(0);
+		OK(2);
 	case RH_GET_STATUS | RH_CLASS:
-			*(__u32 *) data_buf = m32_swap (
-				RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE));
-			OK (4);
+		databuf.u32[0] = m32_swap(
+			RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE));
+		OK(4);
 	case RH_GET_STATUS | RH_OTHER | RH_CLASS:
-			*(__u32 *) data_buf = m32_swap (RD_RH_PORTSTAT); OK (4);
+		databuf.u32[0] = m32_swap(RD_RH_PORTSTAT);
+		OK(4);
 
 	case RH_CLEAR_FEATURE | RH_ENDPOINT:
 		switch (wValue) {
@@ -1118,14 +1129,14 @@ pkt_print(dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe));
 					  min_t(unsigned int,
 					      sizeof (root_hub_dev_des),
 					      wLength));
-				data_buf = root_hub_dev_des; OK(len);
+				databuf.ptr = root_hub_dev_des; OK(len);
 			case (0x02): /* configuration descriptor */
 				len = min_t(unsigned int,
 					  leni,
 					  min_t(unsigned int,
 					      sizeof (root_hub_config_des),
 					      wLength));
-				data_buf = root_hub_config_des; OK(len);
+				databuf.ptr = root_hub_config_des; OK(len);
 			case (0x03): /* string descriptors */
 				if(wValue==0x0300) {
 					len = min_t(unsigned int,
@@ -1133,7 +1144,7 @@ pkt_print(dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe));
 						  min_t(unsigned int,
 						      sizeof (root_hub_str_index0),
 						      wLength));
-					data_buf = root_hub_str_index0;
+					databuf.ptr = root_hub_str_index0;
 					OK(len);
 				}
 				if(wValue==0x0301) {
@@ -1142,7 +1153,7 @@ pkt_print(dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe));
 						  min_t(unsigned int,
 						      sizeof (root_hub_str_index1),
 						      wLength));
-					data_buf = root_hub_str_index1;
+					databuf.ptr = root_hub_str_index1;
 					OK(len);
 			}
 			default:
@@ -1154,38 +1165,42 @@ pkt_print(dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe));
 	    {
 		    __u32 temp = roothub_a (&gohci);
 
-		    data_buf [0] = 9;		/* min length; */
-		    data_buf [1] = 0x29;
-		    data_buf [2] = temp & RH_A_NDP;
-		    data_buf [3] = 0;
+		    databuf.u8[0] = 9;		/* min length; */
+		    databuf.u8[1] = 0x29;
+		    databuf.u8[2] = temp & RH_A_NDP;
+		    databuf.u8[3] = 0;
 		    if (temp & RH_A_PSM)	/* per-port power switching? */
-			data_buf [3] |= 0x1;
+			databuf.u8[3] |= 0x1;
 		    if (temp & RH_A_NOCP)	/* no overcurrent reporting? */
-			data_buf [3] |= 0x10;
+			databuf.u8[3] |= 0x10;
 		    else if (temp & RH_A_OCPM)	/* per-port overcurrent reporting? */
-			data_buf [3] |= 0x8;
+			databuf.u8[3] |= 0x8;
 
 		    /* corresponds to data_buf[4-7] */
-		    datab [1] = 0;
-		    data_buf [5] = (temp & RH_A_POTPGT) >> 24;
+		    databuf.u32[1] = 0;
+		    databuf.u8[5] = (temp & RH_A_POTPGT) >> 24;
 		    temp = roothub_b (&gohci);
-		    data_buf [7] = temp & RH_B_DR;
-		    if (data_buf [2] < 7) {
-			data_buf [8] = 0xff;
+		    databuf.u8[7] = temp & RH_B_DR;
+		    if (databuf.u8[2] < 7) {
+			databuf.u8[8] = 0xff;
 		    } else {
-			data_buf [0] += 2;
-			data_buf [8] = (temp & RH_B_DR) >> 8;
-			data_buf [10] = data_buf [9] = 0xff;
+			databuf.u8[0] += 2;
+			databuf.u8[8] = (temp & RH_B_DR) >> 8;
+			databuf.u8[10] = databuf.u8[9] = 0xff;
 		    }
 
 		    len = min_t(unsigned int, leni,
-			      min_t(unsigned int, data_buf [0], wLength));
-		    OK (len);
+			      min_t(unsigned int, databuf.u8[0], wLength));
+		    OK(len);
 		}
 
-	case RH_GET_CONFIGURATION:	*(__u8 *) data_buf = 0x01; OK (1);
+	case RH_GET_CONFIGURATION:
+		databuf.u8[0] = 0x01;
+		OK(1);
 
-	case RH_SET_CONFIGURATION:	WR_RH_STAT (0x10000); OK (0);
+	case RH_SET_CONFIGURATION:
+		WR_RH_STAT(0x10000);
+		OK(0);
 
 	default:
 		dbg ("unsupported root hub command");
@@ -1197,8 +1212,8 @@ pkt_print(dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe));
 #endif
 
 	len = min_t(int, len, leni);
-	if (data != data_buf)
-	    memcpy (data, data_buf, len);
+	if (data != databuf.ptr)
+		memcpy(data, databuf.ptr, len);
 	dev->act_len = len;
 	dev->status = stat;
 
-- 
1.7.3.1

  parent reply	other threads:[~2012-01-06  3:54 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-06  3:54 [U-Boot] [PATCH 0/9] Fix a few warnings that bug me Simon Glass
2012-01-06  3:54 ` [U-Boot] [PATCH 1/9] usb: Fix strict-aliasing warning in host/ohci-hcd.c Simon Glass
2012-01-08  9:32   ` Mike Frysinger
2012-01-08 18:02     ` Simon Glass
2012-01-06  3:54 ` [U-Boot] [PATCH 2/9] Fix strict-aliasing warning in dlmalloc Simon Glass
2012-01-06  6:48   ` Wolfgang Denk
2012-01-06 20:39     ` Simon Glass
2012-01-06 23:37       ` Wolfgang Denk
2012-01-08  0:57         ` Simon Glass
2012-01-08  9:27       ` Mike Frysinger
2012-08-13 15:25   ` Andreas Bießmann
2012-09-04 21:25     ` Andreas Bießmann
2012-01-06  3:54 ` [U-Boot] [PATCH 3/9] mpc5xxx: Fix strict-aliasing warnings in usb_ohci.c Simon Glass
2012-01-06  3:54 ` Simon Glass [this message]
2012-10-16  6:28   ` [U-Boot] [PATCH 4/9] ppc4xx: " Marek Vasut
2012-10-16 13:35     ` Simon Glass
2012-01-06  3:54 ` [U-Boot] [PATCH 5/9] sandbox: sort header files in os.c Simon Glass
2012-01-08  8:49   ` Mike Frysinger
2012-01-09 22:17     ` Simon Glass
2012-01-06  3:54 ` [U-Boot] [PATCH 6/9] sandbox: Add required header to os.c Simon Glass
2012-01-08  8:49   ` Mike Frysinger
2012-01-09 22:18     ` Simon Glass
2012-01-06  3:54 ` [U-Boot] [PATCH 7/9] Remove CONFIG_SYS_EXTBDINFO from snapper9260.h Simon Glass
2012-02-22 11:07   ` Stefano Babic
2012-03-27 16:58   ` Anatolij Gustschin
2012-01-06  3:54 ` [U-Boot] [PATCH 8/9] m68k: Change memsz to a signed char to avoid warning Simon Glass
2012-01-08  9:29   ` Mike Frysinger
2012-02-22 12:01   ` Stefano Babic
2012-01-06  3:54 ` [U-Boot] [PATCH 9/9] ppc: Change memsz variable to signed char Simon Glass
2012-01-08  9:29   ` Mike Frysinger
2012-02-22 12:00   ` Stefano Babic
2012-01-06  6:20 ` [U-Boot] [PATCH 0/9] Fix a few warnings that bug me Wolfgang Denk
2012-01-06  6:28   ` Simon Glass
2012-02-20 18:49     ` Simon Glass
2012-02-21 10:20       ` Stefano Babic
2012-02-21 13:49         ` Stefano Babic
2012-02-21 17:06         ` Mike Frysinger
2012-02-21 17:15           ` Stefano Babic
2012-02-21 18:40             ` Simon Glass
2012-02-22  5:35               ` Mike Frysinger
2012-02-22 11:06               ` Stefano Babic
2012-03-03 14:31               ` Wolfgang Denk
2012-03-05 18:22 ` Marek Vasut
2012-03-05 18:33   ` Simon Glass
2012-03-05 18:42     ` Andy Pont
2012-03-05 19:17       ` Wolfgang Denk
2012-03-05 18:46     ` Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1325822097-15227-5-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.