Skip to contentSkip to conversation

cfg80211: fix locking in wiphy_new

PATCH Applied John W. Linville 2 participants 2 messages Apr 27, 2007 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cfg80211: fix locking in wiphy_new

From: Johannes Berg <[email protected]>

This patch fixes the locking in wiphy new. Ingo Oeser <[email protected]> noticed that locking in the error case was wrong and also suggested this fix.

---
 net/wireless/core.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
net/wireless/core.c +10 -6
index 532e1e0..24a21ad 100644
@@ -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);
Signature · 5 lines
1.5.0.6

-- 
John W. Linville
[email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]