hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/net/wireless/rndis_wlan.c
....@@ -1,21 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Driver for RNDIS based wireless USB devices.
34 *
45 * Copyright (C) 2007 by Bjorge Dijkstra <bjd@jooz.net>
56 * Copyright (C) 2008-2009 by Jussi Kivilinna <jussi.kivilinna@iki.fi>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
197 *
208 * Portions of this file are based on NDISwrapper project,
219 * Copyright (C) 2003-2005 Pontus Fuchs, Giridhar Pemmasani
....@@ -213,7 +201,7 @@
213201 struct ndis_80211_pmkid_cand_list {
214202 __le32 version;
215203 __le32 num_candidates;
216
- struct ndis_80211_pmkid_candidate candidate_list[0];
204
+ struct ndis_80211_pmkid_candidate candidate_list[];
217205 } __packed;
218206
219207 struct ndis_80211_status_indication {
....@@ -258,12 +246,12 @@
258246 __le32 net_infra;
259247 u8 rates[NDIS_802_11_LENGTH_RATES_EX];
260248 __le32 ie_length;
261
- u8 ies[0];
249
+ u8 ies[];
262250 } __packed;
263251
264252 struct ndis_80211_bssid_list_ex {
265253 __le32 num_items;
266
- struct ndis_80211_bssid_ex bssid[0];
254
+ struct ndis_80211_bssid_ex bssid[];
267255 } __packed;
268256
269257 struct ndis_80211_fixed_ies {
....@@ -324,17 +312,11 @@
324312 __le32 offset_resp_ies;
325313 } __packed;
326314
327
-struct ndis_80211_auth_encr_pair {
328
- __le32 auth_mode;
329
- __le32 encr_mode;
330
-} __packed;
331
-
332315 struct ndis_80211_capability {
333316 __le32 length;
334317 __le32 version;
335318 __le32 num_pmkids;
336319 __le32 num_auth_encr_pair;
337
- struct ndis_80211_auth_encr_pair auth_encr_pair[0];
338320 } __packed;
339321
340322 struct ndis_80211_bssid_info {
....@@ -345,7 +327,7 @@
345327 struct ndis_80211_pmkid {
346328 __le32 length;
347329 __le32 bssid_info_count;
348
- struct ndis_80211_bssid_info bssid_info[0];
330
+ struct ndis_80211_bssid_info bssid_info[];
349331 } __packed;
350332
351333 /*
....@@ -712,8 +694,8 @@
712694 struct rndis_query *get;
713695 struct rndis_query_c *get_c;
714696 } u;
715
- int ret, buflen;
716
- int resplen, respoffs, copylen;
697
+ int ret;
698
+ size_t buflen, resplen, respoffs, copylen;
717699
718700 buflen = *len + sizeof(*u.get);
719701 if (buflen < CONTROL_BUFFER_SIZE)
....@@ -748,22 +730,15 @@
748730
749731 if (respoffs > buflen) {
750732 /* Device returned data offset outside buffer, error. */
751
- netdev_dbg(dev->net, "%s(%s): received invalid "
752
- "data offset: %d > %d\n", __func__,
753
- oid_to_string(oid), respoffs, buflen);
733
+ netdev_dbg(dev->net,
734
+ "%s(%s): received invalid data offset: %zu > %zu\n",
735
+ __func__, oid_to_string(oid), respoffs, buflen);
754736
755737 ret = -EINVAL;
756738 goto exit_unlock;
757739 }
758740
759
- if ((resplen + respoffs) > buflen) {
760
- /* Device would have returned more data if buffer would
761
- * have been big enough. Copy just the bits that we got.
762
- */
763
- copylen = buflen - respoffs;
764
- } else {
765
- copylen = resplen;
766
- }
741
+ copylen = min(resplen, buflen - respoffs);
767742
768743 if (copylen > *len)
769744 copylen = *len;
....@@ -1707,7 +1682,7 @@
17071682 int len, ret, max_pmkids;
17081683
17091684 max_pmkids = priv->wdev.wiphy->max_num_pmkids;
1710
- len = sizeof(*pmkids) + max_pmkids * sizeof(pmkids->bssid_info[0]);
1685
+ len = struct_size(pmkids, bssid_info, max_pmkids);
17111686
17121687 pmkids = kzalloc(len, GFP_KERNEL);
17131688 if (!pmkids)
....@@ -1740,7 +1715,7 @@
17401715 int ret, len, num_pmkids;
17411716
17421717 num_pmkids = le32_to_cpu(pmkids->bssid_info_count);
1743
- len = sizeof(*pmkids) + num_pmkids * sizeof(pmkids->bssid_info[0]);
1718
+ len = struct_size(pmkids, bssid_info, num_pmkids);
17441719 pmkids->length = cpu_to_le32(len);
17451720
17461721 debug_print_pmkids(usbdev, pmkids, __func__);
....@@ -1761,7 +1736,7 @@
17611736 struct cfg80211_pmksa *pmksa,
17621737 int max_pmkids)
17631738 {
1764
- int i, newlen, err;
1739
+ int i, err;
17651740 unsigned int count;
17661741
17671742 count = le32_to_cpu(pmkids->bssid_info_count);
....@@ -1786,9 +1761,7 @@
17861761 pmkids->bssid_info[i] = pmkids->bssid_info[i + 1];
17871762
17881763 count--;
1789
- newlen = sizeof(*pmkids) + count * sizeof(pmkids->bssid_info[0]);
1790
-
1791
- pmkids->length = cpu_to_le32(newlen);
1764
+ pmkids->length = cpu_to_le32(struct_size(pmkids, bssid_info, count));
17921765 pmkids->bssid_info_count = cpu_to_le32(count);
17931766
17941767 return pmkids;
....@@ -1831,7 +1804,7 @@
18311804 }
18321805
18331806 /* add new pmkid */
1834
- newlen = sizeof(*pmkids) + (count + 1) * sizeof(pmkids->bssid_info[0]);
1807
+ newlen = struct_size(pmkids, bssid_info, count + 1);
18351808
18361809 new_pmkids = krealloc(pmkids, newlen, GFP_KERNEL);
18371810 if (!new_pmkids) {
....@@ -3123,8 +3096,7 @@
31233096 __le32 num_items;
31243097 __le32 items[8];
31253098 } networks_supported;
3126
- struct ndis_80211_capability *caps;
3127
- u8 caps_buf[sizeof(*caps) + sizeof(caps->auth_encr_pair) * 16];
3099
+ struct ndis_80211_capability caps;
31283100 int len, retval, i, n;
31293101 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
31303102
....@@ -3133,7 +3105,7 @@
31333105 retval = rndis_query_oid(usbdev,
31343106 RNDIS_OID_802_11_NETWORK_TYPES_SUPPORTED,
31353107 &networks_supported, &len);
3136
- if (retval >= 0) {
3108
+ if (!retval) {
31373109 n = le32_to_cpu(networks_supported.num_items);
31383110 if (n > 8)
31393111 n = 8;
....@@ -3154,19 +3126,18 @@
31543126 }
31553127
31563128 /* get device 802.11 capabilities, number of PMKIDs */
3157
- caps = (struct ndis_80211_capability *)caps_buf;
3158
- len = sizeof(caps_buf);
3129
+ len = sizeof(caps);
31593130 retval = rndis_query_oid(usbdev,
31603131 RNDIS_OID_802_11_CAPABILITY,
3161
- caps, &len);
3162
- if (retval >= 0) {
3132
+ &caps, &len);
3133
+ if (!retval) {
31633134 netdev_dbg(usbdev->net, "RNDIS_OID_802_11_CAPABILITY -> len %d, "
31643135 "ver %d, pmkids %d, auth-encr-pairs %d\n",
3165
- le32_to_cpu(caps->length),
3166
- le32_to_cpu(caps->version),
3167
- le32_to_cpu(caps->num_pmkids),
3168
- le32_to_cpu(caps->num_auth_encr_pair));
3169
- wiphy->max_num_pmkids = le32_to_cpu(caps->num_pmkids);
3136
+ le32_to_cpu(caps.length),
3137
+ le32_to_cpu(caps.version),
3138
+ le32_to_cpu(caps.num_pmkids),
3139
+ le32_to_cpu(caps.num_auth_encr_pair));
3140
+ wiphy->max_num_pmkids = le32_to_cpu(caps.num_pmkids);
31703141 } else
31713142 wiphy->max_num_pmkids = 0;
31723143