Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

wifi: mac80211: 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.

Use the `DEFINE_RAW_FLEX()` helper for on-stack definitions of
a flexible structure where the size of the flexible-array member
is known at compile-time, and refactor the rest of the code,
accordingly.

So, with these changes, fix the following warnings:

net/mac80211/spectmgmt.c:151:47: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
net/mac80211/spectmgmt.c:155:48: 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>
Reviewed-by: Kees Cook <kees@kernel.org>
Link: https://patch.msgid.link/Z-SQdHZljwAgIlp9@kspp
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

authored by

Gustavo A. R. Silva and committed by
Johannes Berg
17328a5b 98fd01b4

+27 -28
+27 -28
net/mac80211/spectmgmt.c
··· 147 147 struct ieee80211_local *local = sdata->local; 148 148 u32 control_freq, center_freq1, center_freq2; 149 149 enum nl80211_chan_width chan_width; 150 - struct { 151 - struct ieee80211_he_operation _oper; 152 - struct ieee80211_he_6ghz_oper _6ghz_oper; 153 - } __packed he; 154 - struct { 155 - struct ieee80211_eht_operation _oper; 156 - struct ieee80211_eht_operation_info _oper_info; 157 - } __packed eht; 150 + DEFINE_RAW_FLEX(struct ieee80211_he_operation, he, optional, 151 + sizeof(struct ieee80211_he_6ghz_oper)); 152 + struct ieee80211_he_6ghz_oper *_6ghz_oper = 153 + (struct ieee80211_he_6ghz_oper *)he->optional; 154 + DEFINE_RAW_FLEX(struct ieee80211_eht_operation, eht, optional, 155 + sizeof(struct ieee80211_eht_operation_info)); 156 + struct ieee80211_eht_operation_info *_oper_info = 157 + (struct ieee80211_eht_operation_info *)eht->optional; 158 158 const struct ieee80211_eht_operation *eht_oper; 159 159 160 160 if (conn->mode < IEEE80211_CONN_MODE_HE) { ··· 167 167 center_freq2 = chandef->center_freq2; 168 168 chan_width = chandef->width; 169 169 170 - he._oper.he_oper_params = 170 + he->he_oper_params = 171 171 le32_encode_bits(1, IEEE80211_HE_OPERATION_6GHZ_OP_INFO); 172 - he._6ghz_oper.primary = 172 + _6ghz_oper->primary = 173 173 ieee80211_frequency_to_channel(control_freq); 174 - he._6ghz_oper.ccfs0 = ieee80211_frequency_to_channel(center_freq1); 175 - he._6ghz_oper.ccfs1 = center_freq2 ? 174 + _6ghz_oper->ccfs0 = ieee80211_frequency_to_channel(center_freq1); 175 + _6ghz_oper->ccfs1 = center_freq2 ? 176 176 ieee80211_frequency_to_channel(center_freq2) : 0; 177 177 178 178 switch (chan_width) { 179 179 case NL80211_CHAN_WIDTH_320: 180 - he._6ghz_oper.ccfs1 = he._6ghz_oper.ccfs0; 181 - he._6ghz_oper.ccfs0 += control_freq < center_freq1 ? -16 : 16; 182 - he._6ghz_oper.control = IEEE80211_EHT_OPER_CHAN_WIDTH_320MHZ; 180 + _6ghz_oper->ccfs1 = _6ghz_oper->ccfs0; 181 + _6ghz_oper->ccfs0 += control_freq < center_freq1 ? -16 : 16; 182 + _6ghz_oper->control = IEEE80211_EHT_OPER_CHAN_WIDTH_320MHZ; 183 183 break; 184 184 case NL80211_CHAN_WIDTH_160: 185 - he._6ghz_oper.ccfs1 = he._6ghz_oper.ccfs0; 186 - he._6ghz_oper.ccfs0 += control_freq < center_freq1 ? -8 : 8; 185 + _6ghz_oper->ccfs1 = _6ghz_oper->ccfs0; 186 + _6ghz_oper->ccfs0 += control_freq < center_freq1 ? -8 : 8; 187 187 fallthrough; 188 188 case NL80211_CHAN_WIDTH_80P80: 189 - he._6ghz_oper.control = 189 + _6ghz_oper->control = 190 190 IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_160MHZ; 191 191 break; 192 192 case NL80211_CHAN_WIDTH_80: 193 - he._6ghz_oper.control = 193 + _6ghz_oper->control = 194 194 IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_80MHZ; 195 195 break; 196 196 case NL80211_CHAN_WIDTH_40: 197 - he._6ghz_oper.control = 197 + _6ghz_oper->control = 198 198 IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_40MHZ; 199 199 break; 200 200 default: 201 - he._6ghz_oper.control = 201 + _6ghz_oper->control = 202 202 IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_20MHZ; 203 203 break; 204 204 } ··· 206 206 if (conn->mode < IEEE80211_CONN_MODE_EHT) { 207 207 eht_oper = NULL; 208 208 } else { 209 - eht._oper.params = IEEE80211_EHT_OPER_INFO_PRESENT; 210 - eht._oper_info.control = he._6ghz_oper.control; 211 - eht._oper_info.ccfs0 = he._6ghz_oper.ccfs0; 212 - eht._oper_info.ccfs1 = he._6ghz_oper.ccfs1; 213 - eht_oper = &eht._oper; 209 + eht->params = IEEE80211_EHT_OPER_INFO_PRESENT; 210 + _oper_info->control = _6ghz_oper->control; 211 + _oper_info->ccfs0 = _6ghz_oper->ccfs0; 212 + _oper_info->ccfs1 = _6ghz_oper->ccfs1; 213 + eht_oper = eht; 214 214 } 215 215 216 - if (!ieee80211_chandef_he_6ghz_oper(local, &he._oper, 217 - eht_oper, chandef)) 216 + if (!ieee80211_chandef_he_6ghz_oper(local, he, eht_oper, chandef)) 218 217 chandef->chan = NULL; 219 218 } 220 219