[PATCH ath-next 3/7] wifi: ath12k: fix ath12k_mac_op_change_vif_links() for active-link updates

From: Miaoqing Pan

Date: Tue Nov 17 2026 - 21:56:13 EST


Currently, ath12k_mac_op_change_vif_links() derives the links to add and
remove from the old_links/new_links arguments: it creates a link vif
(arvif) for each link in ~old_links & new_links and frees the arvif of
each link in old_links & ~new_links.

However, mac80211 invokes drv_change_vif_links() both when the valid
links change and when the active links change. In the first case
old_links/new_links are the valid links. In the second case they are
only the active links, while vif->valid_links is not modified. A link
that is deactivated is therefore reported as removed, although it is
still a valid link of the MLD.

To fix this, derive the arvif lifetime from vif->valid_links, which
mac80211 updates before calling the driver and which an active-link
change leaves untouched. Create an arvif for each link in
valid_links & ~links_map and remove those in links_map & ~valid_links.
A link that is only deactivated keeps its arvif. On disconnect
(valid_links == 0) every remaining arvif is removed. The WARN_ON() for
adding a link that already has an arvif is dropped, since links already
in links_map are not selected for creation.

Tested-on: QCC2072 hw1.0 PCI WLAN.COL.1.0.c2-00277-QCACOLSWPL_V1_TO_SILICONZ-1
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3

Fixes: 315d80be304a ("wifi: ath12k: allocate new links in change_vif_links()")
Signed-off-by: Miaoqing Pan <miaoqing.pan@xxxxxxxxxxxxxxxx>
---
drivers/net/wireless/ath/ath12k/mac.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c
index 3f106ac6141c..28cb549b1f46 100644
--- a/drivers/net/wireless/ath/ath12k/mac.c
+++ b/drivers/net/wireless/ath/ath12k/mac.c
@@ -4377,9 +4377,8 @@ ath12k_mac_op_change_vif_links(struct ieee80211_hw *hw,
struct ieee80211_bss_conf *ol[IEEE80211_MLD_MAX_NUM_LINKS])
{
struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(vif);
- unsigned long to_remove = old_links & ~new_links;
- unsigned long to_add = ~old_links & new_links;
struct ath12k_hw *ah = ath12k_hw_to_ah(hw);
+ unsigned long to_remove, to_add;
struct ath12k_link_vif *arvif;
u8 link_id;

@@ -4389,14 +4388,15 @@ ath12k_mac_op_change_vif_links(struct ieee80211_hw *hw,
"mac vif link changed for MLD %pM old_links 0x%x new_links 0x%x\n",
vif->addr, old_links, new_links);

- for_each_set_bit(link_id, &to_add, IEEE80211_MLD_MAX_NUM_LINKS) {
- arvif = wiphy_dereference(hw->wiphy, ahvif->link[link_id]);
- /* mac80211 wants to add link but driver already has the
- * link. This should not happen ideally.
- */
- if (WARN_ON(arvif))
- return -EINVAL;
+ /*
+ * Link objects follow vif->valid_links, which mac80211 updates before
+ * calling us. old_links/new_links only describe the active links and
+ * must not be used to decide object lifetime.
+ */
+ to_add = vif->valid_links & ~ahvif->links_map;
+ to_remove = ahvif->links_map & ~vif->valid_links;

+ for_each_set_bit(link_id, &to_add, IEEE80211_MLD_MAX_NUM_LINKS) {
arvif = ath12k_mac_assign_link_vif(ah, vif, link_id);
if (WARN_ON(!arvif))
return -EINVAL;
--
2.34.1