Skip to content

Commit

Permalink
wifi: ipw2x00: libipw: Avoid -Wflex-array-member-not-at-end warnings
Browse files Browse the repository at this point in the history
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are
getting ready to enable it, globally.

So, in order to avoid ending up with a flexible-array member in the
middle of multiple other structs, we use the `__struct_group()`
helper to create a new tagged `struct libipw_hdr_3addr_hdr`.
This structure groups together all the members of the flexible
`struct libipw_hdr_3addr` except the flexible array.

As a result, the array is effectively separated from the rest of the
members without modifying the memory layout of the flexible structure.
We then change the type of the middle struct members currently causing
trouble from `struct libipw_hdr_3addr` to `struct libipw_hdr_3addr_hdr`.

We also want to ensure that when new members need to be added to the
flexible structure, they are always included within the newly created
tagged struct. For this, we use `static_assert()`. This ensures that the
memory layout for both the flexible structure and the new tagged struct
is the same after any changes.

This approach avoids having to implement `struct libipw_hdr_3addr_hdr`
as a completely separate structure, thus preventing having to maintain
two independent but basically identical structures, closing the door
to potential bugs in the future.

Also, remove a couple of unused structures `struct libipw_ibss_dfs` and
`struct libipw_assoc_request`.

So, with these changes, fix the following warnings:

drivers/net/wireless/intel/ipw2x00/libipw.h:403:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/net/wireless/intel/ipw2x00/libipw.h:420:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/net/wireless/intel/ipw2x00/libipw.h:433:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/net/wireless/intel/ipw2x00/libipw.h:441:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/net/wireless/intel/ipw2x00/libipw.h:447:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/net/wireless/intel/ipw2x00/libipw.h:460:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/net/wireless/intel/ipw2x00/libipw.h:468:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/net/wireless/intel/ipw2x00/libipw.h:476:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/net/wireless/intel/ipw2x00/libipw.h:592:36: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://patch.msgid.link/ZrJqtUpCI+uCeb4D@cute
  • Loading branch information
Gustavo A. R. Silva authored and Kalle Valo committed Aug 10, 2024
1 parent ca0107c commit 089332e
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions drivers/net/wireless/intel/ipw2x00/libipw.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,19 @@ struct libipw_hdr_2addr {
} __packed;

struct libipw_hdr_3addr {
__le16 frame_ctl;
__le16 duration_id;
u8 addr1[ETH_ALEN];
u8 addr2[ETH_ALEN];
u8 addr3[ETH_ALEN];
__le16 seq_ctl;
/* New members MUST be added within the __struct_group() macro below. */
__struct_group(libipw_hdr_3addr_hdr, hdr, __packed,
__le16 frame_ctl;
__le16 duration_id;
u8 addr1[ETH_ALEN];
u8 addr2[ETH_ALEN];
u8 addr3[ETH_ALEN];
__le16 seq_ctl;
);
u8 payload[];
} __packed;
static_assert(offsetof(struct libipw_hdr_3addr, payload) == sizeof(struct libipw_hdr_3addr_hdr),
"struct member likely outside of __struct_group()");

struct libipw_hdr_4addr {
__le16 frame_ctl;
Expand Down Expand Up @@ -400,7 +405,7 @@ struct libipw_info_element {
*/

struct libipw_auth {
struct libipw_hdr_3addr header;
struct libipw_hdr_3addr_hdr header;
__le16 algorithm;
__le16 transaction;
__le16 status;
Expand All @@ -417,7 +422,7 @@ struct libipw_channel_switch {
} __packed;

struct libipw_action {
struct libipw_hdr_3addr header;
struct libipw_hdr_3addr_hdr header;
u8 category;
u8 action;
union {
Expand All @@ -430,21 +435,21 @@ struct libipw_action {
} __packed;

struct libipw_disassoc {
struct libipw_hdr_3addr header;
struct libipw_hdr_3addr_hdr header;
__le16 reason;
} __packed;

/* Alias deauth for disassoc */
#define libipw_deauth libipw_disassoc

struct libipw_probe_request {
struct libipw_hdr_3addr header;
struct libipw_hdr_3addr_hdr header;
/* SSID, supported rates */
u8 variable[];
} __packed;

struct libipw_probe_response {
struct libipw_hdr_3addr header;
struct libipw_hdr_3addr_hdr header;
__le32 time_stamp[2];
__le16 beacon_interval;
__le16 capability;
Expand All @@ -456,24 +461,16 @@ struct libipw_probe_response {
/* Alias beacon for probe_response */
#define libipw_beacon libipw_probe_response

struct libipw_assoc_request {
struct libipw_hdr_3addr header;
__le16 capability;
__le16 listen_interval;
/* SSID, supported rates, RSN */
u8 variable[];
} __packed;

struct libipw_reassoc_request {
struct libipw_hdr_3addr header;
struct libipw_hdr_3addr_hdr header;
__le16 capability;
__le16 listen_interval;
u8 current_ap[ETH_ALEN];
u8 variable[];
} __packed;

struct libipw_assoc_response {
struct libipw_hdr_3addr header;
struct libipw_hdr_3addr_hdr header;
__le16 capability;
__le16 status;
__le16 aid;
Expand Down Expand Up @@ -588,13 +585,6 @@ struct libipw_channel_map {
u8 map;
} __packed;

struct libipw_ibss_dfs {
struct libipw_info_element ie;
u8 owner[ETH_ALEN];
u8 recovery_interval;
struct libipw_channel_map channel_map[];
};

struct libipw_csa {
u8 mode;
u8 channel;
Expand Down

0 comments on commit 089332e

Please sign in to comment.