]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - net/wireless/core.c
Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mfashe...
[mv-sheeva.git] / net / wireless / core.c
index 532e1e09e028e3d69e5f4089c76ac0d0e9532e2a..7eabd55417a5eab222a4c756d1e2181513575cc7 100644 (file)
@@ -53,21 +53,25 @@ struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
 
        mutex_lock(&cfg80211_drv_mutex);
 
-       if (unlikely(wiphy_counter<0)) {
+       drv->idx = wiphy_counter;
+
+       /* now increase counter for the next device unless
+        * it has wrapped previously */
+       if (wiphy_counter >= 0)
+               wiphy_counter++;
+
+       mutex_unlock(&cfg80211_drv_mutex);
+
+       if (unlikely(drv->idx < 0)) {
                /* ugh, wrapped! */
                kfree(drv);
                return NULL;
        }
-       drv->idx = wiphy_counter;
 
        /* give it a proper name */
        snprintf(drv->wiphy.dev.bus_id, BUS_ID_SIZE,
                 PHY_NAME "%d", drv->idx);
 
-       /* now increase counter for the next time */
-       wiphy_counter++;
-       mutex_unlock(&cfg80211_drv_mutex);
-
        mutex_init(&drv->mtx);
        mutex_init(&drv->devlist_mtx);
        INIT_LIST_HEAD(&drv->netdev_list);
@@ -87,7 +91,6 @@ int wiphy_register(struct wiphy *wiphy)
 
        mutex_lock(&cfg80211_drv_mutex);
 
-
        res = device_add(&drv->wiphy.dev);
        if (res)
                goto out_unlock;
@@ -110,14 +113,26 @@ void wiphy_unregister(struct wiphy *wiphy)
 {
        struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy);
 
+       /* protect the device list */
        mutex_lock(&cfg80211_drv_mutex);
 
-       /* hold registered driver mutex during list removal as well
-        * to make sure no commands are in progress at the moment */
+       BUG_ON(!list_empty(&drv->netdev_list));
+
+       /*
+        * Try to grab drv->mtx. If a command is still in progress,
+        * hopefully the driver will refuse it since it's tearing
+        * down the device already. We wait for this command to complete
+        * before unlinking the item from the list.
+        * Note: as codified by the BUG_ON above we cannot get here if
+        * a virtual interface is still associated. Hence, we can only
+        * get to lock contention here if userspace issues a command
+        * that identified the hardware by wiphy index.
+        */
        mutex_lock(&drv->mtx);
-       list_del(&drv->list);
+       /* unlock again before freeing */
        mutex_unlock(&drv->mtx);
 
+       list_del(&drv->list);
        device_del(&drv->wiphy.dev);
        debugfs_remove(drv->wiphy.debugfsdir);