Skip to contentSkip to conversation

ratp: Mark struct ratp_bb as packed

PATCH In review Andrey Smirnov 2 participants 7 messages Sep 7, 2019 – Sep 12, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 ratp: Mark struct ratp_bb as packed

Mark struct ratp_bb as packed to make sure that it has the same alignment as struct ratp_bb_md_response and struct ratp_bb_mw_response where it's used. GCC9 catches this mismatch and generates a -Waddress-of-packed-member warning

---
 include/ratp_bb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/ratp_bb.h +1 -1
index b6699979b6..9162e7cbe5 100644
@@ -32,7 +32,7 @@ struct ratp_bb {
 	uint16_t type;
 	uint16_t flags;
 	uint8_t data[];
-};
+} __packed;
 
 struct ratp_bb_pkt {
 	unsigned int len;
Signature · 7 lines
2.21.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 2/4 net: Adjust net_copy_uint32's signature

Net_copy_uint32() uses memcpy() under the hood, so there's no need to specify "to" and "from" parameters as uint32_t * and place stricter alignment requirements than necessary.

GCC9 generates a couple of -Waddress-of-packed-member warnings here otherwise.

---
 include/net.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net.h +1 -1
index 6912a557b5..3491425e09 100644
@@ -315,7 +315,7 @@ static inline void net_copy_ip(void *to, void *from)
 }
 
 /* copy ulong */
-static inline void net_copy_uint32(uint32_t *to, uint32_t *from)
+static inline void net_copy_uint32(void *to, void *from)
 {
 	memcpy(to, from, sizeof(uint32_t));
 }
Signature · 7 lines
2.21.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH 3/4 mtd: ubi: Compile fastmap.c with -Wno-address-of-packed-member

In reply to Andrey Smirnov

GCC9 for ARM produces the following warnings:

fastmap.c: In function 'ubi_attach_fastmap':
fastmap.c:700:31: warning: taking address of packed member of 'struct ubi_fm_scan_pool' may result in an unaligned pointer value [-Waddress-of-packed-member]

  700 |  ret = scan_pool(ubi, ai, fmpl->pebs, pool_size, &max_sqnum, &lfree);
      |                           ~~~~^~~~~~
fastmap.c:704:34: warning: taking address of packed member of 'struct ubi_fm_scan_pool' may result in an unaligned pointer value [-Waddress-of-packed-member]
  704 |  ret = scan_pool(ubi, ai, fmpl_wl->pebs, wl_pool_size, &max_sqnum, &lfree);
      |                           ~~~~~~~^~~~~~

the offending code seems OK and there doesn't seem to be a way to fix this in code, so disable the warning for that file.

---
 drivers/mtd/ubi/Makefile | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/ubi/Makefile +1 -0
index 33ac39026c..6ffb4ae2bc 100644
@@ -2,4 +2,5 @@ obj-$(CONFIG_MTD_UBI) += ubi.o
 
 ubi-y += vtbl.o vmt.o upd.o build.o barebox.o kapi.o eba.o io.o wl.o attach.o
 ubi-y += misc.o debug.o
+CFLAGS_fastmap.o := -Wno-address-of-packed-member
 ubi-$(CONFIG_MTD_UBI_FASTMAP) += fastmap.o
Signature · 7 lines
2.21.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

Re: [PATCH 3/4] mtd: ubi: Compile fastmap.c with -Wno-address-of-packed-member

Quoted 10 lines · Andrey Smirnov

GCC9 for ARM produces the following warnings:

fastmap.c: In function 'ubi_attach_fastmap':
fastmap.c:700:31: warning: taking address of packed member of 'struct ubi_fm_scan_pool' may result in an unaligned pointer value [-Waddress-of-packed-member]

  700 |  ret = scan_pool(ubi, ai, fmpl->pebs, pool_size, &max_sqnum, &lfree);
      |                           ~~~~^~~~~~
fastmap.c:704:34: warning: taking address of packed member of 'struct ubi_fm_scan_pool' may result in an unaligned pointer value [-Waddress-of-packed-member]
  704 |  ret = scan_pool(ubi, ai, fmpl_wl->pebs, wl_pool_size, &max_sqnum, &lfree);
      |                           ~~~~~~~^~~~~~
Quoted 5 lines

the offending code seems OK and there doesn't seem to be a way to fix this in code, so disable the warning for that file.

---

Linux disables this warning completely. We just burnt some developer cycles, came to the conclusion that the world isn't perfect, that there's no good (at least good realistic) solution to this problem and that we should just do the same as Linux.

Disabling this warning for individual files in which it triggers probably doesn't bring us further.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

Re: [PATCH 3/4] mtd: ubi: Compile fastmap.c with -Wno-address-of-packed-member

Quoted 12 lines · Sascha Hauer
Quoted 10 lines · Andrey Smirnov

GCC9 for ARM produces the following warnings:

fastmap.c: In function 'ubi_attach_fastmap':
fastmap.c:700:31: warning: taking address of packed member of 'struct ubi_fm_scan_pool' may result in an unaligned pointer value [-Waddress-of-packed-member]

  700 |  ret = scan_pool(ubi, ai, fmpl->pebs, pool_size, &max_sqnum, &lfree);
      |                           ~~~~^~~~~~
fastmap.c:704:34: warning: taking address of packed member of 'struct ubi_fm_scan_pool' may result in an unaligned pointer value [-Waddress-of-packed-member]
  704 |  ret = scan_pool(ubi, ai, fmpl_wl->pebs, wl_pool_size, &max_sqnum, &lfree);
      |                           ~~~~~~~^~~~~~
Quoted 7 lines
Quoted 5 lines

the offending code seems OK and there doesn't seem to be a way to fix this in code, so disable the warning for that file.

---

Linux disables this warning completely.

Yeah, I saw that. Wasn't sure if we wanted to go that direction or not.

Quoted 8 lines

We just burnt some developer
cycles, came to the conclusion that the world isn't perfect, that there's no good (at least good realistic) solution to this problem and that we should just do the same as Linux.

Disabling this warning for individual files in which it triggers probably doesn't bring us further.

Sure, will do. I think "ratp: Mark struct ratp_bb as packed" might still be worth applying though.

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#5 lore raw

Re: [PATCH 3/4] mtd: ubi: Compile fastmap.c with -Wno-address-of-packed-member

Quoted 28 lines · Andrey Smirnov
Quoted 12 lines · Sascha Hauer
Quoted 10 lines · Andrey Smirnov

GCC9 for ARM produces the following warnings:

fastmap.c: In function 'ubi_attach_fastmap':
fastmap.c:700:31: warning: taking address of packed member of 'struct ubi_fm_scan_pool' may result in an unaligned pointer value [-Waddress-of-packed-member]

  700 |  ret = scan_pool(ubi, ai, fmpl->pebs, pool_size, &max_sqnum, &lfree);
      |                           ~~~~^~~~~~
fastmap.c:704:34: warning: taking address of packed member of 'struct ubi_fm_scan_pool' may result in an unaligned pointer value [-Waddress-of-packed-member]
  704 |  ret = scan_pool(ubi, ai, fmpl_wl->pebs, wl_pool_size, &max_sqnum, &lfree);
      |                           ~~~~~~~^~~~~~
Quoted 7 lines
Quoted 5 lines

the offending code seems OK and there doesn't seem to be a way to fix this in code, so disable the warning for that file.

---

Linux disables this warning completely.

Yeah, I saw that. Wasn't sure if we wanted to go that direction or not.

Quoted 5 lines

We just burnt some developer
cycles, came to the conclusion that the world isn't perfect, that there's no good (at least good realistic) solution to this problem and that we should just do the same as Linux.

Quoted 6 lines
Quoted 3 lines

Disabling this warning for individual files in which it triggers probably doesn't bring us further.

Sure, will do. I think "ratp: Mark struct ratp_bb as packed" might still be worth applying though.

Applied this and also [PATCH 2/4] net: Adjust net_copy_uint32's signature

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH 4/4 USB: gadget: Compile composite.c with -Wno-address-of-packed-member

In reply to Andrey Smirnov

GCC9 for ARM produces the following warnings:

drivers/usb/gadget/composite.c: In function 'bos_desc':
drivers/usb/gadget/composite.c:522:15: warning: taking address of packed member of 'struct usb_bos_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]

  522 |  le16_add_cpu(&bos->wTotalLength, USB_DT_USB_EXT_CAP_SIZE);
      |               ^~~~~~~~~~~~~~~~~~
drivers/usb/gadget/composite.c:534:15: warning: taking address of packed member of 'struct usb_bos_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
  534 |  le16_add_cpu(&bos->wTotalLength, USB_DT_USB_SS_CAP_SIZE);
      |               ^~~~~~~~~~~~~~~~~~
drivers/usb/gadget/composite.c: In function 'get_string':
drivers/usb/gadget/composite.c:928:23: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
  928 |    collect_langs(sp, s->wData);
      |                      ~^~~~~~~
drivers/usb/gadget/composite.c:933:24: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
  933 |     collect_langs(sp, s->wData);
      |                       ~^~~~~~~
drivers/usb/gadget/composite.c:938:25: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
  938 |      collect_langs(sp, s->wData);
      |                        ~^~~~~~~
drivers/usb/gadget/composite.c:945:23: warning: taking address of packed member of 'struct usb_string_descriptor' may result in an unaligned pointer value [-Waddress-of-packed-member]
  945 |    collect_langs(sp, s->wData);
      |                      ~^~~~~~~

the offending code seems OK and there doesn't seem to be a way to fix this in code, so disable the warning for that file.

---
 drivers/usb/gadget/Makefile | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/gadget/Makefile +2 -0
index 9ef594575b..8d399e568f 100644
@@ -1,4 +1,6 @@
 
+CFLAGS_composite.o := -Wno-address-of-packed-member
+
 obj-$(CONFIG_USB_GADGET) += composite.o config.o usbstring.o epautoconf.o udc-core.o functions.o config.o multi.o
 obj-$(CONFIG_USB_GADGET_SERIAL) += u_serial.o serial.o f_serial.o f_acm.o
 obj-$(CONFIG_USB_GADGET_DFU) += dfu.o
Signature · 7 lines
2.21.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox