Skip to content

Commit aadb50d

Browse files
Arend van SprielKalle Valo
authored andcommitted
wifi: brcmfmac: avoid NULL-deref in survey dump for 2G only device
When dealing with a device for 2GHz band only the wiphy->bands for 5GHz will be NULL. This would result in a NULL-deref in the brcmf_cfg80211_dump_survey() function. Rework the code with a for-loop to make it easier to add another band. Fixes: 6c04dea ("brcmfmac: Add dump_survey cfg80211 ops for HostApd AutoChannelSelection") Signed-off-by: Arend van Spriel <arend.vanspriel@broadcom.com> Signed-off-by: Kalle Valo <kvalo@kernel.org> Link: https://lore.kernel.org/r/20230103124117.271988-3-arend.vanspriel@broadcom.com
1 parent e5d1ab1 commit aadb50d

File tree

1 file changed

+13
-10
lines changed
  • drivers/net/wireless/broadcom/brcm80211/brcmfmac

1 file changed

+13
-10
lines changed

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7964,6 +7964,7 @@ brcmf_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *ndev,
79647964
struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
79657965
struct brcmf_dump_survey survey = {};
79667966
struct ieee80211_supported_band *band;
7967+
enum nl80211_band band_id;
79677968
struct cca_msrmnt_query req;
79687969
u32 noise;
79697970
int err;
@@ -7976,21 +7977,23 @@ brcmf_cfg80211_dump_survey(struct wiphy *wiphy, struct net_device *ndev,
79767977
return -EBUSY;
79777978
}
79787979

7979-
band = wiphy->bands[NL80211_BAND_2GHZ];
7980-
if (band && idx >= band->n_channels) {
7981-
idx -= band->n_channels;
7982-
band = NULL;
7983-
}
7980+
for (band_id = 0; band_id < NUM_NL80211_BANDS; band_id++) {
7981+
band = wiphy->bands[band_id];
7982+
if (!band)
7983+
continue;
7984+
if (idx >= band->n_channels) {
7985+
idx -= band->n_channels;
7986+
continue;
7987+
}
79847988

7985-
if (!band || idx >= band->n_channels) {
7986-
band = wiphy->bands[NL80211_BAND_5GHZ];
7987-
if (idx >= band->n_channels)
7988-
return -ENOENT;
7989+
info->channel = &band->channels[idx];
7990+
break;
79897991
}
7992+
if (band_id == NUM_NL80211_BANDS)
7993+
return -ENOENT;
79907994

79917995
/* Setting current channel to the requested channel */
79927996
info->filled = 0;
7993-
info->channel = &band->channels[idx];
79947997
if (cfg80211_set_channel(wiphy, ndev, info->channel, NL80211_CHAN_HT20))
79957998
return 0;
79967999

0 commit comments

Comments
 (0)