]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wifi: mt76: mt7925: switch link STA allocation to RCU lifetime
authorSean Wang <sean.wang@mediatek.com>
Fri, 6 Mar 2026 23:22:36 +0000 (17:22 -0600)
committerFelix Fietkau <nbd@nbd.name>
Tue, 24 Mar 2026 15:49:32 +0000 (15:49 +0000)
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>
Link: https://patch.msgid.link/20260306232238.2039675-18-sean.wang@kernel.org
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7925/main.c
drivers/net/wireless/mediatek/mt76/mt792x.h

index 9e3f3874d0b3ea83c44a1c18f3862c16ae7ca41c..eb16c4683100fc2d340505e8db7b939c1f34901a 100644 (file)
@@ -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;
        }
index 1f381ab356bc09ca3720415c8abb6e721bc0e93a..4ff93f2cd624deb1b5777728ab433c2836812769 100644 (file)
@@ -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];