| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Driver for RNDIS based wireless USB devices. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2007 by Bjorge Dijkstra <bjd@jooz.net> |
|---|
| 5 | 6 | * 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/>. |
|---|
| 19 | 7 | * |
|---|
| 20 | 8 | * Portions of this file are based on NDISwrapper project, |
|---|
| 21 | 9 | * Copyright (C) 2003-2005 Pontus Fuchs, Giridhar Pemmasani |
|---|
| .. | .. |
|---|
| 213 | 201 | struct ndis_80211_pmkid_cand_list { |
|---|
| 214 | 202 | __le32 version; |
|---|
| 215 | 203 | __le32 num_candidates; |
|---|
| 216 | | - struct ndis_80211_pmkid_candidate candidate_list[0]; |
|---|
| 204 | + struct ndis_80211_pmkid_candidate candidate_list[]; |
|---|
| 217 | 205 | } __packed; |
|---|
| 218 | 206 | |
|---|
| 219 | 207 | struct ndis_80211_status_indication { |
|---|
| .. | .. |
|---|
| 258 | 246 | __le32 net_infra; |
|---|
| 259 | 247 | u8 rates[NDIS_802_11_LENGTH_RATES_EX]; |
|---|
| 260 | 248 | __le32 ie_length; |
|---|
| 261 | | - u8 ies[0]; |
|---|
| 249 | + u8 ies[]; |
|---|
| 262 | 250 | } __packed; |
|---|
| 263 | 251 | |
|---|
| 264 | 252 | struct ndis_80211_bssid_list_ex { |
|---|
| 265 | 253 | __le32 num_items; |
|---|
| 266 | | - struct ndis_80211_bssid_ex bssid[0]; |
|---|
| 254 | + struct ndis_80211_bssid_ex bssid[]; |
|---|
| 267 | 255 | } __packed; |
|---|
| 268 | 256 | |
|---|
| 269 | 257 | struct ndis_80211_fixed_ies { |
|---|
| .. | .. |
|---|
| 324 | 312 | __le32 offset_resp_ies; |
|---|
| 325 | 313 | } __packed; |
|---|
| 326 | 314 | |
|---|
| 327 | | -struct ndis_80211_auth_encr_pair { |
|---|
| 328 | | - __le32 auth_mode; |
|---|
| 329 | | - __le32 encr_mode; |
|---|
| 330 | | -} __packed; |
|---|
| 331 | | - |
|---|
| 332 | 315 | struct ndis_80211_capability { |
|---|
| 333 | 316 | __le32 length; |
|---|
| 334 | 317 | __le32 version; |
|---|
| 335 | 318 | __le32 num_pmkids; |
|---|
| 336 | 319 | __le32 num_auth_encr_pair; |
|---|
| 337 | | - struct ndis_80211_auth_encr_pair auth_encr_pair[0]; |
|---|
| 338 | 320 | } __packed; |
|---|
| 339 | 321 | |
|---|
| 340 | 322 | struct ndis_80211_bssid_info { |
|---|
| .. | .. |
|---|
| 345 | 327 | struct ndis_80211_pmkid { |
|---|
| 346 | 328 | __le32 length; |
|---|
| 347 | 329 | __le32 bssid_info_count; |
|---|
| 348 | | - struct ndis_80211_bssid_info bssid_info[0]; |
|---|
| 330 | + struct ndis_80211_bssid_info bssid_info[]; |
|---|
| 349 | 331 | } __packed; |
|---|
| 350 | 332 | |
|---|
| 351 | 333 | /* |
|---|
| .. | .. |
|---|
| 1707 | 1689 | int len, ret, max_pmkids; |
|---|
| 1708 | 1690 | |
|---|
| 1709 | 1691 | 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); |
|---|
| 1711 | 1693 | |
|---|
| 1712 | 1694 | pmkids = kzalloc(len, GFP_KERNEL); |
|---|
| 1713 | 1695 | if (!pmkids) |
|---|
| .. | .. |
|---|
| 1740 | 1722 | int ret, len, num_pmkids; |
|---|
| 1741 | 1723 | |
|---|
| 1742 | 1724 | 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); |
|---|
| 1744 | 1726 | pmkids->length = cpu_to_le32(len); |
|---|
| 1745 | 1727 | |
|---|
| 1746 | 1728 | debug_print_pmkids(usbdev, pmkids, __func__); |
|---|
| .. | .. |
|---|
| 1761 | 1743 | struct cfg80211_pmksa *pmksa, |
|---|
| 1762 | 1744 | int max_pmkids) |
|---|
| 1763 | 1745 | { |
|---|
| 1764 | | - int i, newlen, err; |
|---|
| 1746 | + int i, err; |
|---|
| 1765 | 1747 | unsigned int count; |
|---|
| 1766 | 1748 | |
|---|
| 1767 | 1749 | count = le32_to_cpu(pmkids->bssid_info_count); |
|---|
| .. | .. |
|---|
| 1786 | 1768 | pmkids->bssid_info[i] = pmkids->bssid_info[i + 1]; |
|---|
| 1787 | 1769 | |
|---|
| 1788 | 1770 | 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)); |
|---|
| 1792 | 1772 | pmkids->bssid_info_count = cpu_to_le32(count); |
|---|
| 1793 | 1773 | |
|---|
| 1794 | 1774 | return pmkids; |
|---|
| .. | .. |
|---|
| 1831 | 1811 | } |
|---|
| 1832 | 1812 | |
|---|
| 1833 | 1813 | /* add new pmkid */ |
|---|
| 1834 | | - newlen = sizeof(*pmkids) + (count + 1) * sizeof(pmkids->bssid_info[0]); |
|---|
| 1814 | + newlen = struct_size(pmkids, bssid_info, count + 1); |
|---|
| 1835 | 1815 | |
|---|
| 1836 | 1816 | new_pmkids = krealloc(pmkids, newlen, GFP_KERNEL); |
|---|
| 1837 | 1817 | if (!new_pmkids) { |
|---|
| .. | .. |
|---|
| 3123 | 3103 | __le32 num_items; |
|---|
| 3124 | 3104 | __le32 items[8]; |
|---|
| 3125 | 3105 | } 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; |
|---|
| 3128 | 3107 | int len, retval, i, n; |
|---|
| 3129 | 3108 | struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev); |
|---|
| 3130 | 3109 | |
|---|
| .. | .. |
|---|
| 3133 | 3112 | retval = rndis_query_oid(usbdev, |
|---|
| 3134 | 3113 | RNDIS_OID_802_11_NETWORK_TYPES_SUPPORTED, |
|---|
| 3135 | 3114 | &networks_supported, &len); |
|---|
| 3136 | | - if (retval >= 0) { |
|---|
| 3115 | + if (!retval) { |
|---|
| 3137 | 3116 | n = le32_to_cpu(networks_supported.num_items); |
|---|
| 3138 | 3117 | if (n > 8) |
|---|
| 3139 | 3118 | n = 8; |
|---|
| .. | .. |
|---|
| 3154 | 3133 | } |
|---|
| 3155 | 3134 | |
|---|
| 3156 | 3135 | /* 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); |
|---|
| 3159 | 3137 | retval = rndis_query_oid(usbdev, |
|---|
| 3160 | 3138 | RNDIS_OID_802_11_CAPABILITY, |
|---|
| 3161 | | - caps, &len); |
|---|
| 3162 | | - if (retval >= 0) { |
|---|
| 3139 | + &caps, &len); |
|---|
| 3140 | + if (!retval) { |
|---|
| 3163 | 3141 | netdev_dbg(usbdev->net, "RNDIS_OID_802_11_CAPABILITY -> len %d, " |
|---|
| 3164 | 3142 | "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); |
|---|
| 3170 | 3148 | } else |
|---|
| 3171 | 3149 | wiphy->max_num_pmkids = 0; |
|---|
| 3172 | 3150 | |
|---|