summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2026-09-28 19:38:32 +0200
committerJohannes Berg <johannes.berg@intel.com>2026-10-05 15:11:29 +0200
commit34f93ba0bc9f2bca0fde881b2267bc18bc9ac052 (patch)
treeb67192805094b488eba6ab262ca30ffe0463e646 /include
parentd160663ca2fadfa0ffbb674f8b3141c064c1d546 (diff)
wifi: ieee80211: type-check (extended) element functions
Type-check element finding functions and element iteration macros, so that when constants are given for the (extended) ID they must be from the appropriate enum, otherwise an enum compare compiler warning will trigger. Two places are using element iteration for subelements, but don't have the outer element as a struct element, so they need casts to avoid the warning now, but overall this will flag issues like the one in the previous commit. Link: https://patch.msgid.link/20260928193832.706fb927f309.I0f8702dc218b56470017d2fcf8fff2980946e818@changeid Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'include')
-rw-r--r--include/linux/ieee80211.h17
-rw-r--r--include/net/cfg80211.h17
2 files changed, 24 insertions, 10 deletions
diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index 73ac5336a17a..66f9ebe79c61 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -2730,6 +2730,10 @@ struct element {
u8 data[];
} __packed;
+/* trigger enum comparison warnings if applicable (constant id) */
+#define element_iteration_typecheck(type, id) \
+ (((type)0 == (id)) || true)
+
/* element iteration helpers */
#define for_each_element(_elem, _data, _datalen) \
for (_elem = (const struct element *)(_data); \
@@ -2741,11 +2745,15 @@ struct element {
#define for_each_element_id(element, _id, data, datalen) \
for_each_element(element, data, datalen) \
- if (element->id == (_id))
+ if (element_iteration_typecheck(enum ieee80211_eid, \
+ _id) && \
+ element->id == (_id))
#define for_each_element_extid(element, extid, _data, _datalen) \
for_each_element(element, _data, _datalen) \
- if (element->id == WLAN_EID_EXTENSION && \
+ if (element_iteration_typecheck(enum ieee80211_eid_ext, \
+ extid) && \
+ element->id == WLAN_EID_EXTENSION && \
element->datalen > 0 && \
element->data[0] == (extid))
@@ -2753,10 +2761,11 @@ struct element {
for_each_element(sub, (element)->data, (element)->datalen)
#define for_each_subelement_id(sub, id, element) \
- for_each_element_id(sub, id, (element)->data, (element)->datalen)
+ for_each_element_id(sub, (u8)id, (element)->data, (element)->datalen)
#define for_each_subelement_extid(sub, extid, element) \
- for_each_element_extid(sub, extid, (element)->data, (element)->datalen)
+ for_each_element_extid(sub, (u8)extid, (element)->data, \
+ (element)->datalen)
/**
* for_each_element_completed - determine if element parsing consumed all data
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index b603f1804cc2..2e3dfee85019 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -7858,7 +7858,8 @@ unsigned int cfg80211_classify8021d(struct sk_buff *skb,
* byte array to match.
*/
const struct element *
-cfg80211_find_elem_match(u8 eid, const u8 *ies, unsigned int len,
+cfg80211_find_elem_match(enum ieee80211_eid eid,
+ const u8 *ies, unsigned int len,
const u8 *match, unsigned int match_len,
unsigned int match_offset);
@@ -7887,7 +7888,7 @@ cfg80211_find_elem_match(u8 eid, const u8 *ies, unsigned int len,
* byte array to match.
*/
static inline const u8 *
-cfg80211_find_ie_match(u8 eid, const u8 *ies, unsigned int len,
+cfg80211_find_ie_match(enum ieee80211_eid eid, const u8 *ies, unsigned int len,
const u8 *match, unsigned int match_len,
unsigned int match_offset)
{
@@ -7920,7 +7921,7 @@ cfg80211_find_ie_match(u8 eid, const u8 *ies, unsigned int len,
* having to fit into the given data.
*/
static inline const struct element *
-cfg80211_find_elem(u8 eid, const u8 *ies, int len)
+cfg80211_find_elem(enum ieee80211_eid eid, const u8 *ies, int len)
{
return cfg80211_find_elem_match(eid, ies, len, NULL, 0, 0);
}
@@ -7940,7 +7941,8 @@ cfg80211_find_elem(u8 eid, const u8 *ies, int len)
* Note: There are no checks on the element length other than
* having to fit into the given data.
*/
-static inline const u8 *cfg80211_find_ie(u8 eid, const u8 *ies, int len)
+static inline const u8 *cfg80211_find_ie(enum ieee80211_eid eid,
+ const u8 *ies, int len)
{
return cfg80211_find_ie_match(eid, ies, len, NULL, 0, 0);
}
@@ -7961,10 +7963,13 @@ static inline const u8 *cfg80211_find_ie(u8 eid, const u8 *ies, int len)
* having to fit into the given data.
*/
static inline const struct element *
-cfg80211_find_ext_elem(u8 ext_eid, const u8 *ies, int len)
+cfg80211_find_ext_elem(enum ieee80211_eid_ext ext_eid,
+ const u8 *ies, int len)
{
+ u8 _ext_eid = ext_eid;
+
return cfg80211_find_elem_match(WLAN_EID_EXTENSION, ies, len,
- &ext_eid, 1, 0);
+ &_ext_eid, 1, 0);
}
/**