hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
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 /*
....@@ -1707,7 +1689,7 @@
17071689 int len, ret, max_pmkids;
17081690
17091691 max_pmkids = priv->wdev.wiphy->max_num_pmkids;
1710
- len = sizeof(*pmkids) + max_pmkids * sizeof(pmkids->bssid_info[0]);
1692
+ len = struct_size(pmkids, bssid_info, max_pmkids);
17111693
17121694 pmkids = kzalloc(len, GFP_KERNEL);
17131695 if (!pmkids)
....@@ -1740,7 +1722,7 @@
17401722 int ret, len, num_pmkids;
17411723
17421724 num_pmkids = le32_to_cpu(pmkids->bssid_info_count);
1743
- len = sizeof(*pmkids) + num_pmkids * sizeof(pmkids->bssid_info[0]);
1725
+ len = struct_size(pmkids, bssid_info, num_pmkids);
17441726 pmkids->length = cpu_to_le32(len);
17451727
17461728 debug_print_pmkids(usbdev, pmkids, __func__);
....@@ -1761,7 +1743,7 @@
17611743 struct cfg80211_pmksa *pmksa,
17621744 int max_pmkids)
17631745 {
1764
- int i, newlen, err;
1746
+ int i, err;
17651747 unsigned int count;
17661748
17671749 count = le32_to_cpu(pmkids->bssid_info_count);
....@@ -1786,9 +1768,7 @@
17861768 pmkids->bssid_info[i] = pmkids->bssid_info[i + 1];
17871769
17881770 count--;
1789
- newlen = sizeof(*pmkids) + count * sizeof(pmkids->bssid_info[0]);
1790
-
1791
- pmkids->length = cpu_to_le32(newlen);
1771
+ pmkids->length = cpu_to_le32(struct_size(pmkids, bssid_info, count));
17921772 pmkids->bssid_info_count = cpu_to_le32(count);
17931773
17941774 return pmkids;
....@@ -1831,7 +1811,7 @@
18311811 }
18321812
18331813 /* add new pmkid */
1834
- newlen = sizeof(*pmkids) + (count + 1) * sizeof(pmkids->bssid_info[0]);
1814
+ newlen = struct_size(pmkids, bssid_info, count + 1);
18351815
18361816 new_pmkids = krealloc(pmkids, newlen, GFP_KERNEL);
18371817 if (!new_pmkids) {
....@@ -3123,8 +3103,7 @@
31233103 __le32 num_items;
31243104 __le32 items[8];
31253105 } networks_supported;
3126
- struct ndis_80211_capability *caps;
3127
- u8 caps_buf[sizeof(*caps) + sizeof(caps->auth_encr_pair) * 16];
3106
+ struct ndis_80211_capability caps;
31283107 int len, retval, i, n;
31293108 struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
31303109
....@@ -3133,7 +3112,7 @@
31333112 retval = rndis_query_oid(usbdev,
31343113 RNDIS_OID_802_11_NETWORK_TYPES_SUPPORTED,
31353114 &networks_supported, &len);
3136
- if (retval >= 0) {
3115
+ if (!retval) {
31373116 n = le32_to_cpu(networks_supported.num_items);
31383117 if (n > 8)
31393118 n = 8;
....@@ -3154,19 +3133,18 @@
31543133 }
31553134
31563135 /* get device 802.11 capabilities, number of PMKIDs */
3157
- caps = (struct ndis_80211_capability *)caps_buf;
3158
- len = sizeof(caps_buf);
3136
+ len = sizeof(caps);
31593137 retval = rndis_query_oid(usbdev,
31603138 RNDIS_OID_802_11_CAPABILITY,
3161
- caps, &len);
3162
- if (retval >= 0) {
3139
+ &caps, &len);
3140
+ if (!retval) {
31633141 netdev_dbg(usbdev->net, "RNDIS_OID_802_11_CAPABILITY -> len %d, "
31643142 "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);
3143
+ le32_to_cpu(caps.length),
3144
+ le32_to_cpu(caps.version),
3145
+ le32_to_cpu(caps.num_pmkids),
3146
+ le32_to_cpu(caps.num_auth_encr_pair));
3147
+ wiphy->max_num_pmkids = le32_to_cpu(caps.num_pmkids);
31703148 } else
31713149 wiphy->max_num_pmkids = 0;
31723150