Skip to content

Commit

Permalink
cfg80211: fix race between sysfs and cfg80211
Browse files Browse the repository at this point in the history
device_add() is called before adding the phy to the cfg80211 device
list.

So if a userspace program uses sysfs uevents to detect new phy
devices, and queries nl80211 to get phy info, it can get ENODEV even
though the phy exists in sysfs.

An easy workaround is to hold the cfg80211 mutex until the phy is
present in sysfs/cfg80211/debugfs.

Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Maxime Bizon authored and John W. Linville committed Jul 21, 2010
1 parent acd82aa commit 5a65205
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions net/wireless/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,24 +472,22 @@ int wiphy_register(struct wiphy *wiphy)
/* check and set up bitrates */
ieee80211_set_bitrate_flags(wiphy);

mutex_lock(&cfg80211_mutex);

res = device_add(&rdev->wiphy.dev);
if (res)
return res;
goto out_unlock;

res = rfkill_register(rdev->rfkill);
if (res)
goto out_rm_dev;

mutex_lock(&cfg80211_mutex);

/* set up regulatory info */
wiphy_update_regulatory(wiphy, NL80211_REGDOM_SET_BY_CORE);

list_add_rcu(&rdev->list, &cfg80211_rdev_list);
cfg80211_rdev_list_generation++;

mutex_unlock(&cfg80211_mutex);

/* add to debugfs */
rdev->wiphy.debugfsdir =
debugfs_create_dir(wiphy_name(&rdev->wiphy),
Expand All @@ -509,11 +507,15 @@ int wiphy_register(struct wiphy *wiphy)
}

cfg80211_debugfs_rdev_add(rdev);
mutex_unlock(&cfg80211_mutex);

return 0;

out_rm_dev:
out_rm_dev:
device_del(&rdev->wiphy.dev);

out_unlock:
mutex_unlock(&cfg80211_mutex);
return res;
}
EXPORT_SYMBOL(wiphy_register);
Expand Down

0 comments on commit 5a65205

Please sign in to comment.