Skip to content

Commit

Permalink
wifi: cfg80211: define and use wiphy guard
Browse files Browse the repository at this point in the history
Define a guard for the wiphy mutex, and use it in
most code in cfg80211, though not all due to some
interaction with RTNL and/or indentation.

Suggested-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Reviewed-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Link: https://patch.msgid.link/20241122094225.88765cbaab65.I610c9b14f36902e75e1d13f0db29f8bef2298804@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  • Loading branch information
Johannes Berg committed Dec 4, 2024
1 parent bee404e commit f42d22d
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 448 deletions.
4 changes: 4 additions & 0 deletions include/net/cfg80211.h
Original file line number Diff line number Diff line change
Expand Up @@ -6031,6 +6031,10 @@ static inline void wiphy_unlock(struct wiphy *wiphy)
mutex_unlock(&wiphy->mtx);
}

DEFINE_GUARD(wiphy, struct wiphy *,
mutex_lock(&_T->mtx),
mutex_unlock(&_T->mtx))

struct wiphy_work;
typedef void (*wiphy_work_func_t)(struct wiphy *, struct wiphy_work *);

Expand Down
4 changes: 2 additions & 2 deletions net/wireless/chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,10 +1039,10 @@ bool cfg80211_any_wiphy_oper_chan(struct wiphy *wiphy,
if (!reg_dfs_domain_same(wiphy, &rdev->wiphy))
continue;

wiphy_lock(&rdev->wiphy);
guard(wiphy)(&rdev->wiphy);

found = cfg80211_is_wiphy_oper_chan(&rdev->wiphy, chan) ||
cfg80211_offchan_chain_is_active(rdev, chan);
wiphy_unlock(&rdev->wiphy);

if (found)
return true;
Expand Down
42 changes: 19 additions & 23 deletions net/wireless/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
return err;
}

wiphy_lock(&rdev->wiphy);
guard(wiphy)(&rdev->wiphy);

list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
if (!wdev->netdev)
continue;
Expand All @@ -212,7 +213,6 @@ int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
continue;
nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE);
}
wiphy_unlock(&rdev->wiphy);

return 0;
}
Expand All @@ -221,9 +221,9 @@ static void cfg80211_rfkill_poll(struct rfkill *rfkill, void *data)
{
struct cfg80211_registered_device *rdev = data;

wiphy_lock(&rdev->wiphy);
guard(wiphy)(&rdev->wiphy);

rdev_rfkill_poll(rdev);
wiphy_unlock(&rdev->wiphy);
}

void cfg80211_stop_p2p_device(struct cfg80211_registered_device *rdev,
Expand Down Expand Up @@ -283,7 +283,7 @@ void cfg80211_shutdown_all_interfaces(struct wiphy *wiphy)

/* otherwise, check iftype */

wiphy_lock(wiphy);
guard(wiphy)(wiphy);

switch (wdev->iftype) {
case NL80211_IFTYPE_P2P_DEVICE:
Expand All @@ -295,8 +295,6 @@ void cfg80211_shutdown_all_interfaces(struct wiphy *wiphy)
default:
break;
}

wiphy_unlock(wiphy);
}
}
EXPORT_SYMBOL_GPL(cfg80211_shutdown_all_interfaces);
Expand Down Expand Up @@ -331,9 +329,9 @@ static void cfg80211_event_work(struct work_struct *work)
rdev = container_of(work, struct cfg80211_registered_device,
event_work);

wiphy_lock(&rdev->wiphy);
guard(wiphy)(&rdev->wiphy);

cfg80211_process_rdev_events(rdev);
wiphy_unlock(&rdev->wiphy);
}

void cfg80211_destroy_ifaces(struct cfg80211_registered_device *rdev)
Expand All @@ -347,10 +345,10 @@ void cfg80211_destroy_ifaces(struct cfg80211_registered_device *rdev)
if (wdev->netdev)
dev_close(wdev->netdev);

wiphy_lock(&rdev->wiphy);
guard(wiphy)(&rdev->wiphy);

cfg80211_leave(rdev, wdev);
cfg80211_remove_virtual_intf(rdev, wdev);
wiphy_unlock(&rdev->wiphy);
}
}
}
Expand Down Expand Up @@ -423,9 +421,9 @@ static void cfg80211_wiphy_work(struct work_struct *work)

trace_wiphy_work_worker_start(&rdev->wiphy);

wiphy_lock(&rdev->wiphy);
guard(wiphy)(&rdev->wiphy);
if (rdev->suspended)
goto out;
return;

spin_lock_irq(&rdev->wiphy_work_lock);
wk = list_first_entry_or_null(&rdev->wiphy_work_list,
Expand All @@ -441,8 +439,6 @@ static void cfg80211_wiphy_work(struct work_struct *work)
} else {
spin_unlock_irq(&rdev->wiphy_work_lock);
}
out:
wiphy_unlock(&rdev->wiphy);
}

/* exported functions */
Expand Down Expand Up @@ -1526,9 +1522,9 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
break;
case NETDEV_REGISTER:
if (!wdev->registered) {
wiphy_lock(&rdev->wiphy);
guard(wiphy)(&rdev->wiphy);

cfg80211_register_wdev(rdev, wdev);
wiphy_unlock(&rdev->wiphy);
}
break;
case NETDEV_UNREGISTER:
Expand All @@ -1537,16 +1533,16 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
* so check wdev->registered.
*/
if (wdev->registered && !wdev->registering) {
wiphy_lock(&rdev->wiphy);
guard(wiphy)(&rdev->wiphy);

_cfg80211_unregister_wdev(wdev, false);
wiphy_unlock(&rdev->wiphy);
}
break;
case NETDEV_GOING_DOWN:
wiphy_lock(&rdev->wiphy);
cfg80211_leave(rdev, wdev);
cfg80211_remove_links(wdev);
wiphy_unlock(&rdev->wiphy);
scoped_guard(wiphy, &rdev->wiphy) {
cfg80211_leave(rdev, wdev);
cfg80211_remove_links(wdev);
}
/* since we just did cfg80211_leave() nothing to do there */
cancel_work_sync(&wdev->disconnect_wk);
cancel_work_sync(&wdev->pmsr_free_wk);
Expand Down
8 changes: 4 additions & 4 deletions net/wireless/mlme.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,10 @@ void cfg80211_mgmt_registrations_update_wk(struct work_struct *wk)
rdev = container_of(wk, struct cfg80211_registered_device,
mgmt_registrations_update_wk);

wiphy_lock(&rdev->wiphy);
guard(wiphy)(&rdev->wiphy);

list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list)
cfg80211_mgmt_registrations_update(wdev);
wiphy_unlock(&rdev->wiphy);
}

int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_portid,
Expand Down Expand Up @@ -1193,10 +1193,10 @@ cfg80211_background_cac_event(struct cfg80211_registered_device *rdev,
const struct cfg80211_chan_def *chandef,
enum nl80211_radar_event event)
{
wiphy_lock(&rdev->wiphy);
guard(wiphy)(&rdev->wiphy);

__cfg80211_background_cac_event(rdev, rdev->background_radar_wdev,
chandef, event);
wiphy_unlock(&rdev->wiphy);
}

void cfg80211_background_cac_done_wk(struct work_struct *work)
Expand Down
Loading

0 comments on commit f42d22d

Please sign in to comment.