Skip to content

Commit 8b5fe62

Browse files
jholkartben
authored andcommitted
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 <[email protected]>
1 parent 3991604 commit 8b5fe62

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/zephyr/usb/usb_ch9.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ struct usb_setup_packet {
4141
union {
4242
uint8_t bmRequestType;
4343
struct usb_req_type_field RequestType;
44-
};
44+
} __packed;
4545
uint8_t bRequest;
4646
uint16_t wValue;
4747
uint16_t wIndex;
4848
uint16_t wLength;
49-
};
49+
} __packed;
5050

5151
/** USB Setup packet RequestType Direction values (from Table 9-2) */
5252
#define USB_REQTYPE_DIR_TO_DEVICE 0

0 commit comments

Comments
 (0)