Skip to content

Commit 8bcf314

Browse files
Binary-EaterBenjamin Tissoires
authored andcommitted
HID: nvidia-shield: Pack inner/related declarations in HOSTCMD reports
Match alignment information in composite type declarations used by packed HOSTCMD report structures. Compiler packing attribute is not recursive for inner declarations. Mismatched alignment information can cause undefined behavior in code generated for accessing composite type members. struct pointers passed to thunderstrike_parse_board_info_payload and thunderstrike_parse_haptics_payload are an example of this being potentially problematic since alignment information from the packed HOSTCMD report is lost. Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Link: llvm/llvm-project#55520 (comment) Link: https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Common-Type-Attributes.html#index-packed-type-attribute Signed-off-by: Rahul Rameshbabu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 5f15136 commit 8bcf314

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/hid/hid-nvidia-shield.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ static_assert(sizeof(enum thunderstrike_led_state) == 1);
6363
struct thunderstrike_hostcmd_board_info {
6464
__le16 revision;
6565
__le16 serial[7];
66-
};
66+
} __packed;
6767

6868
struct thunderstrike_hostcmd_haptics {
6969
u8 motor_left;
7070
u8 motor_right;
71-
};
71+
} __packed;
7272

7373
struct thunderstrike_hostcmd_resp_report {
7474
u8 report_id; /* THUNDERSTRIKE_HOSTCMD_RESP_REPORT_ID */
@@ -81,7 +81,7 @@ struct thunderstrike_hostcmd_resp_report {
8181
__le16 fw_version;
8282
enum thunderstrike_led_state led_state;
8383
u8 payload[30];
84-
};
84+
} __packed;
8585
} __packed;
8686
static_assert(sizeof(struct thunderstrike_hostcmd_resp_report) ==
8787
THUNDERSTRIKE_HOSTCMD_REPORT_SIZE);
@@ -92,15 +92,15 @@ struct thunderstrike_hostcmd_req_report {
9292
u8 reserved_at_10;
9393

9494
union {
95-
struct {
95+
struct __packed {
9696
u8 update;
9797
enum thunderstrike_led_state state;
9898
} led;
99-
struct {
99+
struct __packed {
100100
u8 update;
101101
struct thunderstrike_hostcmd_haptics motors;
102102
} haptics;
103-
};
103+
} __packed;
104104
u8 reserved_at_30[27];
105105
} __packed;
106106
static_assert(sizeof(struct thunderstrike_hostcmd_req_report) ==

0 commit comments

Comments
 (0)