Skip to content

Commit dc60941

Browse files
rory-littlegregkh
authored andcommitted
wifi: mac80211: Add non-atomic station iterator
[ Upstream commit 7c3b69e ] Drivers may at times want to iterate their stations with a function which requires some non-atomic operations. ieee80211_iterate_stations_mtx() introduces an API to iterate stations while holding that wiphy's mutex. This allows the iterating function to do non-atomic operations safely. Signed-off-by: Rory Little <[email protected]> Link: https://patch.msgid.link/[email protected] [unify internal list iteration functions] Signed-off-by: Johannes Berg <[email protected]> Stable-dep-of: 8fac326 ("wifi: ath12k: fix atomic calls in ath12k_mac_op_set_bitrate_mask()") Signed-off-by: Sasha Levin <[email protected]>
1 parent 4eceef7 commit dc60941

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

include/net/mac80211.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6080,6 +6080,24 @@ void ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw,
60806080
void (*iterator)(void *data,
60816081
struct ieee80211_sta *sta),
60826082
void *data);
6083+
6084+
/**
6085+
* ieee80211_iterate_stations_mtx - iterate stations
6086+
*
6087+
* This function iterates over all stations associated with a given
6088+
* hardware that are currently uploaded to the driver and calls the callback
6089+
* function for them. This version can only be used while holding the wiphy
6090+
* mutex.
6091+
*
6092+
* @hw: the hardware struct of which the interfaces should be iterated over
6093+
* @iterator: the iterator function to call
6094+
* @data: first argument of the iterator function
6095+
*/
6096+
void ieee80211_iterate_stations_mtx(struct ieee80211_hw *hw,
6097+
void (*iterator)(void *data,
6098+
struct ieee80211_sta *sta),
6099+
void *data);
6100+
60836101
/**
60846102
* ieee80211_queue_work - add work onto the mac80211 workqueue
60856103
*

net/mac80211/util.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,8 @@ static void __iterate_stations(struct ieee80211_local *local,
827827
{
828828
struct sta_info *sta;
829829

830-
list_for_each_entry_rcu(sta, &local->sta_list, list) {
830+
list_for_each_entry_rcu(sta, &local->sta_list, list,
831+
lockdep_is_held(&local->hw.wiphy->mtx)) {
831832
if (!sta->uploaded)
832833
continue;
833834

@@ -848,6 +849,19 @@ void ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw,
848849
}
849850
EXPORT_SYMBOL_GPL(ieee80211_iterate_stations_atomic);
850851

852+
void ieee80211_iterate_stations_mtx(struct ieee80211_hw *hw,
853+
void (*iterator)(void *data,
854+
struct ieee80211_sta *sta),
855+
void *data)
856+
{
857+
struct ieee80211_local *local = hw_to_local(hw);
858+
859+
lockdep_assert_wiphy(local->hw.wiphy);
860+
861+
__iterate_stations(local, iterator, data);
862+
}
863+
EXPORT_SYMBOL_GPL(ieee80211_iterate_stations_mtx);
864+
851865
struct ieee80211_vif *wdev_to_ieee80211_vif(struct wireless_dev *wdev)
852866
{
853867
struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);

0 commit comments

Comments
 (0)