RxRPC: Error handling for rxrpc_alloc_connection()
[safe/jmp/linux-2.6] / net / wireless / core.c
index e347093..d1f5565 100644 (file)
@@ -32,17 +32,17 @@ MODULE_DESCRIPTION("wireless configuration support");
 LIST_HEAD(cfg80211_drv_list);
 
 /*
- * This is used to protect the cfg80211_drv_list, cfg80211_regdomain, and
- * the last reguluatory request receipt in regd.c
+ * This is used to protect the cfg80211_drv_list, cfg80211_regdomain,
+ * country_ie_regdomain, the reg_beacon_list and the the last regulatory
+ * request receipt (last_request).
  */
 DEFINE_MUTEX(cfg80211_mutex);
 
 /* for debugfs */
 static struct dentry *ieee80211_debugfs_dir;
 
-/* requires cfg80211_drv_mutex to be held! */
-static struct cfg80211_registered_device *
-cfg80211_drv_by_wiphy_idx(int wiphy_idx)
+/* requires cfg80211_mutex to be held! */
+struct cfg80211_registered_device *cfg80211_drv_by_wiphy_idx(int wiphy_idx)
 {
        struct cfg80211_registered_device *result = NULL, *drv;
 
@@ -61,8 +61,33 @@ cfg80211_drv_by_wiphy_idx(int wiphy_idx)
        return result;
 }
 
+int get_wiphy_idx(struct wiphy *wiphy)
+{
+       struct cfg80211_registered_device *drv;
+       if (!wiphy)
+               return WIPHY_IDX_STALE;
+       drv = wiphy_to_dev(wiphy);
+       return drv->wiphy_idx;
+}
+
+/* requires cfg80211_drv_mutex to be held! */
+struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx)
+{
+       struct cfg80211_registered_device *drv;
+
+       if (!wiphy_idx_valid(wiphy_idx))
+               return NULL;
+
+       assert_cfg80211_lock();
+
+       drv = cfg80211_drv_by_wiphy_idx(wiphy_idx);
+       if (!drv)
+               return NULL;
+       return &drv->wiphy;
+}
+
 /* requires cfg80211_mutex to be held! */
-static struct cfg80211_registered_device *
+struct cfg80211_registered_device *
 __cfg80211_drv_from_info(struct genl_info *info)
 {
        int ifindex;
@@ -151,13 +176,14 @@ void cfg80211_put_dev(struct cfg80211_registered_device *drv)
        mutex_unlock(&drv->mtx);
 }
 
+/* requires cfg80211_mutex to be held */
 int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
                        char *newname)
 {
        struct cfg80211_registered_device *drv;
        int wiphy_idx, taken = -1, result, digits;
 
-       mutex_lock(&cfg80211_mutex);
+       assert_cfg80211_lock();
 
        /* prohibit calling the thing phy%d when %d is not its number */
        sscanf(newname, PHY_NAME "%d%n", &wiphy_idx, &taken);
@@ -170,30 +196,23 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
                 * deny the name if it is phy<idx> where <idx> is printed
                 * without leading zeroes. taken == strlen(newname) here
                 */
-               result = -EINVAL;
                if (taken == strlen(PHY_NAME) + digits)
-                       goto out_unlock;
+                       return -EINVAL;
        }
 
 
        /* Ignore nop renames */
-       result = 0;
        if (strcmp(newname, dev_name(&rdev->wiphy.dev)) == 0)
-               goto out_unlock;
+               return 0;
 
        /* Ensure another device does not already have this name. */
-       list_for_each_entry(drv, &cfg80211_drv_list, list) {
-               result = -EINVAL;
+       list_for_each_entry(drv, &cfg80211_drv_list, list)
                if (strcmp(newname, dev_name(&drv->wiphy.dev)) == 0)
-                       goto out_unlock;
-       }
+                       return -EINVAL;
 
-       /* this will only check for collisions in sysfs
-        * which is not even always compiled in.
-        */
        result = device_rename(&rdev->wiphy.dev, newname);
        if (result)
-               goto out_unlock;
+               return result;
 
        if (rdev->wiphy.debugfsdir &&
            !debugfs_rename(rdev->wiphy.debugfsdir->d_parent,
@@ -203,13 +222,9 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
                printk(KERN_ERR "cfg80211: failed to rename debugfs dir to %s!\n",
                       newname);
 
-       result = 0;
-out_unlock:
-       mutex_unlock(&cfg80211_mutex);
-       if (result == 0)
-               nl80211_notify_dev_rename(rdev);
+       nl80211_notify_dev_rename(rdev);
 
-       return result;
+       return 0;
 }
 
 /* exported functions */
@@ -325,7 +340,7 @@ int wiphy_register(struct wiphy *wiphy)
        mutex_lock(&cfg80211_mutex);
 
        /* set up regulatory info */
-       wiphy_update_regulatory(wiphy, REGDOM_SET_BY_CORE);
+       wiphy_update_regulatory(wiphy, NL80211_REGDOM_SET_BY_CORE);
 
        res = device_add(&drv->wiphy.dev);
        if (res)
@@ -340,6 +355,17 @@ int wiphy_register(struct wiphy *wiphy)
        if (IS_ERR(drv->wiphy.debugfsdir))
                drv->wiphy.debugfsdir = NULL;
 
+       if (wiphy->custom_regulatory) {
+               struct regulatory_request request;
+
+               request.wiphy_idx = get_wiphy_idx(wiphy);
+               request.initiator = NL80211_REGDOM_SET_BY_DRIVER;
+               request.alpha2[0] = '9';
+               request.alpha2[1] = '9';
+
+               nl80211_send_reg_change_event(&request);
+       }
+
        res = 0;
 out_unlock:
        mutex_unlock(&cfg80211_mutex);