diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2008-10-24 14:32:20 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-10-31 19:02:30 -0400 |
commit | d2372b315289aec9f565a855023c40654a5bff68 (patch) | |
tree | cfc73e74dfdea854dd27b747d68224076d8e8d90 | |
parent | 7dddaf1a36a372c14ca96a0b5fdfbe2015c43841 (diff) |
wireless: make regdom passing semantics simpler
The regdom struct is given to the core, so it might as well
free it in error conditions.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r-- | Documentation/networking/regulatory.txt | 13 | ||||
-rw-r--r-- | include/net/wireless.h | 3 | ||||
-rw-r--r-- | net/wireless/nl80211.c | 5 | ||||
-rw-r--r-- | net/wireless/reg.c | 9 |
4 files changed, 10 insertions, 20 deletions
diff --git a/Documentation/networking/regulatory.txt b/Documentation/networking/regulatory.txt index a96989a8ff35..357d4ba4f135 100644 --- a/Documentation/networking/regulatory.txt +++ b/Documentation/networking/regulatory.txt | |||
@@ -167,7 +167,6 @@ struct ieee80211_regdomain mydriver_jp_regdom = { | |||
167 | 167 | ||
168 | Then in some part of your code after your wiphy has been registered: | 168 | Then in some part of your code after your wiphy has been registered: |
169 | 169 | ||
170 | int r; | ||
171 | struct ieee80211_regdomain *rd; | 170 | struct ieee80211_regdomain *rd; |
172 | int size_of_regd; | 171 | int size_of_regd; |
173 | int num_rules = mydriver_jp_regdom.n_reg_rules; | 172 | int num_rules = mydriver_jp_regdom.n_reg_rules; |
@@ -178,17 +177,11 @@ Then in some part of your code after your wiphy has been registered: | |||
178 | 177 | ||
179 | rd = kzalloc(size_of_regd, GFP_KERNEL); | 178 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
180 | if (!rd) | 179 | if (!rd) |
181 | return -ENOMEM; | 180 | return -ENOMEM; |
182 | 181 | ||
183 | memcpy(rd, &mydriver_jp_regdom, sizeof(struct ieee80211_regdomain)); | 182 | memcpy(rd, &mydriver_jp_regdom, sizeof(struct ieee80211_regdomain)); |
184 | 183 | ||
185 | for (i=0; i < num_rules; i++) { | 184 | for (i=0; i < num_rules; i++) |
186 | memcpy(&rd->reg_rules[i], &mydriver_jp_regdom.reg_rules[i], | 185 | memcpy(&rd->reg_rules[i], &mydriver_jp_regdom.reg_rules[i], |
187 | sizeof(struct ieee80211_reg_rule)); | 186 | sizeof(struct ieee80211_reg_rule)); |
188 | } | 187 | return regulatory_hint(hw->wiphy, NULL, rd); |
189 | r = regulatory_hint(hw->wiphy, NULL, rd); | ||
190 | if (r) { | ||
191 | kfree(rd); | ||
192 | return r; | ||
193 | } | ||
194 | |||
diff --git a/include/net/wireless.h b/include/net/wireless.h index 061fe5017e5c..6e3ea0159045 100644 --- a/include/net/wireless.h +++ b/include/net/wireless.h | |||
@@ -358,8 +358,7 @@ ieee80211_get_channel(struct wiphy *wiphy, int freq) | |||
358 | * for a regulatory domain structure for the respective country. If | 358 | * for a regulatory domain structure for the respective country. If |
359 | * a regulatory domain is build and passed you should set the alpha2 | 359 | * a regulatory domain is build and passed you should set the alpha2 |
360 | * if possible, otherwise set it to the special value of "99" which tells | 360 | * if possible, otherwise set it to the special value of "99" which tells |
361 | * the wireless core it is unknown. If you pass a built regulatory domain | 361 | * the wireless core it is unknown. |
362 | * and we return non zero you are in charge of kfree()'ing the structure. | ||
363 | * | 362 | * |
364 | * Returns -EALREADY if *a regulatory domain* has already been set. Note that | 363 | * Returns -EALREADY if *a regulatory domain* has already been set. Note that |
365 | * this could be by another driver. It is safe for drivers to continue if | 364 | * this could be by another driver. It is safe for drivers to continue if |
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 9a16e9e6c5ca..f82cc9aa6908 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c | |||
@@ -1935,12 +1935,9 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) | |||
1935 | mutex_lock(&cfg80211_drv_mutex); | 1935 | mutex_lock(&cfg80211_drv_mutex); |
1936 | r = set_regdom(rd); | 1936 | r = set_regdom(rd); |
1937 | mutex_unlock(&cfg80211_drv_mutex); | 1937 | mutex_unlock(&cfg80211_drv_mutex); |
1938 | if (r) | ||
1939 | goto bad_reg; | ||
1940 | |||
1941 | return r; | 1938 | return r; |
1942 | 1939 | ||
1943 | bad_reg: | 1940 | bad_reg: |
1944 | kfree(rd); | 1941 | kfree(rd); |
1945 | return -EINVAL; | 1942 | return -EINVAL; |
1946 | } | 1943 | } |
diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 00c326b66c03..038f8f133c54 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c | |||
@@ -605,7 +605,6 @@ int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by, | |||
605 | return r; | 605 | return r; |
606 | } | 606 | } |
607 | 607 | ||
608 | /* If rd is not NULL and if this call fails the caller must free it */ | ||
609 | int regulatory_hint(struct wiphy *wiphy, const char *alpha2, | 608 | int regulatory_hint(struct wiphy *wiphy, const char *alpha2, |
610 | struct ieee80211_regdomain *rd) | 609 | struct ieee80211_regdomain *rd) |
611 | { | 610 | { |
@@ -690,6 +689,7 @@ void print_regdomain_info(const struct ieee80211_regdomain *rd) | |||
690 | print_rd_rules(rd); | 689 | print_rd_rules(rd); |
691 | } | 690 | } |
692 | 691 | ||
692 | /* Takes ownership of rd only if it doesn't fail */ | ||
693 | static int __set_regdom(const struct ieee80211_regdomain *rd) | 693 | static int __set_regdom(const struct ieee80211_regdomain *rd) |
694 | { | 694 | { |
695 | /* Some basic sanity checks first */ | 695 | /* Some basic sanity checks first */ |
@@ -750,16 +750,17 @@ static int __set_regdom(const struct ieee80211_regdomain *rd) | |||
750 | 750 | ||
751 | /* Use this call to set the current regulatory domain. Conflicts with | 751 | /* Use this call to set the current regulatory domain. Conflicts with |
752 | * multiple drivers can be ironed out later. Caller must've already | 752 | * multiple drivers can be ironed out later. Caller must've already |
753 | * kmalloc'd the rd structure. If this calls fails you should kfree() | 753 | * kmalloc'd the rd structure. Caller must hold cfg80211_drv_mutex */ |
754 | * the passed rd. Caller must hold cfg80211_drv_mutex */ | ||
755 | int set_regdom(const struct ieee80211_regdomain *rd) | 754 | int set_regdom(const struct ieee80211_regdomain *rd) |
756 | { | 755 | { |
757 | int r; | 756 | int r; |
758 | 757 | ||
759 | /* Note that this doesn't update the wiphys, this is done below */ | 758 | /* Note that this doesn't update the wiphys, this is done below */ |
760 | r = __set_regdom(rd); | 759 | r = __set_regdom(rd); |
761 | if (r) | 760 | if (r) { |
761 | kfree(rd); | ||
762 | return r; | 762 | return r; |
763 | } | ||
763 | 764 | ||
764 | /* This would make this whole thing pointless */ | 765 | /* This would make this whole thing pointless */ |
765 | BUG_ON(rd != cfg80211_regdomain); | 766 | BUG_ON(rd != cfg80211_regdomain); |