cfg80211: fix deadlock
[pandora-kernel.git] / net / wireless / core.c
index 62e1ac0..69a185b 100644 (file)
@@ -412,6 +412,8 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
        rdev->wiphy.dev.class = &ieee80211_class;
        rdev->wiphy.dev.platform_data = rdev;
 
+       rdev->wiphy.ps_default = CONFIG_CFG80211_DEFAULT_PS_VALUE;
+
        wiphy_net_set(&rdev->wiphy, &init_net);
 
        rdev->rfkill_ops.set_block = cfg80211_rfkill_set_block;
@@ -584,9 +586,14 @@ void wiphy_unregister(struct wiphy *wiphy)
         * get to lock contention here if userspace issues a command
         * that identified the hardware by wiphy index.
         */
-       mutex_lock(&rdev->mtx);
-       /* unlock again before freeing */
-       mutex_unlock(&rdev->mtx);
+       cfg80211_lock_rdev(rdev);
+
+       if (WARN_ON(rdev->scan_req)) {
+               rdev->scan_req->aborted = true;
+               ___cfg80211_scan_done(rdev);
+       }
+
+       cfg80211_unlock_rdev(rdev);
 
        cfg80211_debugfs_rdev_del(rdev);
 
@@ -601,9 +608,8 @@ void wiphy_unregister(struct wiphy *wiphy)
 
        mutex_unlock(&cfg80211_mutex);
 
+       flush_work(&rdev->scan_done_wk);
        cancel_work_sync(&rdev->conn_work);
-       cancel_work_sync(&rdev->scan_done_wk);
-       kfree(rdev->scan_req);
        flush_work(&rdev->event_work);
 }
 EXPORT_SYMBOL(wiphy_unregister);
@@ -651,6 +657,11 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
 
        switch (state) {
        case NETDEV_REGISTER:
+               /*
+                * NB: cannot take rdev->mtx here because this may be
+                * called within code protected by it when interfaces
+                * are added with nl80211.
+                */
                mutex_init(&wdev->mtx);
                INIT_LIST_HEAD(&wdev->event_list);
                spin_lock_init(&wdev->event_lock);
@@ -674,7 +685,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
                wdev->wext.default_key = -1;
                wdev->wext.default_mgmt_key = -1;
                wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
-               wdev->wext.ps = CONFIG_CFG80211_DEFAULT_PS_VALUE;
+               wdev->wext.ps = wdev->wiphy->ps_default;
                wdev->wext.ps_timeout = 100;
                if (rdev->ops->set_power_mgmt)
                        if (rdev->ops->set_power_mgmt(wdev->wiphy, dev,
@@ -710,6 +721,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
        case NETDEV_UP:
 #ifdef CONFIG_WIRELESS_EXT
                cfg80211_lock_rdev(rdev);
+               mutex_lock(&rdev->devlist_mtx);
                wdev_lock(wdev);
                switch (wdev->iftype) {
                case NL80211_IFTYPE_ADHOC:
@@ -722,10 +734,16 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
                        break;
                }
                wdev_unlock(wdev);
+               mutex_unlock(&rdev->devlist_mtx);
                cfg80211_unlock_rdev(rdev);
 #endif
                break;
        case NETDEV_UNREGISTER:
+               /*
+                * NB: cannot take rdev->mtx here because this may be
+                * called within code protected by it when interfaces
+                * are removed with nl80211.
+                */
                mutex_lock(&rdev->devlist_mtx);
                /*
                 * It is possible to get NETDEV_UNREGISTER