diff options
author | Johannes Berg <johannes.berg@intel.com> | 2012-12-06 09:57:14 -0500 |
---|---|---|
committer | Johannes Berg <johannes.berg@intel.com> | 2013-01-03 07:01:31 -0500 |
commit | 361c9c8b0eeeec7d881e018d5143bf883558c566 (patch) | |
tree | 631cd436b7e80b8134084a935337c6ee3243bd7b | |
parent | c492db370c17c428a0a58d3673294d4e99634b7d (diff) |
regulatory: use IS_ERR macro family for freq_reg_info
Instead of returning an error and filling a pointer
return the pointer and an ERR_PTR value in error cases.
Acked-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
-rw-r--r-- | drivers/net/wireless/ath/regd.c | 16 | ||||
-rw-r--r-- | drivers/net/wireless/brcm80211/brcmsmac/channel.c | 7 | ||||
-rw-r--r-- | drivers/net/wireless/rtlwifi/regd.c | 14 | ||||
-rw-r--r-- | include/net/cfg80211.h | 18 | ||||
-rw-r--r-- | net/wireless/reg.c | 38 |
5 files changed, 41 insertions, 52 deletions
diff --git a/drivers/net/wireless/ath/regd.c b/drivers/net/wireless/ath/regd.c index 8ae58c404c67..7a6c79e1f819 100644 --- a/drivers/net/wireless/ath/regd.c +++ b/drivers/net/wireless/ath/regd.c | |||
@@ -195,7 +195,6 @@ ath_reg_apply_beaconing_flags(struct wiphy *wiphy, | |||
195 | const struct ieee80211_reg_rule *reg_rule; | 195 | const struct ieee80211_reg_rule *reg_rule; |
196 | struct ieee80211_channel *ch; | 196 | struct ieee80211_channel *ch; |
197 | unsigned int i; | 197 | unsigned int i; |
198 | int r; | ||
199 | 198 | ||
200 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | 199 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
201 | 200 | ||
@@ -213,10 +212,8 @@ ath_reg_apply_beaconing_flags(struct wiphy *wiphy, | |||
213 | continue; | 212 | continue; |
214 | 213 | ||
215 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) { | 214 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) { |
216 | r = freq_reg_info(wiphy, | 215 | reg_rule = freq_reg_info(wiphy, ch->center_freq); |
217 | ch->center_freq, | 216 | if (IS_ERR(reg_rule)) |
218 | ®_rule); | ||
219 | if (r) | ||
220 | continue; | 217 | continue; |
221 | /* | 218 | /* |
222 | * If 11d had a rule for this channel ensure | 219 | * If 11d had a rule for this channel ensure |
@@ -252,7 +249,6 @@ ath_reg_apply_active_scan_flags(struct wiphy *wiphy, | |||
252 | struct ieee80211_supported_band *sband; | 249 | struct ieee80211_supported_band *sband; |
253 | struct ieee80211_channel *ch; | 250 | struct ieee80211_channel *ch; |
254 | const struct ieee80211_reg_rule *reg_rule; | 251 | const struct ieee80211_reg_rule *reg_rule; |
255 | int r; | ||
256 | 252 | ||
257 | sband = wiphy->bands[IEEE80211_BAND_2GHZ]; | 253 | sband = wiphy->bands[IEEE80211_BAND_2GHZ]; |
258 | if (!sband) | 254 | if (!sband) |
@@ -280,16 +276,16 @@ ath_reg_apply_active_scan_flags(struct wiphy *wiphy, | |||
280 | */ | 276 | */ |
281 | 277 | ||
282 | ch = &sband->channels[11]; /* CH 12 */ | 278 | ch = &sband->channels[11]; /* CH 12 */ |
283 | r = freq_reg_info(wiphy, ch->center_freq, ®_rule); | 279 | reg_rule = freq_reg_info(wiphy, ch->center_freq); |
284 | if (!r) { | 280 | if (!IS_ERR(reg_rule)) { |
285 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) | 281 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) |
286 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) | 282 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
287 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; | 283 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
288 | } | 284 | } |
289 | 285 | ||
290 | ch = &sband->channels[12]; /* CH 13 */ | 286 | ch = &sband->channels[12]; /* CH 13 */ |
291 | r = freq_reg_info(wiphy, ch->center_freq, ®_rule); | 287 | reg_rule = freq_reg_info(wiphy, ch->center_freq); |
292 | if (!r) { | 288 | if (!IS_ERR(reg_rule)) { |
293 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) | 289 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) |
294 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) | 290 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
295 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; | 291 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/channel.c b/drivers/net/wireless/brcm80211/brcmsmac/channel.c index 30272519d795..4eb3f0d52105 100644 --- a/drivers/net/wireless/brcm80211/brcmsmac/channel.c +++ b/drivers/net/wireless/brcm80211/brcmsmac/channel.c | |||
@@ -670,7 +670,7 @@ brcms_reg_apply_beaconing_flags(struct wiphy *wiphy, | |||
670 | struct ieee80211_supported_band *sband; | 670 | struct ieee80211_supported_band *sband; |
671 | struct ieee80211_channel *ch; | 671 | struct ieee80211_channel *ch; |
672 | const struct ieee80211_reg_rule *rule; | 672 | const struct ieee80211_reg_rule *rule; |
673 | int band, i, ret; | 673 | int band, i; |
674 | 674 | ||
675 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | 675 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
676 | sband = wiphy->bands[band]; | 676 | sband = wiphy->bands[band]; |
@@ -685,9 +685,8 @@ brcms_reg_apply_beaconing_flags(struct wiphy *wiphy, | |||
685 | continue; | 685 | continue; |
686 | 686 | ||
687 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) { | 687 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) { |
688 | ret = freq_reg_info(wiphy, ch->center_freq, | 688 | rule = freq_reg_info(wiphy, ch->center_freq); |
689 | &rule); | 689 | if (IS_ERR(rule)) |
690 | if (ret) | ||
691 | continue; | 690 | continue; |
692 | 691 | ||
693 | if (!(rule->flags & NL80211_RRF_NO_IBSS)) | 692 | if (!(rule->flags & NL80211_RRF_NO_IBSS)) |
diff --git a/drivers/net/wireless/rtlwifi/regd.c b/drivers/net/wireless/rtlwifi/regd.c index be55dc9167f0..7e3ead774fb9 100644 --- a/drivers/net/wireless/rtlwifi/regd.c +++ b/drivers/net/wireless/rtlwifi/regd.c | |||
@@ -158,7 +158,6 @@ static void _rtl_reg_apply_beaconing_flags(struct wiphy *wiphy, | |||
158 | const struct ieee80211_reg_rule *reg_rule; | 158 | const struct ieee80211_reg_rule *reg_rule; |
159 | struct ieee80211_channel *ch; | 159 | struct ieee80211_channel *ch; |
160 | unsigned int i; | 160 | unsigned int i; |
161 | int r; | ||
162 | 161 | ||
163 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | 162 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
164 | 163 | ||
@@ -173,8 +172,8 @@ static void _rtl_reg_apply_beaconing_flags(struct wiphy *wiphy, | |||
173 | (ch->flags & IEEE80211_CHAN_RADAR)) | 172 | (ch->flags & IEEE80211_CHAN_RADAR)) |
174 | continue; | 173 | continue; |
175 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) { | 174 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) { |
176 | r = freq_reg_info(wiphy, ch->center_freq, ®_rule); | 175 | reg_rule = freq_reg_info(wiphy, ch->center_freq); |
177 | if (r) | 176 | if (IS_ERR(reg_rule)) |
178 | continue; | 177 | continue; |
179 | 178 | ||
180 | /* | 179 | /* |
@@ -209,7 +208,6 @@ static void _rtl_reg_apply_active_scan_flags(struct wiphy *wiphy, | |||
209 | struct ieee80211_supported_band *sband; | 208 | struct ieee80211_supported_band *sband; |
210 | struct ieee80211_channel *ch; | 209 | struct ieee80211_channel *ch; |
211 | const struct ieee80211_reg_rule *reg_rule; | 210 | const struct ieee80211_reg_rule *reg_rule; |
212 | int r; | ||
213 | 211 | ||
214 | if (!wiphy->bands[IEEE80211_BAND_2GHZ]) | 212 | if (!wiphy->bands[IEEE80211_BAND_2GHZ]) |
215 | return; | 213 | return; |
@@ -237,16 +235,16 @@ static void _rtl_reg_apply_active_scan_flags(struct wiphy *wiphy, | |||
237 | */ | 235 | */ |
238 | 236 | ||
239 | ch = &sband->channels[11]; /* CH 12 */ | 237 | ch = &sband->channels[11]; /* CH 12 */ |
240 | r = freq_reg_info(wiphy, ch->center_freq, ®_rule); | 238 | reg_rule = freq_reg_info(wiphy, ch->center_freq); |
241 | if (!r) { | 239 | if (!IS_ERR(reg_rule)) { |
242 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) | 240 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) |
243 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) | 241 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
244 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; | 242 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
245 | } | 243 | } |
246 | 244 | ||
247 | ch = &sband->channels[12]; /* CH 13 */ | 245 | ch = &sband->channels[12]; /* CH 13 */ |
248 | r = freq_reg_info(wiphy, ch->center_freq, ®_rule); | 246 | reg_rule = freq_reg_info(wiphy, ch->center_freq); |
249 | if (!r) { | 247 | if (!IS_ERR(reg_rule)) { |
250 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) | 248 | if (!(reg_rule->flags & NL80211_RRF_PASSIVE_SCAN)) |
251 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) | 249 | if (ch->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
252 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; | 250 | ch->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; |
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index f3be58a29642..1f74360b527c 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h | |||
@@ -2938,22 +2938,22 @@ extern void wiphy_apply_custom_regulatory( | |||
2938 | * freq_reg_info - get regulatory information for the given frequency | 2938 | * freq_reg_info - get regulatory information for the given frequency |
2939 | * @wiphy: the wiphy for which we want to process this rule for | 2939 | * @wiphy: the wiphy for which we want to process this rule for |
2940 | * @center_freq: Frequency in KHz for which we want regulatory information for | 2940 | * @center_freq: Frequency in KHz for which we want regulatory information for |
2941 | * @reg_rule: the regulatory rule which we have for this frequency | ||
2942 | * | 2941 | * |
2943 | * Use this function to get the regulatory rule for a specific frequency on | 2942 | * Use this function to get the regulatory rule for a specific frequency on |
2944 | * a given wireless device. If the device has a specific regulatory domain | 2943 | * a given wireless device. If the device has a specific regulatory domain |
2945 | * it wants to follow we respect that unless a country IE has been received | 2944 | * it wants to follow we respect that unless a country IE has been received |
2946 | * and processed already. | 2945 | * and processed already. |
2947 | * | 2946 | * |
2948 | * Returns 0 if it was able to find a valid regulatory rule which does | 2947 | * When an error occurs, for example if no rule can be found, the return value |
2949 | * apply to the given center_freq otherwise it returns non-zero. It will | 2948 | * is encoded using ERR_PTR(). Use IS_ERR() to check and PTR_ERR() to obtain |
2950 | * also return -ERANGE if we determine the given center_freq does not even have | 2949 | * the numeric return value. The numeric return value will be -ERANGE if we |
2951 | * a regulatory rule for a frequency range in the center_freq's band. See | 2950 | * determine the given center_freq does not even have a regulatory rule for a |
2952 | * freq_in_rule_band() for our current definition of a band -- this is purely | 2951 | * frequency range in the center_freq's band. See freq_in_rule_band() for our |
2953 | * subjective and right now its 802.11 specific. | 2952 | * current definition of a band -- this is purely subjective and right now it's |
2953 | * 802.11 specific. | ||
2954 | */ | 2954 | */ |
2955 | extern int freq_reg_info(struct wiphy *wiphy, u32 center_freq, | 2955 | const struct ieee80211_reg_rule *freq_reg_info(struct wiphy *wiphy, |
2956 | const struct ieee80211_reg_rule **reg_rule); | 2956 | u32 center_freq); |
2957 | 2957 | ||
2958 | /* | 2958 | /* |
2959 | * callbacks for asynchronous cfg80211 methods, notification | 2959 | * callbacks for asynchronous cfg80211 methods, notification |
diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 2a7c3adf902f..fd53d975c0bc 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c | |||
@@ -710,16 +710,16 @@ static u32 map_regdom_flags(u32 rd_flags) | |||
710 | return channel_flags; | 710 | return channel_flags; |
711 | } | 711 | } |
712 | 712 | ||
713 | static int freq_reg_info_regd(struct wiphy *wiphy, u32 center_freq, | 713 | static const struct ieee80211_reg_rule * |
714 | const struct ieee80211_reg_rule **reg_rule, | 714 | freq_reg_info_regd(struct wiphy *wiphy, u32 center_freq, |
715 | const struct ieee80211_regdomain *regd) | 715 | const struct ieee80211_regdomain *regd) |
716 | { | 716 | { |
717 | int i; | 717 | int i; |
718 | bool band_rule_found = false; | 718 | bool band_rule_found = false; |
719 | bool bw_fits = false; | 719 | bool bw_fits = false; |
720 | 720 | ||
721 | if (!regd) | 721 | if (!regd) |
722 | return -EINVAL; | 722 | return ERR_PTR(-EINVAL); |
723 | 723 | ||
724 | for (i = 0; i < regd->n_reg_rules; i++) { | 724 | for (i = 0; i < regd->n_reg_rules; i++) { |
725 | const struct ieee80211_reg_rule *rr; | 725 | const struct ieee80211_reg_rule *rr; |
@@ -738,20 +738,18 @@ static int freq_reg_info_regd(struct wiphy *wiphy, u32 center_freq, | |||
738 | 738 | ||
739 | bw_fits = reg_does_bw_fit(fr, center_freq, MHZ_TO_KHZ(20)); | 739 | bw_fits = reg_does_bw_fit(fr, center_freq, MHZ_TO_KHZ(20)); |
740 | 740 | ||
741 | if (band_rule_found && bw_fits) { | 741 | if (band_rule_found && bw_fits) |
742 | *reg_rule = rr; | 742 | return rr; |
743 | return 0; | ||
744 | } | ||
745 | } | 743 | } |
746 | 744 | ||
747 | if (!band_rule_found) | 745 | if (!band_rule_found) |
748 | return -ERANGE; | 746 | return ERR_PTR(-ERANGE); |
749 | 747 | ||
750 | return -EINVAL; | 748 | return ERR_PTR(-EINVAL); |
751 | } | 749 | } |
752 | 750 | ||
753 | int freq_reg_info(struct wiphy *wiphy, u32 center_freq, | 751 | const struct ieee80211_reg_rule *freq_reg_info(struct wiphy *wiphy, |
754 | const struct ieee80211_reg_rule **reg_rule) | 752 | u32 center_freq) |
755 | { | 753 | { |
756 | const struct ieee80211_regdomain *regd; | 754 | const struct ieee80211_regdomain *regd; |
757 | struct regulatory_request *lr = get_last_request(); | 755 | struct regulatory_request *lr = get_last_request(); |
@@ -767,7 +765,7 @@ int freq_reg_info(struct wiphy *wiphy, u32 center_freq, | |||
767 | else | 765 | else |
768 | regd = get_cfg80211_regdom(); | 766 | regd = get_cfg80211_regdom(); |
769 | 767 | ||
770 | return freq_reg_info_regd(wiphy, center_freq, reg_rule, regd); | 768 | return freq_reg_info_regd(wiphy, center_freq, regd); |
771 | } | 769 | } |
772 | EXPORT_SYMBOL(freq_reg_info); | 770 | EXPORT_SYMBOL(freq_reg_info); |
773 | 771 | ||
@@ -829,7 +827,6 @@ static void handle_channel(struct wiphy *wiphy, | |||
829 | enum nl80211_reg_initiator initiator, | 827 | enum nl80211_reg_initiator initiator, |
830 | struct ieee80211_channel *chan) | 828 | struct ieee80211_channel *chan) |
831 | { | 829 | { |
832 | int r; | ||
833 | u32 flags, bw_flags = 0; | 830 | u32 flags, bw_flags = 0; |
834 | const struct ieee80211_reg_rule *reg_rule = NULL; | 831 | const struct ieee80211_reg_rule *reg_rule = NULL; |
835 | const struct ieee80211_power_rule *power_rule = NULL; | 832 | const struct ieee80211_power_rule *power_rule = NULL; |
@@ -841,8 +838,8 @@ static void handle_channel(struct wiphy *wiphy, | |||
841 | 838 | ||
842 | flags = chan->orig_flags; | 839 | flags = chan->orig_flags; |
843 | 840 | ||
844 | r = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq), ®_rule); | 841 | reg_rule = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); |
845 | if (r) { | 842 | if (IS_ERR(reg_rule)) { |
846 | /* | 843 | /* |
847 | * We will disable all channels that do not match our | 844 | * We will disable all channels that do not match our |
848 | * received regulatory rule unless the hint is coming | 845 | * received regulatory rule unless the hint is coming |
@@ -854,7 +851,7 @@ static void handle_channel(struct wiphy *wiphy, | |||
854 | * while 5 GHz is still supported. | 851 | * while 5 GHz is still supported. |
855 | */ | 852 | */ |
856 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && | 853 | if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && |
857 | r == -ERANGE) | 854 | PTR_ERR(reg_rule) == -ERANGE) |
858 | return; | 855 | return; |
859 | 856 | ||
860 | REG_DBG_PRINT("Disabling freq %d MHz\n", chan->center_freq); | 857 | REG_DBG_PRINT("Disabling freq %d MHz\n", chan->center_freq); |
@@ -1239,16 +1236,15 @@ static void handle_channel_custom(struct wiphy *wiphy, | |||
1239 | struct ieee80211_channel *chan, | 1236 | struct ieee80211_channel *chan, |
1240 | const struct ieee80211_regdomain *regd) | 1237 | const struct ieee80211_regdomain *regd) |
1241 | { | 1238 | { |
1242 | int r; | ||
1243 | u32 bw_flags = 0; | 1239 | u32 bw_flags = 0; |
1244 | const struct ieee80211_reg_rule *reg_rule = NULL; | 1240 | const struct ieee80211_reg_rule *reg_rule = NULL; |
1245 | const struct ieee80211_power_rule *power_rule = NULL; | 1241 | const struct ieee80211_power_rule *power_rule = NULL; |
1246 | const struct ieee80211_freq_range *freq_range = NULL; | 1242 | const struct ieee80211_freq_range *freq_range = NULL; |
1247 | 1243 | ||
1248 | r = freq_reg_info_regd(wiphy, MHZ_TO_KHZ(chan->center_freq), | 1244 | reg_rule = freq_reg_info_regd(wiphy, MHZ_TO_KHZ(chan->center_freq), |
1249 | ®_rule, regd); | 1245 | regd); |
1250 | 1246 | ||
1251 | if (r) { | 1247 | if (IS_ERR(reg_rule)) { |
1252 | REG_DBG_PRINT("Disabling freq %d MHz as custom regd has no rule that fits it\n", | 1248 | REG_DBG_PRINT("Disabling freq %d MHz as custom regd has no rule that fits it\n", |
1253 | chan->center_freq); | 1249 | chan->center_freq); |
1254 | chan->flags = IEEE80211_CHAN_DISABLED; | 1250 | chan->flags = IEEE80211_CHAN_DISABLED; |