Commit 7388afe0 authored by Jouni Malinen's avatar Jouni Malinen Committed by Johannes Berg

cfg80211: Use const more consistently in for_each_element macros

Enforce the first argument to be a correct type of a pointer to struct
element and avoid unnecessary typecasts from const to non-const pointers
(the change in validate_ie_attr() is needed to make this part work). In
addition, avoid signed/unsigned comparison within for_each_element() and
mark struct element packed just in case.
Signed-off-by: default avatarJouni Malinen <j@w1.fi>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent e646a025
...@@ -3284,16 +3284,16 @@ struct element { ...@@ -3284,16 +3284,16 @@ struct element {
u8 id; u8 id;
u8 datalen; u8 datalen;
u8 data[]; u8 data[];
}; } __packed;
/* element iteration helpers */ /* element iteration helpers */
#define for_each_element(element, _data, _datalen) \ #define for_each_element(_elem, _data, _datalen) \
for (element = (void *)(_data); \ for (_elem = (const struct element *)(_data); \
(u8 *)(_data) + (_datalen) - (u8 *)element >= \ (const u8 *)(_data) + (_datalen) - (const u8 *)_elem >= \
sizeof(*element) && \ (int)sizeof(*_elem) && \
(u8 *)(_data) + (_datalen) - (u8 *)element >= \ (const u8 *)(_data) + (_datalen) - (const u8 *)_elem >= \
sizeof(*element) + element->datalen; \ (int)sizeof(*_elem) + _elem->datalen; \
element = (void *)(element->data + element->datalen)) _elem = (const struct element *)(_elem->data + _elem->datalen))
#define for_each_element_id(element, _id, data, datalen) \ #define for_each_element_id(element, _id, data, datalen) \
for_each_element(element, data, datalen) \ for_each_element(element, data, datalen) \
...@@ -3330,7 +3330,7 @@ struct element { ...@@ -3330,7 +3330,7 @@ struct element {
static inline bool for_each_element_completed(const struct element *element, static inline bool for_each_element_completed(const struct element *element,
const void *data, size_t datalen) const void *data, size_t datalen)
{ {
return (u8 *)element == (u8 *)data + datalen; return (const u8 *)element == (const u8 *)data + datalen;
} }
#endif /* LINUX_IEEE80211_H */ #endif /* LINUX_IEEE80211_H */
...@@ -205,7 +205,7 @@ static int validate_ie_attr(const struct nlattr *attr, ...@@ -205,7 +205,7 @@ static int validate_ie_attr(const struct nlattr *attr,
{ {
const u8 *data = nla_data(attr); const u8 *data = nla_data(attr);
unsigned int len = nla_len(attr); unsigned int len = nla_len(attr);
struct element *elem; const struct element *elem;
for_each_element(elem, data, len) { for_each_element(elem, data, len) {
/* nothing */ /* nothing */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment