From: Miri Korenblit Date: Wed, 27 May 2026 19:51:44 +0000 (+0300) Subject: wifi: mac80211: refactor ieee80211_nan_try_evacuate X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5b9ebd5c3f409ddfe1c15bdba361f904c16d719;p=thirdparty%2Flinux.git wifi: mac80211: refactor ieee80211_nan_try_evacuate Extract the logic that finds a NAN channel which makes a good evacuation candidate into a separate function. It will be used in a later patch. Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20260527224745.589503562912.I9e266da48ceaf85bd0fe1b0487c3fdbeaaf9baaa@changeid Signed-off-by: Johannes Berg --- diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 20b27c8f7d4e2..fcdb6fdd4d75e 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -1946,6 +1946,11 @@ ieee80211_vif_get_num_mcast_if(struct ieee80211_sub_if_data *sdata) return -1; } +static inline bool ieee80211_sdata_running(struct ieee80211_sub_if_data *sdata) +{ + return test_bit(SDATA_STATE_RUNNING, &sdata->state); +} + int ieee80211_hw_config(struct ieee80211_local *local, int radio_idx, u32 changed); int ieee80211_hw_conf_chan(struct ieee80211_local *local); @@ -2055,6 +2060,23 @@ int ieee80211_nan_set_peer_sched(struct ieee80211_sub_if_data *sdata, void ieee80211_nan_free_peer_sched(struct ieee80211_nan_peer_sched *sched); void ieee80211_nan_update_ndi_carrier(struct ieee80211_sub_if_data *ndi_sdata); +static inline struct ieee80211_sub_if_data * +ieee80211_find_nan_sdata(struct ieee80211_local *local) +{ + struct ieee80211_sub_if_data *sdata; + + lockdep_assert_wiphy(local->hw.wiphy); + + /* Find the NAN interface - there can only be one */ + list_for_each_entry(sdata, &local->interfaces, list) { + if (ieee80211_sdata_running(sdata) && + sdata->vif.type == NL80211_IFTYPE_NAN) + return sdata; + } + + return NULL; +} + /* scan/BSS handling */ void ieee80211_scan_work(struct wiphy *wiphy, struct wiphy_work *work); int ieee80211_request_ibss_scan(struct ieee80211_sub_if_data *sdata, @@ -2155,11 +2177,6 @@ void ieee80211_recalc_txpower(struct ieee80211_link_data *link, bool update_bss); void ieee80211_recalc_offload(struct ieee80211_local *local); -static inline bool ieee80211_sdata_running(struct ieee80211_sub_if_data *sdata) -{ - return test_bit(SDATA_STATE_RUNNING, &sdata->state); -} - /* link handling */ void ieee80211_link_setup(struct ieee80211_link_data *link); void ieee80211_link_init(struct ieee80211_sub_if_data *sdata, diff --git a/net/mac80211/nan.c b/net/mac80211/nan.c index cea620aaee6ad..44b6e298d94dd 100644 --- a/net/mac80211/nan.c +++ b/net/mac80211/nan.c @@ -754,33 +754,20 @@ ieee80211_nan_evacuate_channel(struct ieee80211_sub_if_data *sdata, ieee80211_free_chanctx(sdata->local, ctx, false); } -bool ieee80211_nan_try_evacuate(struct ieee80211_hw *hw, - struct ieee80211_chanctx_conf *conf) +static struct ieee80211_nan_channel * +ieee80211_nan_find_evac_chan(struct ieee80211_local *local, + struct ieee80211_sub_if_data *sdata, + struct ieee80211_chanctx *ctx) { - struct ieee80211_sub_if_data *sdata = NULL, *tmp; - struct ieee80211_local *local = hw_to_local(hw); - struct ieee80211_nan_channel *evac_chan = NULL; struct ieee80211_nan_sched_cfg *sched_cfg; - struct ieee80211_chanctx *ctx = NULL; + struct ieee80211_nan_channel *evac_chan = NULL; int min_slot_count = INT_MAX; int usable_channels = 0; lockdep_assert_wiphy(local->hw.wiphy); - if (conf) - ctx = container_of(conf, struct ieee80211_chanctx, conf); - - /* Find the NAN interface - there can only be one */ - list_for_each_entry(tmp, &local->interfaces, list) { - if (ieee80211_sdata_running(tmp) && - tmp->vif.type == NL80211_IFTYPE_NAN) { - sdata = tmp; - break; - } - } - - if (!sdata) - return false; + if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_NAN)) + return NULL; sched_cfg = &sdata->vif.cfg.nan_sched; @@ -823,10 +810,34 @@ bool ieee80211_nan_try_evacuate(struct ieee80211_hw *hw, /* No suitable NAN channel found */ if (!evac_chan) - return false; + return NULL; /* NAN needs at least one remaining usable channel after evacuation */ if (usable_channels < 2) + return NULL; + + return evac_chan; +} + +bool ieee80211_nan_try_evacuate(struct ieee80211_hw *hw, + struct ieee80211_chanctx_conf *conf) +{ + struct ieee80211_local *local = hw_to_local(hw); + struct ieee80211_sub_if_data *sdata = + ieee80211_find_nan_sdata(local); + struct ieee80211_nan_channel *evac_chan; + struct ieee80211_chanctx *ctx = NULL; + + lockdep_assert_wiphy(local->hw.wiphy); + + if (!sdata) + return false; + + if (conf) + ctx = container_of(conf, struct ieee80211_chanctx, conf); + + evac_chan = ieee80211_nan_find_evac_chan(local, sdata, ctx); + if (!evac_chan) return false; ieee80211_nan_evacuate_channel(sdata, evac_chan);