summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2007-04-26 20:50:35 -0700
committerDavid S. Miller <davem@davemloft.net>2007-04-26 20:50:35 -0700
commita4d73ee168eeaed3baea86542ad42e1fd7e192d3 (patch)
treec00fcd6915a2d92ecd15589566bbeb2d908ae87a /net
parentb86e0280bb5585a610783ff5392d9d439dee7ddd (diff)
downloadlinux-a4d73ee168eeaed3baea86542ad42e1fd7e192d3.tar.bz2
[WIRELESS] cfg80211: Fix locking in wiphy_new.
This patch fixes the locking in wiphy new. Ingo Oeser <netdev@axxeo.de> noticed that locking in the error case was wrong and also suggested this fix. Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: John W. Linville <linville@tuxdriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/wireless/core.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 532e1e09e028..24a21add0ba6 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -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);