1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/drivers/net/can/usb
Marc Kleine-Budde a4cb6e62ea can: ems_usb: fix clang's -Wunaligned-access warning
clang emits a -Wunaligned-access warning on struct __packed
ems_cpc_msg.

The reason is that the anonymous union msg (not declared as packed) is
being packed right after some non naturally aligned variables (3*8
bits + 2*32) inside a packed struct:

| struct __packed ems_cpc_msg {
| 	u8 type;	/* type of message */
| 	u8 length;	/* length of data within union 'msg' */
| 	u8 msgid;	/* confirmation handle */
| 	__le32 ts_sec;	/* timestamp in seconds */
| 	__le32 ts_nsec;	/* timestamp in nano seconds */
|	/* ^ not naturally aligned */
|
| 	union {
| 	/* ^ not declared as packed */
| 		u8 generic[64];
| 		struct cpc_can_msg can_msg;
| 		struct cpc_can_params can_params;
| 		struct cpc_confirm confirmation;
| 		struct cpc_overrun overrun;
| 		struct cpc_can_error error;
| 		struct cpc_can_err_counter err_counter;
| 		u8 can_state;
| 	} msg;
| };

Starting from LLVM 14, having an unpacked struct nested in a packed
struct triggers a warning. c.f. [1].

Fix the warning by marking the anonymous union as packed.

[1] https://github.com/llvm/llvm-project/issues/55520

Fixes: 702171adee ("ems_usb: Added support for EMS CPC-USB/ARM7 CAN/USB interface")
Link: https://lore.kernel.org/all/20220802094021.959858-1-mkl@pengutronix.de
Cc: Gerhard Uttenthaler <uttenthaler@ems-wuensche.com>
Cc: Sebastian Haas <haas@ems-wuensche.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-08-09 09:05:06 +02:00
..
etas_es58x can: etas_es58x: remove useless calls to usb_fill_bulk_urb() 2022-07-29 10:14:53 +02:00
kvaser_usb can: kvaser_usb: advertise timestamping capabilities and add ioctl support 2022-07-28 11:44:31 +02:00
peak_usb can: peak_usb: advertise timestamping capabilities and add ioctl support 2022-07-28 11:44:31 +02:00
ems_usb.c can: ems_usb: fix clang's -Wunaligned-access warning 2022-08-09 09:05:06 +02:00
esd_usb.c can: tree-wide: advertise software timestamping capabilities 2022-07-28 11:44:01 +02:00
gs_usb.c can: tree-wide: advertise software timestamping capabilities 2022-07-28 11:44:01 +02:00
Kconfig can/esd_usb2: Rename esd_usb2.c to esd_usb.c 2022-06-25 13:05:26 +02:00
Makefile can/esd_usb2: Rename esd_usb2.c to esd_usb.c 2022-06-25 13:05:26 +02:00
mcba_usb.c can: tree-wide: advertise software timestamping capabilities 2022-07-28 11:44:01 +02:00
ucan.c can: tree-wide: advertise software timestamping capabilities 2022-07-28 11:44:01 +02:00
usb_8dev.c can: tree-wide: advertise software timestamping capabilities 2022-07-28 11:44:01 +02:00