public inbox for linux-wireless@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Wang <sean.wang@kernel.org>
To: nbd@nbd.name, lorenzo.bianconi@redhat.com
Cc: linux-wireless@vger.kernel.org,
	linux-mediatek@lists.infradead.org,
	Sean Wang <sean.wang@mediatek.com>
Subject: [PATCH 17/19] wifi: mt76: mt7925: switch link STA allocation to RCU lifetime
Date: Fri,  6 Mar 2026 17:22:36 -0600	[thread overview]
Message-ID: <20260306232238.2039675-18-sean.wang@kernel.org> (raw)
In-Reply-To: <20260306232238.2039675-1-sean.wang@kernel.org>

From: Sean Wang <sean.wang@mediatek.com>

Allocate mt792x_link_sta with kzalloc() and free it with kfree_rcu()
instead of devm-managed memory.

msta->link[] is published via RCU, so the link STA must remain valid
until readers have quiesced after teardown. Manage the object lifetime
with kfree_rcu() to match its RCU-visible publication.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
---
 drivers/net/wireless/mediatek/mt76/mt7925/main.c | 10 +++++++---
 drivers/net/wireless/mediatek/mt76/mt792x.h      |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/main.c b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
index 9e3f3874d0b3..eb16c4683100 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -1005,7 +1005,7 @@ mt7925_mac_sta_add_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 			mlink = &msta->deflink;
 			msta->deflink_id = link_id;
 		} else {
-			mlink = devm_kzalloc(dev->mt76.dev, sizeof(*mlink), GFP_KERNEL);
+			mlink = kzalloc(sizeof(*mlink), GFP_KERNEL);
 			if (!mlink) {
 				err = -ENOMEM;
 				break;
@@ -1197,6 +1197,7 @@ mt7925_mac_sta_remove_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 			    struct ieee80211_sta *sta, unsigned long old_links)
 {
 	struct mt792x_sta *msta = (struct mt792x_sta *)sta->drv_priv;
+	struct mt76_dev *mdev = &dev->mt76;
 	unsigned int link_id;
 
 	/* clean up bss before starec */
@@ -1235,17 +1236,20 @@ mt7925_mac_sta_remove_links(struct mt792x_dev *dev, struct ieee80211_vif *vif,
 		if (!link_sta)
 			continue;
 
-		mlink = mt792x_sta_to_link(msta, link_id);
+		mlink = rcu_replace_pointer(msta->link[link_id], NULL,
+					    lockdep_is_held(&mdev->mutex));
 		if (!mlink)
 			continue;
 
-		rcu_assign_pointer(msta->link[link_id], NULL);
 		msta->valid_links &= ~BIT(link_id);
 		mlink->sta = NULL;
 		mlink->pri_link = NULL;
 
 		mt7925_mac_link_sta_remove(&dev->mt76, vif, link_sta, mlink);
 
+		if (mlink != &msta->deflink)
+			kfree_rcu(mlink, rcu_head);
+
 		if (msta->deflink_id == link_id)
 			msta->deflink_id = IEEE80211_LINK_UNSPECIFIED;
 	}
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h
index 1f381ab356bc..4ff93f2cd624 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x.h
+++ b/drivers/net/wireless/mediatek/mt76/mt792x.h
@@ -97,6 +97,7 @@ DECLARE_EWMA(avg_signal, 10, 8)
 
 struct mt792x_link_sta {
 	struct mt76_wcid wcid; /* must be first */
+	struct rcu_head rcu_head;
 
 	u32 airtime_ac[8];
 
-- 
2.43.0


  parent reply	other threads:[~2026-03-06 23:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-06 23:22 [PATCH 00/19] wifi: mt76: mt7925: fix up MLO link lifetime and error handling Sean Wang
2026-03-06 23:22 ` [PATCH 01/19] wifi: mt76: mt7925: pass mlink to sta_amsdu_tlv() Sean Wang
2026-03-06 23:22 ` [PATCH 02/19] wifi: mt76: mt7925: pass WCID indices to bss_basic_tlv() Sean Wang
2026-03-07 13:45   ` kernel test robot
2026-03-07 17:59   ` kernel test robot
2026-03-06 23:22 ` [PATCH 03/19] wifi: mt76: mt7925: pass mlink and mconf to sta_mld_tlv() Sean Wang
2026-03-06 23:22 ` [PATCH 04/19] wifi: mt76: mt7925: pass mlink to mcu_sta_update() Sean Wang
2026-03-06 23:22 ` [PATCH 05/19] wifi: mt76: mt7925: resolve primary mlink via def_wcid Sean Wang
2026-03-06 23:22 ` [PATCH 06/19] wifi: mt76: mt7925: pass mlink to mac_link_sta_remove() Sean Wang
2026-03-06 23:22 ` [PATCH 07/19] wifi: mt76: mt7925: pass mlink to sta_hdr_trans_tlv() Sean Wang
2026-03-06 23:22 ` [PATCH 08/19] wifi: mt76: mt7925: validate mlink in sta_hdr_trans_tlv() Sean Wang
2026-03-06 23:22 ` [PATCH 09/19] wifi: mt76: mt7925: pass mlink to wtbl_update_hdr_trans() Sean Wang
2026-03-06 23:22 ` [PATCH 10/19] wifi: mt76: mt7925: pass mlink to set_link_key() Sean Wang
2026-03-06 23:22 ` [PATCH 11/19] wifi: mt76: mt7925: resolve link after acquiring mt76 mutex Sean Wang
2026-03-06 23:22 ` [PATCH 12/19] wifi: mt76: mt7925: pass mconf and mlink to wtbl_update_hdr_trans() Sean Wang
2026-03-06 23:22 ` [PATCH 13/19] wifi: mt76: mt7925: make WCID cleanup unconditional in sta_remove_links() Sean Wang
2026-03-06 23:22 ` [PATCH 14/19] wifi: mt76: mt7925: unwind WCID setup on link STA add failure Sean Wang
2026-03-06 23:22 ` [PATCH 15/19] wifi: mt76: mt7925: drop WCID reinit after publish Sean Wang
2026-03-06 23:22 ` [PATCH 16/19] wifi: mt76: mt7925: move WCID teardown into link_sta_remove() Sean Wang
2026-03-06 23:22 ` Sean Wang [this message]
2026-03-06 23:22 ` [PATCH 18/19] wifi: mt76: mt7925: publish msta->link after successful link add Sean Wang
2026-03-06 23:22 ` [PATCH 19/19] wifi: mt76: mt7925: host-only unwind published links on add failure Sean Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260306232238.2039675-18-sean.wang@kernel.org \
    --to=sean.wang@kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lorenzo.bianconi@redhat.com \
    --cc=nbd@nbd.name \
    --cc=sean.wang@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox