]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
mac80211: use element iteration macro in parsing
authorJohannes Berg <johannes.berg@intel.com>
Thu, 7 Feb 2019 21:18:19 +0000 (22:18 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Fri, 8 Feb 2019 12:51:50 +0000 (13:51 +0100)
Instead of open-coding the element walk, use the new macro.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/mac80211/util.c

index d0eb38b890aa65934d752e547190624132cc31a9..7fa9ba197c260c671053967e49583aa86e28a9f9 100644 (file)
@@ -895,8 +895,7 @@ u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
                               struct ieee802_11_elems *elems,
                               u64 filter, u32 crc)
 {
-       size_t left = len;
-       const u8 *pos = start;
+       struct element *elem;
        bool calc_crc = filter != 0;
        DECLARE_BITMAP(seen_elems, 256);
        const u8 *ie;
@@ -906,18 +905,11 @@ u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
        elems->ie_start = start;
        elems->total_len = len;
 
-       while (left >= 2) {
-               u8 id, elen;
+       for_each_element(elem, start, len) {
                bool elem_parse_failed;
-
-               id = *pos++;
-               elen = *pos++;
-               left -= 2;
-
-               if (elen > left) {
-                       elems->parse_error = true;
-                       break;
-               }
+               u8 id = elem->id;
+               u8 elen = elem->datalen;
+               const u8 *pos = elem->data;
 
                switch (id) {
                case WLAN_EID_SSID:
@@ -960,8 +952,6 @@ u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
                 */
                        if (test_bit(id, seen_elems)) {
                                elems->parse_error = true;
-                               left -= elen;
-                               pos += elen;
                                continue;
                        }
                        break;
@@ -1244,12 +1234,9 @@ u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
                        elems->parse_error = true;
                else
                        __set_bit(id, seen_elems);
-
-               left -= elen;
-               pos += elen;
        }
 
-       if (left != 0)
+       if (!for_each_element_completed(elem, start, len))
                elems->parse_error = true;
 
        return crc;