-Wflex-array-member-not-at-end was introduced in GCC-14, and we are getting ready to enable it, globally. Use an anonymous embedded struct (enabled via -fms-extensions) to split the header portion from the flexible-array member in struct iwl_dhc_cmd, so the new header type struct iwl_dhc_cmd_hdr can be referenced independently (of the flexible-array member), and fix the following warning: drivers/net/wireless/intel/iwlwifi/mld/tlc.c:544:36: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] Add comments and a static_assert() to prevent adding new members directly to struct iwl_dhc_cmd. Any new members must be added to struct iwl_dhc_cmd_hdr instead. This preserves the expected memory layout between the header and the flexible-array member. Signed-off-by: Gustavo A. R. Silva --- .../net/wireless/intel/iwlwifi/fw/api/dhc.h | 21 ++++++++++++++++--- drivers/net/wireless/intel/iwlwifi/mld/tlc.c | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/dhc.h b/drivers/net/wireless/intel/iwlwifi/fw/api/dhc.h index b6d79c678cd8..bce4097fee27 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/dhc.h +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/dhc.h @@ -51,7 +51,7 @@ enum iwl_dhc_umac_integration_table { #define DHC_TARGET_UMAC BIT(27) /** - * struct iwl_dhc_cmd - debug host command + * struct iwl_dhc_cmd_hdr - debug host command header * @length: length in DWs of the data structure that is concatenated to the end * of this struct * @index_and_mask: bit 31 is 1 for data set operation else it's 0 @@ -62,14 +62,29 @@ enum iwl_dhc_umac_integration_table { * bit 26 is 0 if the cmd targeted to LMAC0 and 1 if targeted to LMAC1, * relevant only if bit 27 set to 0 * bits 0-25 is a specific entry index in the table specified in bits 28-30 + */ +struct iwl_dhc_cmd_hdr { + __le32 length; + __le32 index_and_mask; +} __packed; + +/** + * struct iwl_dhc_cmd - debug host command + * + * (NOTE: New members MUST NOT be added directly to this struct. Add them to + * struct iwl_dhc_cmd_hdr instead.) * + * @iwl_dhc_cmd_hdr: anonymous embedded header - members are directly + * accessible * @data: the concatenated data. + * */ struct iwl_dhc_cmd { - __le32 length; - __le32 index_and_mask; + struct iwl_dhc_cmd_hdr; __le32 data[]; } __packed; /* DHC_CMD_API_S */ +static_assert(offsetof(struct iwl_dhc_cmd, data) == sizeof(struct iwl_dhc_cmd_hdr), + "New members must be added to struct iwl_dhc_cmd_hdr instead."); /** * struct iwl_dhc_payload_hdr - DHC payload header diff --git a/drivers/net/wireless/intel/iwlwifi/mld/tlc.c b/drivers/net/wireless/intel/iwlwifi/mld/tlc.c index 78d6162d9297..b6f41a8c138e 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/tlc.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/tlc.c @@ -619,7 +619,7 @@ static void iwl_mld_send_tlc_cmd(struct iwl_mld *mld, int iwl_mld_send_tlc_dhc(struct iwl_mld *mld, u8 sta_id, u32 type, u32 data) { struct { - struct iwl_dhc_cmd dhc; + struct iwl_dhc_cmd_hdr dhc; struct iwl_dhc_tlc_cmd tlc; } __packed cmd = { .tlc.sta_id = sta_id, -- 2.43.0