Commit fdc9d7b2 authored by Johannes Berg's avatar Johannes Berg

regulatory: remove BUG_ON

This code is a bit too BUG_ON happy, remove all
instances and while doing so make some code a bit
smarter by passing the right pointer instead of
indices into arrays.
Acked-by: default avatarLuis R. Rodriguez <mcgrof@do-not-panic.com>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent f4173766
...@@ -4309,8 +4309,6 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) ...@@ -4309,8 +4309,6 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
} }
} }
BUG_ON(rule_idx != num_rules);
r = set_regdom(rd); r = set_regdom(rd);
rd = NULL; rd = NULL;
......
...@@ -213,7 +213,7 @@ static void reset_regdomains(bool full_reset) ...@@ -213,7 +213,7 @@ static void reset_regdomains(bool full_reset)
*/ */
static void update_world_regdomain(const struct ieee80211_regdomain *rd) static void update_world_regdomain(const struct ieee80211_regdomain *rd)
{ {
BUG_ON(!last_request); WARN_ON(!last_request);
reset_regdomains(false); reset_regdomains(false);
...@@ -804,8 +804,7 @@ static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan, ...@@ -804,8 +804,7 @@ static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan,
*/ */
static void handle_channel(struct wiphy *wiphy, static void handle_channel(struct wiphy *wiphy,
enum nl80211_reg_initiator initiator, enum nl80211_reg_initiator initiator,
enum ieee80211_band band, struct ieee80211_channel *chan)
unsigned int chan_idx)
{ {
int r; int r;
u32 flags, bw_flags = 0; u32 flags, bw_flags = 0;
...@@ -813,18 +812,12 @@ static void handle_channel(struct wiphy *wiphy, ...@@ -813,18 +812,12 @@ static void handle_channel(struct wiphy *wiphy,
const struct ieee80211_reg_rule *reg_rule = NULL; const struct ieee80211_reg_rule *reg_rule = NULL;
const struct ieee80211_power_rule *power_rule = NULL; const struct ieee80211_power_rule *power_rule = NULL;
const struct ieee80211_freq_range *freq_range = NULL; const struct ieee80211_freq_range *freq_range = NULL;
struct ieee80211_supported_band *sband;
struct ieee80211_channel *chan;
struct wiphy *request_wiphy = NULL; struct wiphy *request_wiphy = NULL;
assert_cfg80211_lock(); assert_cfg80211_lock();
request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
sband = wiphy->bands[band];
BUG_ON(chan_idx >= sband->n_channels);
chan = &sband->channels[chan_idx];
flags = chan->orig_flags; flags = chan->orig_flags;
r = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq), r = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq),
...@@ -897,17 +890,17 @@ static void handle_channel(struct wiphy *wiphy, ...@@ -897,17 +890,17 @@ static void handle_channel(struct wiphy *wiphy,
chan->max_power = chan->max_reg_power; chan->max_power = chan->max_reg_power;
} }
static void handle_band(struct wiphy *wiphy, enum ieee80211_band band, static void handle_band(struct wiphy *wiphy,
enum nl80211_reg_initiator initiator) enum nl80211_reg_initiator initiator,
struct ieee80211_supported_band *sband)
{ {
unsigned int i; unsigned int i;
struct ieee80211_supported_band *sband;
BUG_ON(!wiphy->bands[band]); if (!sband)
sband = wiphy->bands[band]; return;
for (i = 0; i < sband->n_channels; i++) for (i = 0; i < sband->n_channels; i++)
handle_channel(wiphy, initiator, band, i); handle_channel(wiphy, initiator, &sband->channels[i]);
} }
static bool reg_request_cell_base(struct regulatory_request *request) static bool reg_request_cell_base(struct regulatory_request *request)
...@@ -1116,20 +1109,14 @@ static bool is_ht40_allowed(struct ieee80211_channel *chan) ...@@ -1116,20 +1109,14 @@ static bool is_ht40_allowed(struct ieee80211_channel *chan)
} }
static void reg_process_ht_flags_channel(struct wiphy *wiphy, static void reg_process_ht_flags_channel(struct wiphy *wiphy,
enum ieee80211_band band, struct ieee80211_channel *channel)
unsigned int chan_idx)
{ {
struct ieee80211_supported_band *sband; struct ieee80211_supported_band *sband = wiphy->bands[channel->band];
struct ieee80211_channel *channel;
struct ieee80211_channel *channel_before = NULL, *channel_after = NULL; struct ieee80211_channel *channel_before = NULL, *channel_after = NULL;
unsigned int i; unsigned int i;
assert_cfg80211_lock(); assert_cfg80211_lock();
sband = wiphy->bands[band];
BUG_ON(chan_idx >= sband->n_channels);
channel = &sband->channels[chan_idx];
if (!is_ht40_allowed(channel)) { if (!is_ht40_allowed(channel)) {
channel->flags |= IEEE80211_CHAN_NO_HT40; channel->flags |= IEEE80211_CHAN_NO_HT40;
return; return;
...@@ -1165,16 +1152,15 @@ static void reg_process_ht_flags_channel(struct wiphy *wiphy, ...@@ -1165,16 +1152,15 @@ static void reg_process_ht_flags_channel(struct wiphy *wiphy,
} }
static void reg_process_ht_flags_band(struct wiphy *wiphy, static void reg_process_ht_flags_band(struct wiphy *wiphy,
enum ieee80211_band band) struct ieee80211_supported_band *sband)
{ {
unsigned int i; unsigned int i;
struct ieee80211_supported_band *sband;
BUG_ON(!wiphy->bands[band]); if (!sband)
sband = wiphy->bands[band]; return;
for (i = 0; i < sband->n_channels; i++) for (i = 0; i < sband->n_channels; i++)
reg_process_ht_flags_channel(wiphy, band, i); reg_process_ht_flags_channel(wiphy, &sband->channels[i]);
} }
static void reg_process_ht_flags(struct wiphy *wiphy) static void reg_process_ht_flags(struct wiphy *wiphy)
...@@ -1184,11 +1170,8 @@ static void reg_process_ht_flags(struct wiphy *wiphy) ...@@ -1184,11 +1170,8 @@ static void reg_process_ht_flags(struct wiphy *wiphy)
if (!wiphy) if (!wiphy)
return; return;
for (band = 0; band < IEEE80211_NUM_BANDS; band++) { for (band = 0; band < IEEE80211_NUM_BANDS; band++)
if (wiphy->bands[band]) reg_process_ht_flags_band(wiphy, wiphy->bands[band]);
reg_process_ht_flags_band(wiphy, band);
}
} }
static void wiphy_update_regulatory(struct wiphy *wiphy, static void wiphy_update_regulatory(struct wiphy *wiphy,
...@@ -1203,10 +1186,8 @@ static void wiphy_update_regulatory(struct wiphy *wiphy, ...@@ -1203,10 +1186,8 @@ static void wiphy_update_regulatory(struct wiphy *wiphy,
last_request->dfs_region = cfg80211_regdomain->dfs_region; last_request->dfs_region = cfg80211_regdomain->dfs_region;
for (band = 0; band < IEEE80211_NUM_BANDS; band++) { for (band = 0; band < IEEE80211_NUM_BANDS; band++)
if (wiphy->bands[band]) handle_band(wiphy, initiator, wiphy->bands[band]);
handle_band(wiphy, band, initiator);
}
reg_process_beacons(wiphy); reg_process_beacons(wiphy);
reg_process_ht_flags(wiphy); reg_process_ht_flags(wiphy);
...@@ -1236,8 +1217,7 @@ static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator) ...@@ -1236,8 +1217,7 @@ static void update_all_wiphy_regulatory(enum nl80211_reg_initiator initiator)
} }
static void handle_channel_custom(struct wiphy *wiphy, static void handle_channel_custom(struct wiphy *wiphy,
enum ieee80211_band band, struct ieee80211_channel *chan,
unsigned int chan_idx,
const struct ieee80211_regdomain *regd) const struct ieee80211_regdomain *regd)
{ {
int r; int r;
...@@ -1246,15 +1226,9 @@ static void handle_channel_custom(struct wiphy *wiphy, ...@@ -1246,15 +1226,9 @@ static void handle_channel_custom(struct wiphy *wiphy,
const struct ieee80211_reg_rule *reg_rule = NULL; const struct ieee80211_reg_rule *reg_rule = NULL;
const struct ieee80211_power_rule *power_rule = NULL; const struct ieee80211_power_rule *power_rule = NULL;
const struct ieee80211_freq_range *freq_range = NULL; const struct ieee80211_freq_range *freq_range = NULL;
struct ieee80211_supported_band *sband;
struct ieee80211_channel *chan;
assert_reg_lock(); assert_reg_lock();
sband = wiphy->bands[band];
BUG_ON(chan_idx >= sband->n_channels);
chan = &sband->channels[chan_idx];
r = freq_reg_info_regd(wiphy, MHZ_TO_KHZ(chan->center_freq), r = freq_reg_info_regd(wiphy, MHZ_TO_KHZ(chan->center_freq),
desired_bw_khz, &reg_rule, regd); desired_bw_khz, &reg_rule, regd);
...@@ -1279,17 +1253,17 @@ static void handle_channel_custom(struct wiphy *wiphy, ...@@ -1279,17 +1253,17 @@ static void handle_channel_custom(struct wiphy *wiphy,
(int) MBM_TO_DBM(power_rule->max_eirp); (int) MBM_TO_DBM(power_rule->max_eirp);
} }
static void handle_band_custom(struct wiphy *wiphy, enum ieee80211_band band, static void handle_band_custom(struct wiphy *wiphy,
struct ieee80211_supported_band *sband,
const struct ieee80211_regdomain *regd) const struct ieee80211_regdomain *regd)
{ {
unsigned int i; unsigned int i;
struct ieee80211_supported_band *sband;
BUG_ON(!wiphy->bands[band]); if (!sband)
sband = wiphy->bands[band]; return;
for (i = 0; i < sband->n_channels; i++) for (i = 0; i < sband->n_channels; i++)
handle_channel_custom(wiphy, band, i, regd); handle_channel_custom(wiphy, &sband->channels[i], regd);
} }
/* Used by drivers prior to wiphy registration */ /* Used by drivers prior to wiphy registration */
...@@ -1303,7 +1277,7 @@ void wiphy_apply_custom_regulatory(struct wiphy *wiphy, ...@@ -1303,7 +1277,7 @@ void wiphy_apply_custom_regulatory(struct wiphy *wiphy,
for (band = 0; band < IEEE80211_NUM_BANDS; band++) { for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
if (!wiphy->bands[band]) if (!wiphy->bands[band])
continue; continue;
handle_band_custom(wiphy, band, regd); handle_band_custom(wiphy, wiphy->bands[band], regd);
bands_set++; bands_set++;
} }
mutex_unlock(&reg_mutex); mutex_unlock(&reg_mutex);
...@@ -1537,7 +1511,8 @@ static void reg_process_hint(struct regulatory_request *reg_request, ...@@ -1537,7 +1511,8 @@ static void reg_process_hint(struct regulatory_request *reg_request,
{ {
struct wiphy *wiphy = NULL; struct wiphy *wiphy = NULL;
BUG_ON(!reg_request->alpha2); if (WARN_ON(!reg_request->alpha2))
return;
if (reg_request->wiphy_idx != WIPHY_IDX_INVALID) if (reg_request->wiphy_idx != WIPHY_IDX_INVALID)
wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx); wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx);
...@@ -1678,7 +1653,8 @@ int regulatory_hint_user(const char *alpha2, ...@@ -1678,7 +1653,8 @@ int regulatory_hint_user(const char *alpha2,
{ {
struct regulatory_request *request; struct regulatory_request *request;
BUG_ON(!alpha2); if (WARN_ON(!alpha2))
return -EINVAL;
request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
if (!request) if (!request)
...@@ -1700,8 +1676,8 @@ int regulatory_hint(struct wiphy *wiphy, const char *alpha2) ...@@ -1700,8 +1676,8 @@ int regulatory_hint(struct wiphy *wiphy, const char *alpha2)
{ {
struct regulatory_request *request; struct regulatory_request *request;
BUG_ON(!alpha2); if (WARN_ON(!alpha2 || !wiphy))
BUG_ON(!wiphy); return -EINVAL;
request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
if (!request) if (!request)
...@@ -2239,12 +2215,14 @@ int set_regdom(const struct ieee80211_regdomain *rd) ...@@ -2239,12 +2215,14 @@ int set_regdom(const struct ieee80211_regdomain *rd)
reg_set_request_processed(); reg_set_request_processed();
kfree(rd); kfree(rd);
mutex_unlock(&reg_mutex); goto out;
return r;
} }
/* This would make this whole thing pointless */ /* This would make this whole thing pointless */
BUG_ON(!last_request->intersect && rd != cfg80211_regdomain); if (WARN_ON(!last_request->intersect && rd != cfg80211_regdomain)) {
r = -EINVAL;
goto out;
}
/* update all wiphys now with the new established regulatory domain */ /* update all wiphys now with the new established regulatory domain */
update_all_wiphy_regulatory(last_request->initiator); update_all_wiphy_regulatory(last_request->initiator);
...@@ -2255,6 +2233,7 @@ int set_regdom(const struct ieee80211_regdomain *rd) ...@@ -2255,6 +2233,7 @@ int set_regdom(const struct ieee80211_regdomain *rd)
reg_set_request_processed(); reg_set_request_processed();
out:
mutex_unlock(&reg_mutex); mutex_unlock(&reg_mutex);
return r; return r;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment