[PATCH 04/23] wifi: mt76: mt7925: wire up NAN MAC randomization lifecycle

Sean Wang sean.wang at kernel.org
Sun Sep 27 14:02:46 PDT 2026


From: Chengwei Yu <chengwei.yu at mediatek.com>

Start mac_rand_work in mt7925_add_interface() and stop it in
mt7925_remove_interface() so the work item added by prior patches
is usable and cannot outlive its vif.

INIT_DELAYED_WORK() is unconditional across all vif types, matching
how csa_work is already initialized unconditionally -- mvif->nan
exists on every mt792x_vif so there is nothing NAN-specific to guard.

mt7925_nan_stop_mac_randomization() is called before
mt792x_mutex_acquire(), not inside it: the work function takes the
same dev mutex, so cancel_delayed_work_sync() while holding it would
deadlock. This follows the same ordering mt792x_unassign_vif_chanctx()
uses for csa_work.

Co-developed-by: Sean Wang <sean.wang at mediatek.com>
Signed-off-by: Sean Wang <sean.wang at mediatek.com>
Signed-off-by: Chengwei Yu <chengwei.yu at mediatek.com>
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
index c882952f5df1..3e1c223e8da6 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -480,6 +480,12 @@ mt7925_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
 
 	if (vif->type == NL80211_IFTYPE_NAN)
 		dev->nan_vif = vif;
+
+	if (vif->type == NL80211_IFTYPE_NAN ||
+	    vif->type == NL80211_IFTYPE_NAN_DATA)
+		INIT_DELAYED_WORK(&mvif->nan.mac_rand_work,
+				  mt7925_nan_mac_rand_work);
+
 out:
 	mt792x_mutex_release(dev);
 
@@ -493,6 +499,15 @@ mt7925_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
 	struct mt792x_dev *dev = mt792x_hw_dev(hw);
 	struct mt792x_bss_conf *mconf;
 
+	/*
+	 * Stop before taking the dev mutex: mt7925_nan_mac_rand_work()
+	 * acquires it too, so cancel_delayed_work_sync() would deadlock
+	 * against a concurrently running instance if called while held.
+	 */
+	if (vif->type == NL80211_IFTYPE_NAN ||
+	    vif->type == NL80211_IFTYPE_NAN_DATA)
+		mt7925_nan_stop_mac_randomization(vif);
+
 	mt792x_mutex_acquire(dev);
 
 	if (dev->nan_vif == vif)
-- 
2.43.0




More information about the Linux-mediatek mailing list