Skip to content

Commit 57be3d3

Browse files
GustavoARSilvajmberg-intel
authored andcommitted
wifi: radiotap: Avoid -Wflex-array-member-not-at-end warnings
-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 ieee80211_radiotap_header_fixed`. This structure groups together all the members of the flexible `struct ieee80211_radiotap_header` 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 ieee80211_radiotap_header` to `struct ieee80211_radiotap_header_fixed`. We also want to ensure that in case 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 ieee80211_radiotap_header_fixed` 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. So, with these changes, fix the following warnings: drivers/net/wireless/ath/wil6210/txrx.c:309:50: 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/ipw2100.c:2521:50: 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/ipw2200.h:1146:42: 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:595:36: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/net/wireless/marvell/libertas/radiotap.h:34:42: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/net/wireless/marvell/libertas/radiotap.h:5:42: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/net/wireless/microchip/wilc1000/mon.c:10:42: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/net/wireless/microchip/wilc1000/mon.c:15:42: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/net/wireless/virtual/mac80211_hwsim.c:758:42: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/net/wireless/virtual/mac80211_hwsim.c:767:42: 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 <[email protected]> Link: https://patch.msgid.link/ZwBMtBZKcrzwU7l4@kspp Signed-off-by: Johannes Berg <[email protected]>
1 parent 393b6bc commit 57be3d3

File tree

7 files changed

+33
-28
lines changed

7 files changed

+33
-28
lines changed

drivers/net/wireless/ath/wil6210/txrx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static void wil_rx_add_radiotap_header(struct wil6210_priv *wil,
306306
struct sk_buff *skb)
307307
{
308308
struct wil6210_rtap {
309-
struct ieee80211_radiotap_header rthdr;
309+
struct ieee80211_radiotap_header_fixed rthdr;
310310
/* fields should be in the order of bits in rthdr.it_present */
311311
/* flags */
312312
u8 flags;

drivers/net/wireless/intel/ipw2x00/ipw2100.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2518,7 +2518,7 @@ static void isr_rx_monitor(struct ipw2100_priv *priv, int i,
25182518
* to build this manually element by element, we can write it much
25192519
* more efficiently than we can parse it. ORDER MATTERS HERE */
25202520
struct ipw_rt_hdr {
2521-
struct ieee80211_radiotap_header rt_hdr;
2521+
struct ieee80211_radiotap_header_fixed rt_hdr;
25222522
s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
25232523
} *ipw_rt;
25242524

drivers/net/wireless/intel/ipw2x00/ipw2200.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ struct ipw_prom_priv {
11431143
* structure is provided regardless of any bits unset.
11441144
*/
11451145
struct ipw_rt_hdr {
1146-
struct ieee80211_radiotap_header rt_hdr;
1146+
struct ieee80211_radiotap_header_fixed rt_hdr;
11471147
u64 rt_tsf; /* TSF */ /* XXX */
11481148
u8 rt_flags; /* radiotap packet flags */
11491149
u8 rt_rate; /* rate in 500kb/s */

drivers/net/wireless/marvell/libertas/radiotap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <net/ieee80211_radiotap.h>
33

44
struct tx_radiotap_hdr {
5-
struct ieee80211_radiotap_header hdr;
5+
struct ieee80211_radiotap_header_fixed hdr;
66
u8 rate;
77
u8 txpower;
88
u8 rts_retries;
@@ -31,7 +31,7 @@ struct tx_radiotap_hdr {
3131
#define IEEE80211_FC_DSTODS 0x0300
3232

3333
struct rx_radiotap_hdr {
34-
struct ieee80211_radiotap_header hdr;
34+
struct ieee80211_radiotap_header_fixed hdr;
3535
u8 flags;
3636
u8 rate;
3737
u8 antsignal;

drivers/net/wireless/microchip/wilc1000/mon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
#include "cfg80211.h"
88

99
struct wilc_wfi_radiotap_hdr {
10-
struct ieee80211_radiotap_header hdr;
10+
struct ieee80211_radiotap_header_fixed hdr;
1111
u8 rate;
1212
} __packed;
1313

1414
struct wilc_wfi_radiotap_cb_hdr {
15-
struct ieee80211_radiotap_header hdr;
15+
struct ieee80211_radiotap_header_fixed hdr;
1616
u8 rate;
1717
u8 dump;
1818
u16 tx_flags;

drivers/net/wireless/virtual/mac80211_hwsim.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ static const struct rhashtable_params hwsim_rht_params = {
763763
};
764764

765765
struct hwsim_radiotap_hdr {
766-
struct ieee80211_radiotap_header hdr;
766+
struct ieee80211_radiotap_header_fixed hdr;
767767
__le64 rt_tsft;
768768
u8 rt_flags;
769769
u8 rt_rate;
@@ -772,7 +772,7 @@ struct hwsim_radiotap_hdr {
772772
} __packed;
773773

774774
struct hwsim_radiotap_ack_hdr {
775-
struct ieee80211_radiotap_header hdr;
775+
struct ieee80211_radiotap_header_fixed hdr;
776776
u8 rt_flags;
777777
u8 pad;
778778
__le16 rt_channel;

include/net/ieee80211_radiotap.h

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,37 @@
2424
* struct ieee80211_radiotap_header - base radiotap header
2525
*/
2626
struct ieee80211_radiotap_header {
27-
/**
28-
* @it_version: radiotap version, always 0
29-
*/
30-
uint8_t it_version;
31-
32-
/**
33-
* @it_pad: padding (or alignment)
34-
*/
35-
uint8_t it_pad;
36-
37-
/**
38-
* @it_len: overall radiotap header length
39-
*/
40-
__le16 it_len;
41-
42-
/**
43-
* @it_present: (first) present word
44-
*/
45-
__le32 it_present;
27+
__struct_group(ieee80211_radiotap_header_fixed, hdr, __packed,
28+
/**
29+
* @it_version: radiotap version, always 0
30+
*/
31+
uint8_t it_version;
32+
33+
/**
34+
* @it_pad: padding (or alignment)
35+
*/
36+
uint8_t it_pad;
37+
38+
/**
39+
* @it_len: overall radiotap header length
40+
*/
41+
__le16 it_len;
42+
43+
/**
44+
* @it_present: (first) present word
45+
*/
46+
__le32 it_present;
47+
);
4648

4749
/**
4850
* @it_optional: all remaining presence bitmaps
4951
*/
5052
__le32 it_optional[];
5153
} __packed;
5254

55+
static_assert(offsetof(struct ieee80211_radiotap_header, it_optional) == sizeof(struct ieee80211_radiotap_header_fixed),
56+
"struct member likely outside of __struct_group()");
57+
5358
/* version is always 0 */
5459
#define PKTHDR_RADIOTAP_VERSION 0
5560

0 commit comments

Comments
 (0)