Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cfg80211: Add a function to get the number of supported channels

Add a utility function to get the number of channels supported by
the device, and update the places in the code that need this data.

Signed-off-by: Ilan Peer <ilan.peer@intel.com>
[replace another occurrence in libertas, fix kernel-doc, fix bugs]
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

authored by

Ilan Peer and committed by
Johannes Berg
bdfbec2d 685328b2

+29 -32
+1 -6
drivers/net/wireless/libertas/cfg.c
··· 1268 1268 _new_connect_scan_req(struct wiphy *wiphy, struct cfg80211_connect_params *sme) 1269 1269 { 1270 1270 struct cfg80211_scan_request *creq = NULL; 1271 - int i, n_channels = 0; 1271 + int i, n_channels = ieee80211_get_num_supported_channels(wiphy); 1272 1272 enum ieee80211_band band; 1273 - 1274 - for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 1275 - if (wiphy->bands[band]) 1276 - n_channels += wiphy->bands[band]->n_channels; 1277 - } 1278 1273 1279 1274 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) + 1280 1275 n_channels * sizeof(void *),
+8
include/net/cfg80211.h
··· 4640 4640 */ 4641 4641 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp); 4642 4642 4643 + /** 4644 + * ieee80211_get_num_supported_channels - get number of channels device has 4645 + * @wiphy: the wiphy 4646 + * 4647 + * Return: the number of channels supported by the device. 4648 + */ 4649 + unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy); 4650 + 4643 4651 /* Logging, debugging and troubleshooting/diagnostic helpers. */ 4644 4652 4645 4653 /* wiphy_printk helpers, similar to dev_printk */
+2 -11
net/wireless/nl80211.c
··· 5285 5285 goto unlock; 5286 5286 } 5287 5287 } else { 5288 - enum ieee80211_band band; 5289 - n_channels = 0; 5290 - 5291 - for (band = 0; band < IEEE80211_NUM_BANDS; band++) 5292 - if (wiphy->bands[band]) 5293 - n_channels += wiphy->bands[band]->n_channels; 5288 + n_channels = ieee80211_get_num_supported_channels(wiphy); 5294 5289 } 5295 5290 5296 5291 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) ··· 5493 5498 if (!n_channels) 5494 5499 return -EINVAL; 5495 5500 } else { 5496 - n_channels = 0; 5497 - 5498 - for (band = 0; band < IEEE80211_NUM_BANDS; band++) 5499 - if (wiphy->bands[band]) 5500 - n_channels += wiphy->bands[band]->n_channels; 5501 + n_channels = ieee80211_get_num_supported_channels(wiphy); 5501 5502 } 5502 5503 5503 5504 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
+2 -5
net/wireless/scan.c
··· 1089 1089 /* Determine number of channels, needed to allocate creq */ 1090 1090 if (wreq && wreq->num_channels) 1091 1091 n_channels = wreq->num_channels; 1092 - else { 1093 - for (band = 0; band < IEEE80211_NUM_BANDS; band++) 1094 - if (wiphy->bands[band]) 1095 - n_channels += wiphy->bands[band]->n_channels; 1096 - } 1092 + else 1093 + n_channels = ieee80211_get_num_supported_channels(wiphy); 1097 1094 1098 1095 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) + 1099 1096 n_channels * sizeof(void *),
+3 -10
net/wireless/sme.c
··· 70 70 if (rdev->scan_req) 71 71 return -EBUSY; 72 72 73 - if (wdev->conn->params.channel) { 73 + if (wdev->conn->params.channel) 74 74 n_channels = 1; 75 - } else { 76 - enum ieee80211_band band; 77 - n_channels = 0; 75 + else 76 + n_channels = ieee80211_get_num_supported_channels(wdev->wiphy); 78 77 79 - for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 80 - if (!wdev->wiphy->bands[band]) 81 - continue; 82 - n_channels += wdev->wiphy->bands[band]->n_channels; 83 - } 84 - } 85 78 request = kzalloc(sizeof(*request) + sizeof(request->ssids[0]) + 86 79 sizeof(request->channels[0]) * n_channels, 87 80 GFP_KERNEL);
+13
net/wireless/util.c
··· 1481 1481 return 0; 1482 1482 } 1483 1483 1484 + unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy) 1485 + { 1486 + enum ieee80211_band band; 1487 + unsigned int n_channels = 0; 1488 + 1489 + for (band = 0; band < IEEE80211_NUM_BANDS; band++) 1490 + if (wiphy->bands[band]) 1491 + n_channels += wiphy->bands[band]->n_channels; 1492 + 1493 + return n_channels; 1494 + } 1495 + EXPORT_SYMBOL(ieee80211_get_num_supported_channels); 1496 + 1484 1497 /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ 1485 1498 /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ 1486 1499 const unsigned char rfc1042_header[] __aligned(2) =