Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH] cfg80211: fix locking in wiphy_new
@ 2007-04-27  1:47 John W. Linville
  2007-04-27  3:50 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: John W. Linville @ 2007-04-27  1:47 UTC (permalink / raw)
  To: davem; +Cc: Johannes Berg, netdev, linux-wireless

From: Johannes Berg <johannes@sipsolutions.net>

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>
---
 net/wireless/core.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/net/wireless/core.c b/net/wireless/core.c
index 532e1e0..24a21ad 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);
-- 
1.5.0.6

-- 
John W. Linville
linville@tuxdriver.com

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cfg80211: fix locking in wiphy_new
  2007-04-27  1:47 [PATCH] cfg80211: fix locking in wiphy_new John W. Linville
@ 2007-04-27  3:50 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2007-04-27  3:50 UTC (permalink / raw)
  To: linville; +Cc: johannes, netdev, linux-wireless

From: "John W. Linville" <linville@tuxdriver.com>
Date: Thu, 26 Apr 2007 21:47:44 -0400

> From: Johannes Berg <johannes@sipsolutions.net>
> 
> 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>

Applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-04-27  3:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-27  1:47 [PATCH] cfg80211: fix locking in wiphy_new John W. Linville
2007-04-27  3:50 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox