diff mbox

[U-Boot,1/9] usb: Fix strict-aliasing warning in host/ohci-hcd.c

Message ID 1325822097-15227-2-git-send-email-sjg@chromium.org
State Not Applicable, archived
Delegated to: Marek Vasut
Headers show

Commit Message

Simon Glass Jan. 6, 2012, 3:54 a.m. UTC
This fixes these warnings seen with my gcc 4.6 compiler.

ohci-hcd.c: In function 'submit_control_msg':
ohci-hcd.c:1307: warning: dereferencing pointer 'pretmp.729' does break strict-aliasing rules
cc1: note: initialized from here
ohci-hcd.c:1310: warning: dereferencing pointer 'pretmp.729' does break strict-aliasing rules
cc1: note: initialized from here
ohci-hcd.c:1313: warning: dereferencing pointer 'pretmp.729' does break strict-aliasing rules

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 drivers/usb/host/ohci-hcd.c |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)

Comments

Mike Frysinger Jan. 8, 2012, 9:32 a.m. UTC | #1
On Thursday 05 January 2012 22:54:49 Simon Glass wrote:
>  	len = min_t(int, len, leni);
> -	if (data != databuf.ptr)
> -		memcpy(data, databuf.ptr, len);
> +	if (dataptr)
> +		memcpy(data, dataptr, len);
> +	else
> +		memcpy(data, &databuf, len);

this doesn't seem to be equivalent ?
-mike
Simon Glass Jan. 8, 2012, 6:02 p.m. UTC | #2
Hi Mike,

On Sun, Jan 8, 2012 at 1:32 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Thursday 05 January 2012 22:54:49 Simon Glass wrote:
>>       len = min_t(int, len, leni);
>> -     if (data != databuf.ptr)
>> -             memcpy(data, databuf.ptr, len);
>> +     if (dataptr)
>> +             memcpy(data, dataptr, len);
>> +     else
>> +             memcpy(data, &databuf, len);
>
> this doesn't seem to be equivalent ?
> -mike

I believe it is if you look at the entire change, but I might have
missed something. dataptr is used only when we want to pull in the USB
descriptor info. Otherwise we use our local databuf union.

Regards,
Simon
diff mbox

Patch

diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index cf906b4..2cbb326 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -1261,20 +1261,18 @@  static int ohci_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
 	int leni = transfer_len;
 	int len = 0;
 	int stat = 0;
-	__u32 datab[4];
+	u8 *dataptr = NULL;
 	union {
-		void *ptr;
-		__u8 *u8;
-		__u16 *u16;
-		__u32 *u32;
+		/* data will be in here when dataptr stays as NULL */
+		__u8 u8[16];
+		__u16 u16[8];
+		__u32 u32[3];
 	} databuf;
 	__u16 bmRType_bReq;
 	__u16 wValue;
 	__u16 wIndex;
 	__u16 wLength;
 
-	databuf.u32 = (__u32 *)datab;
-
 #ifdef DEBUG
 pkt_print(NULL, dev, pipe, buffer, transfer_len,
 	  cmd, "SUB(rh)", usb_pipein(pipe));
@@ -1381,14 +1379,14 @@  pkt_print(NULL, dev, pipe, buffer, transfer_len,
 					min_t(unsigned int,
 					sizeof(root_hub_dev_des),
 					wLength));
-			databuf.ptr = root_hub_dev_des; OK(len);
+			dataptr = 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));
-			databuf.ptr = root_hub_config_des; OK(len);
+			dataptr = root_hub_config_des; OK(len);
 		case (0x03): /* string descriptors */
 			if (wValue == 0x0300) {
 				len = min_t(unsigned int,
@@ -1396,7 +1394,7 @@  pkt_print(NULL, dev, pipe, buffer, transfer_len,
 						min_t(unsigned int,
 						sizeof(root_hub_str_index0),
 						wLength));
-				databuf.ptr = root_hub_str_index0;
+				dataptr = root_hub_str_index0;
 				OK(len);
 			}
 			if (wValue == 0x0301) {
@@ -1405,7 +1403,7 @@  pkt_print(NULL, dev, pipe, buffer, transfer_len,
 						min_t(unsigned int,
 						sizeof(root_hub_str_index1),
 						wLength));
-				databuf.ptr = root_hub_str_index1;
+				dataptr = root_hub_str_index1;
 				OK(len);
 		}
 		default:
@@ -1469,8 +1467,10 @@  pkt_print(NULL, dev, pipe, buffer, transfer_len,
 #endif
 
 	len = min_t(int, len, leni);
-	if (data != databuf.ptr)
-		memcpy(data, databuf.ptr, len);
+	if (dataptr)
+		memcpy(data, dataptr, len);
+	else
+		memcpy(data, &databuf, len);
 	dev->act_len = len;
 	dev->status = stat;