From 8b5fe624e2c15e4d32036176d93bf25ffb771375 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Tue, 20 May 2025 09:40:08 -0700 Subject: [PATCH] include: usb_ch9: ensure packing of usb_setup_packet struct usb_setup_packet represents the setup data payload of a USB control message which is exactly 8-bytes in length. On a legacy build of GCC 4.1.2 for an OpenRISC-like architecture it was found that the compiler added padding after the bmRequestType anonymous union, and subsequently the bRequest field causing the structure to be padded to 12-bytes in length with the fields incorrectly laid out. This patch corrects the issue by applying the __packed attribute to the anonymous union. This corrects the issue. The __packed attribute is also applied to the outer structure for the sake of consistency. Signed-off-by: Joel Holdsworth --- include/zephyr/usb/usb_ch9.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/zephyr/usb/usb_ch9.h b/include/zephyr/usb/usb_ch9.h index b78be4397fa..8ecadf64bd8 100644 --- a/include/zephyr/usb/usb_ch9.h +++ b/include/zephyr/usb/usb_ch9.h @@ -41,12 +41,12 @@ struct usb_setup_packet { union { uint8_t bmRequestType; struct usb_req_type_field RequestType; - }; + } __packed; uint8_t bRequest; uint16_t wValue; uint16_t wIndex; uint16_t wLength; -}; +} __packed; /** USB Setup packet RequestType Direction values (from Table 9-2) */ #define USB_REQTYPE_DIR_TO_DEVICE 0