Skip to contentSkip to conversation

usbtty: fix possible alignment issues

PATCH RESEND Superseded Seung-Woo Kim 2 participants 4 messages Jan 7, 2020 – Jan 8, 2020 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20200107052020epcas1p2a5809802832bcf3b8305c6be49e87c00@epcas1p2.samsung.com

#1 lore raw

PATCH RESEND 1/1 usbtty: fix possible alignment issues

With gcc9, below warnings are shown:
drivers/serial/usbtty.c: In function 'usbtty_init_strings':
drivers/serial/usbtty.c:590:44: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]

    590 |  str2wide (CONFIG_USBD_MANUFACTURER, string->wData);
        |                                      ~~~~~~^~~~~~~
  drivers/serial/usbtty.c:596:44: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
    597 |  str2wide (CONFIG_USBD_PRODUCT_NAME, string->wData);
        |                                      ~~~~~~^~~~~~~
  drivers/serial/usbtty.c:603:33: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
    604 |  str2wide (serial_number, string->wData);
        |                           ~~~~~~^~~~~~~
  drivers/serial/usbtty.c:610:49: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
    611 |  str2wide (CONFIG_USBD_CONFIGURATION_STR, string->wData);
        |                                           ~~~~~~^~~~~~~
  drivers/serial/usbtty.c:617:50: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
    618 |  str2wide (CONFIG_USBD_DATA_INTERFACE_STR, string->wData);
        |                                            ~~~~~~^~~~~~~
  drivers/serial/usbtty.c:623:50: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
    624 |  str2wide (CONFIG_USBD_CTRL_INTERFACE_STR, string->wData);
        |                                            ~~~~~~^~~~~~~

Fix the issues by using packed structure.

Ref: commit 616ebd8b9cb4 ("usb: composite: fix possible alignment issues")

---
resend with proper e-mail address

---
 drivers/serial/usbtty.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/serial/usbtty.c +6 -3
index f1c1a260da..54e67dd0d1 100644
@@ -48,6 +48,8 @@
 #define CONFIG_USBD_DATA_INTERFACE_STR "Bulk Data Interface"
 #define CONFIG_USBD_CTRL_INTERFACE_STR "Control Interface"
 
+typedef struct { __le16 val; } __attribute__((aligned(16))) __le16_packed;
+
 /*
  * Buffers to hold input and output data
  */
@@ -372,14 +374,15 @@ static int fill_buffer (circbuf_t * buf);
 void usbtty_poll (void);
 
 /* utility function for converting char* to wide string used by USB */
-static void str2wide (char *str, u16 * wide)
+static void str2wide (char *str, void *wide)
 {
 	int i;
+	__le16_packed	*tmp = wide;
 	for (i = 0; i < strlen (str) && str[i]; i++){
 		#if defined(__LITTLE_ENDIAN)
-			wide[i] = (u16) str[i];
+			tmp[i].val = (u16) str[i];
 		#elif defined(__BIG_ENDIAN)
-			wide[i] = ((u16)(str[i])<<8);
+			tmp[i].val = ((u16)(str[i])<<8);
 		#else
 			#error "__LITTLE_ENDIAN or __BIG_ENDIAN undefined"
 		#endif
Signature · 1 line
2.19.2
#2 lore raw

PATCH RESEND 1/1 usbtty: fix possible alignment issues

Quoted 53 lines · Seung-Woo Kim

With gcc9, below warnings are shown:
drivers/serial/usbtty.c: In function 'usbtty_init_strings':
drivers/serial/usbtty.c:590:44: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]

    590 |  str2wide (CONFIG_USBD_MANUFACTURER, string->wData);
        |                                      ~~~~~~^~~~~~~
  drivers/serial/usbtty.c:596:44: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
    597 |  str2wide (CONFIG_USBD_PRODUCT_NAME, string->wData);
        |                                      ~~~~~~^~~~~~~
  drivers/serial/usbtty.c:603:33: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
    604 |  str2wide (serial_number, string->wData);
        |                           ~~~~~~^~~~~~~
  drivers/serial/usbtty.c:610:49: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
    611 |  str2wide (CONFIG_USBD_CONFIGURATION_STR, string->wData);
        |                                           ~~~~~~^~~~~~~
  drivers/serial/usbtty.c:617:50: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
    618 |  str2wide (CONFIG_USBD_DATA_INTERFACE_STR, string->wData);
        |                                            ~~~~~~^~~~~~~
  drivers/serial/usbtty.c:623:50: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
    624 |  str2wide (CONFIG_USBD_CTRL_INTERFACE_STR, string->wData);
        |                                            ~~~~~~^~~~~~~

Fix the issues by using packed structure.

Ref: commit 616ebd8b9cb4 ("usb: composite: fix possible alignment issues")

---
resend with proper e-mail address

---
 drivers/serial/usbtty.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/serial/usbtty.c +4 -1
index f1c1a260da..54e67dd0d1 100644
@@ -48,6 +48,8 @@
 #define CONFIG_USBD_DATA_INTERFACE_STR "Bulk Data Interface"
 #define CONFIG_USBD_CTRL_INTERFACE_STR "Control Interface"
 
+typedef struct { __le16 val; } __attribute__((aligned(16))) __le16_packed;
+
 /*
  * Buffers to hold input and output data
  */
@@ -372,14 +374,15 @@ static int fill_buffer (circbuf_t * buf);
 void usbtty_poll (void);
 
 /* utility function for converting char* to wide string used by USB */
-static void str2wide (char *str, u16 * wide)
+static void str2wide (char *str, void *wide)
 {
 	int i;
+	__le16_packed	*tmp = wide;

drivers/serial/usbtty.c static int fill_buffer (circbuf_t * buf); · line 388

Quoted 10 lines
drivers/serial/usbtty.c +2 -2
 	for (i = 0; i < strlen (str) && str[i]; i++){
 		#if defined(__LITTLE_ENDIAN)
-			wide[i] = (u16) str[i];
+			tmp[i].val = (u16) str[i];
 		#elif defined(__BIG_ENDIAN)
-			wide[i] = ((u16)(str[i])<<8);
+			tmp[i].val = ((u16)(str[i])<<8);
 		#else
 			#error "__LITTLE_ENDIAN or __BIG_ENDIAN undefined"
 		#endif

We generally don't want packed structs and do need to disable this warning in general. Is this _really_ a problem, or are we just silencing the compiler here? Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200107/d43451a4/attachment.sig>
#3 lore raw

PATCH RESEND 1/1 usbtty: fix possible alignment issues

Hi,

Quoted 2 lines · Tom Rini

On Tue, Jan 07, 2020 at 02:25:02PM +0900, Seung-Woo Kim wrote:

...

Quoted 32 lines
Quoted 32 lines
---
 drivers/serial/usbtty.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/serial/usbtty.c +5 -3
index f1c1a260da..54e67dd0d1 100644
@@ -48,6 +48,8 @@
 #define CONFIG_USBD_DATA_INTERFACE_STR "Bulk Data Interface"
 #define CONFIG_USBD_CTRL_INTERFACE_STR "Control Interface"
 
+typedef struct { __le16 val; } __attribute__((aligned(16))) __le16_packed;
+
 /*
  * Buffers to hold input and output data
  */
@@ -372,14 +374,15 @@ static int fill_buffer (circbuf_t * buf);
 void usbtty_poll (void);
 
 /* utility function for converting char* to wide string used by USB */
-static void str2wide (char *str, u16 * wide)
+static void str2wide (char *str, void *wide)
 {
 	int i;
+	__le16_packed	*tmp = wide;
 	for (i = 0; i < strlen (str) && str[i]; i++){
 		#if defined(__LITTLE_ENDIAN)
-			wide[i] = (u16) str[i];
+			tmp[i].val = (u16) str[i];
 		#elif defined(__BIG_ENDIAN)
-			wide[i] = ((u16)(str[i])<<8);
Quoted 8 lines

drivers/serial/usbtty.c static int fill_buffer (circbuf_t * buf); · line 388

Quoted 4 lines
drivers/serial/usbtty.c +1 -0
+			tmp[i].val = ((u16)(str[i])<<8);
 		#else
 			#error "__LITTLE_ENDIAN or __BIG_ENDIAN undefined"
 		#endif

We generally don't want packed structs and do need to disable this warning in general. Is this _really_ a problem, or are we just silencing the compiler here? Thanks!

The change makes just silence for the warnings as like composite.c in usb gadget.

Regards,
- Seung-Woo Kim

#4 lore raw

PATCH RESEND 1/1 usbtty: fix possible alignment issues

Quoted 47 lines · Seung-Woo Kim

Hi,

Quoted 2 lines · Tom Rini

On Tue, Jan 07, 2020 at 02:25:02PM +0900, Seung-Woo Kim wrote:

...

Quoted 32 lines
Quoted 32 lines
---
 drivers/serial/usbtty.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/serial/usbtty.c +5 -3
index f1c1a260da..54e67dd0d1 100644
@@ -48,6 +48,8 @@
 #define CONFIG_USBD_DATA_INTERFACE_STR "Bulk Data Interface"
 #define CONFIG_USBD_CTRL_INTERFACE_STR "Control Interface"
 
+typedef struct { __le16 val; } __attribute__((aligned(16))) __le16_packed;
+
 /*
  * Buffers to hold input and output data
  */
@@ -372,14 +374,15 @@ static int fill_buffer (circbuf_t * buf);
 void usbtty_poll (void);
 
 /* utility function for converting char* to wide string used by USB */
-static void str2wide (char *str, u16 * wide)
+static void str2wide (char *str, void *wide)
 {
 	int i;
+	__le16_packed	*tmp = wide;
 	for (i = 0; i < strlen (str) && str[i]; i++){
 		#if defined(__LITTLE_ENDIAN)
-			wide[i] = (u16) str[i];
+			tmp[i].val = (u16) str[i];
 		#elif defined(__BIG_ENDIAN)
-			wide[i] = ((u16)(str[i])<<8);
Quoted 8 lines

drivers/serial/usbtty.c static int fill_buffer (circbuf_t * buf); · line 388

Quoted 4 lines
drivers/serial/usbtty.c +1 -0
+			tmp[i].val = ((u16)(str[i])<<8);
 		#else
 			#error "__LITTLE_ENDIAN or __BIG_ENDIAN undefined"
 		#endif

We generally don't want packed structs and do need to disable this warning in general. Is this _really_ a problem, or are we just silencing the compiler here? Thanks!

Quoted 2 lines

The change makes just silence for the warnings as like composite.c in usb gadget.

OK, thanks. NAK on this and I will pick up the general change to disable this warning soon.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200107/d6b056e6/attachment.sig>