mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] wifi: ti: unwind failed interface additions
@ 2026-10-19  1:32 Jiale Yao
  2026-10-19  1:32 ` [PATCH 1/2] wifi: wl1251: " Jiale Yao
  2026-10-19  1:32 ` [PATCH 2/2] wifi: wlcore: " Jiale Yao
  0 siblings, 2 replies; 3+ messages in thread
From: Jiale Yao @ 2026-10-19  1:32 UTC (permalink / raw)
  To: Bob Copeland, John W. Linville, Kalle Valo, linux-wireless, linux-kernel
  Cc: Jiale Yao

mac80211 does not call remove_interface after add_interface returns an
error. Both wl1251 and wlcore retain state or resources acquired before
fallible setup operations, so a failed add can affect later interface
requests or leak firmware and host resources.

Make both add paths failure-atomic. The first patch delays publication
of the wl1251 vif and restores the previous interface state. The second
patch releases wlcore per-vif allocations and disables firmware roles
when later setup fails.

Jiale Yao (2):
  wifi: wl1251: unwind failed interface additions
  wifi: wlcore: unwind failed interface additions

 drivers/net/wireless/ti/wl1251/main.c | 17 +++++--
 drivers/net/wireless/ti/wlcore/main.c | 66 +++++++++++++++++----------
 2 files changed, 56 insertions(+), 27 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] wifi: wl1251: unwind failed interface additions
  2026-10-19  1:32 [PATCH 0/2] wifi: ti: unwind failed interface additions Jiale Yao
@ 2026-10-19  1:32 ` Jiale Yao
  2026-10-19  1:32 ` [PATCH 2/2] wifi: wlcore: " Jiale Yao
  1 sibling, 0 replies; 3+ messages in thread
From: Jiale Yao @ 2026-10-19  1:32 UTC (permalink / raw)
  To: Bob Copeland, John W. Linville, Kalle Valo, linux-wireless, linux-kernel
  Cc: Jiale Yao

wl1251 stores the vif and updates interface state before validating the
type and programming a changed station address. Failures leave the vif
installed even though mac80211 will not invoke remove_interface.

Publish the vif only after all fallible setup succeeds and restore the
previous BSS and address state on failure.

Fixes: 2f01a1f58889 ("wl12xx: add driver")
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
 drivers/net/wireless/ti/wl1251/main.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/ti/wl1251/main.c b/drivers/net/wireless/ti/wl1251/main.c
index 0f3f22e729ce..306dd6379931 100644
--- a/drivers/net/wireless/ti/wl1251/main.c
+++ b/drivers/net/wireless/ti/wl1251/main.c
@@ -481,6 +481,8 @@ static int wl1251_op_add_interface(struct ieee80211_hw *hw,
 				   struct ieee80211_vif *vif)
 {
 	struct wl1251 *wl = hw->priv;
+	u8 old_mac_addr[ETH_ALEN];
+	u8 old_bss_type;
 	int ret = 0;
 
 	vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
@@ -496,7 +498,8 @@ static int wl1251_op_add_interface(struct ieee80211_hw *hw,
 		goto out;
 	}
 
-	wl->vif = vif;
+	memcpy(old_mac_addr, wl->mac_addr, ETH_ALEN);
+	old_bss_type = wl->bss_type;
 
 	switch (vif->type) {
 	case NL80211_IFTYPE_STATION:
@@ -507,7 +510,7 @@ static int wl1251_op_add_interface(struct ieee80211_hw *hw,
 		break;
 	default:
 		ret = -EOPNOTSUPP;
-		goto out;
+		goto restore;
 	}
 
 	if (!ether_addr_equal_unaligned(wl->mac_addr, vif->addr)) {
@@ -515,9 +518,17 @@ static int wl1251_op_add_interface(struct ieee80211_hw *hw,
 		SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
 		ret = wl1251_acx_station_id(wl);
 		if (ret < 0)
-			goto out;
+			goto restore;
 	}
 
+	wl->vif = vif;
+	goto out;
+
+restore:
+	wl->bss_type = old_bss_type;
+	memcpy(wl->mac_addr, old_mac_addr, ETH_ALEN);
+	SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
+
 out:
 	mutex_unlock(&wl->mutex);
 	return ret;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] wifi: wlcore: unwind failed interface additions
  2026-10-19  1:32 [PATCH 0/2] wifi: ti: unwind failed interface additions Jiale Yao
  2026-10-19  1:32 ` [PATCH 1/2] wifi: wl1251: " Jiale Yao
@ 2026-10-19  1:32 ` Jiale Yao
  1 sibling, 0 replies; 3+ messages in thread
From: Jiale Yao @ 2026-10-19  1:32 UTC (permalink / raw)
  To: Bob Copeland, John W. Linville, Kalle Valo, linux-wireless, linux-kernel
  Cc: Jiale Yao

wl12xx_init_vif_data() allocates per-interface host resources before
firmware setup. Later failures return without releasing those resources,
and failures after role enablement also leave the firmware role active
because mac80211 does not call remove_interface.

Factor the per-vif resource release into a helper, use it from removal
and add failure paths, and disable an enabled role when subsequent
initialization fails.

Fixes: 2f01a1f58889 ("wl12xx: add driver")
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
 drivers/net/wireless/ti/wlcore/main.c | 66 +++++++++++++++++----------
 1 file changed, 42 insertions(+), 24 deletions(-)

diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
index 26aabf4ea127..9a0350b9d280 100644
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -2374,6 +2374,30 @@ static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
 	return 0;
 }
 
+static void wl12xx_deinit_vif_data(struct wl1271 *wl,
+				   struct wl12xx_vif *wlvif)
+{
+	int i;
+
+	if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
+	    wlvif->bss_type == BSS_TYPE_IBSS) {
+		wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
+		wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
+		wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
+		wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
+		wlcore_free_klv_template(wl, &wlvif->sta.klv_template_id);
+	} else {
+		wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
+		wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
+		wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
+		wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
+		for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
+			wl12xx_free_rate_policy(wl,
+						&wlvif->ap.ucast_rate_idx[i]);
+		wl1271_free_ap_keys(wl, wlvif);
+	}
+}
+
 static int wl12xx_init_fw(struct wl1271 *wl)
 {
 	struct wlcore_platdev_data *pdev_data = dev_get_platdata(&wl->pdev->dev);
@@ -2633,12 +2657,12 @@ static int wl1271_op_add_interface(struct ieee80211_hw *hw,
 	role_type = wl12xx_get_role_type(wl, wlvif);
 	if (role_type == WL12XX_INVALID_ROLE_TYPE) {
 		ret = -EINVAL;
-		goto out_unlock;
+		goto out_deinit;
 	}
 
 	ret = wlcore_allocate_hw_queue_base(wl, wlvif);
 	if (ret < 0)
-		goto out_unlock;
+		goto out_deinit;
 
 	/*
 	 * TODO: after the nvs issue will be solved, move this block
@@ -2653,7 +2677,7 @@ static int wl1271_op_add_interface(struct ieee80211_hw *hw,
 
 		ret = wl12xx_init_fw(wl);
 		if (ret < 0)
-			goto out_unlock;
+			goto out_deinit;
 	}
 
 	/*
@@ -2662,7 +2686,7 @@ static int wl1271_op_add_interface(struct ieee80211_hw *hw,
 	 */
 	ret = pm_runtime_resume_and_get(wl->dev);
 	if (ret < 0)
-		goto out_unlock;
+		goto out_deinit;
 
 	if (wl12xx_need_fw_change(wl, vif_count, true)) {
 		wl12xx_force_active_psm(wl);
@@ -2680,7 +2704,7 @@ static int wl1271_op_add_interface(struct ieee80211_hw *hw,
 
 		ret = wl1271_init_vif_specific(wl, vif);
 		if (ret < 0)
-			goto out;
+			goto out_disable_role;
 
 	} else {
 		ret = wl12xx_cmd_role_enable(wl, vif->addr, WL1271_ROLE_DEVICE,
@@ -2691,7 +2715,7 @@ static int wl1271_op_add_interface(struct ieee80211_hw *hw,
 		/* needed mainly for configuring rate policies */
 		ret = wl1271_sta_hw_init(wl, wlvif);
 		if (ret < 0)
-			goto out;
+			goto out_disable_role;
 	}
 
 	list_add(&wlvif->list, &wl->wlvif_list);
@@ -2701,8 +2725,18 @@ static int wl1271_op_add_interface(struct ieee80211_hw *hw,
 		wl->ap_count++;
 	else
 		wl->sta_count++;
+	goto out;
+
+out_disable_role:
+	if (!wlcore_is_p2p_mgmt(wlvif))
+		wl12xx_cmd_role_disable(wl, &wlvif->role_id);
+	else
+		wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
 out:
 	pm_runtime_put_autosuspend(wl->dev);
+out_deinit:
+	if (ret)
+		wl12xx_deinit_vif_data(wl, wlvif);
 out_unlock:
 	mutex_unlock(&wl->mutex);
 
@@ -2714,7 +2748,7 @@ static void __wl1271_op_remove_interface(struct wl1271 *wl,
 					 bool reset_tx_queues)
 {
 	struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-	int i, ret;
+	int ret;
 	bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
 
 	wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
@@ -2789,23 +2823,7 @@ static void __wl1271_op_remove_interface(struct wl1271 *wl,
 	/* clear all hlids (except system_hlid) */
 	wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
 
-	if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
-	    wlvif->bss_type == BSS_TYPE_IBSS) {
-		wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
-		wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
-		wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
-		wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
-		wlcore_free_klv_template(wl, &wlvif->sta.klv_template_id);
-	} else {
-		wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
-		wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
-		wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
-		wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
-		for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
-			wl12xx_free_rate_policy(wl,
-						&wlvif->ap.ucast_rate_idx[i]);
-		wl1271_free_ap_keys(wl, wlvif);
-	}
+	wl12xx_deinit_vif_data(wl, wlvif);
 
 	dev_kfree_skb(wlvif->probereq);
 	wlvif->probereq = NULL;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-19  1:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-19  1:32 [PATCH 0/2] wifi: ti: unwind failed interface additions Jiale Yao
2026-10-19  1:32 ` [PATCH 1/2] wifi: wl1251: " Jiale Yao
2026-10-19  1:32 ` [PATCH 2/2] wifi: wlcore: " Jiale Yao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®