FAILED: patch "[PATCH] wifi: mt76: fix memory leak in USB TX path" failed to apply to 5.10-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 82856da2d3b6a30011f4db6ea5f34c13484e0ef8
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 82856da2d3b6a30011f4db6ea5f34c13484e0ef8 Mon Sep 17 00:00:00 2001
From: Eason Lai <[email protected]>
Date: Mon, 14 Sep 2026 10:19:20 +0800
Subject: [PATCH] wifi: mt76: fix memory leak in USB TX path
When errors occur in mt76u_tx_queue_skb(), the skb is not properly freed, leading to memory leaks. This happens when:
- The queue is full
- tx_prepare_skb() drops zero-length frames (such as WMM NULL frames) to prevent hardware TX hangs
- Buffer setup fails
Fix by properly releasing the skb with ieee80211_tx_status_ext() when the queue is full or tx_prepare_skb() fails, and using mt76_tx_complete_skb() when mt76u_tx_setup_buffers() fails (since tx_prepare_skb() has already succeeded and may have allocated resources that need cleanup)
--- drivers/net/wireless/mediatek/mt76/usb.c | 31 ++++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/usb.c +26 -5
@@ -893,6 +893,9 @@ mt76u_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, enum mt76_txq_id qid, struct sk_buff *skb, struct mt76_wcid *wcid, struct ieee80211_sta *sta) { + struct ieee80211_tx_status status = { + .sta = sta, + };struct mt76_tx_info tx_info = { .skb = skb, };
@@ -900,17 +903,27 @@ mt76u_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q,u16 idx = q->head;int err; -if (q->queued == q->ndesc) -return -ENOSPC ; +if (q->queued == q->ndesc) { + err = -ENOSPC ; + goto err_free_skb; + } skb->prev = skb->next =NULL ; err = dev->drv->tx_prepare_skb (dev,NULL , qid, wcid, sta, &tx_info);if (err <0 ) -return err; + goto err_free_skb; err =mt76u_tx_setup_buffers (dev, tx_info.skb, q->entry[idx].urb); -if (err <0 ) -return err; +if (err <0 ) { +/* +* mt76_tx_status_skb_get() walks the idr and dereferences +* a freed skb. This SKB is not counted in non-AQL counter +* due to error return, so using 0xffff as wcid to keep +* balanced. +*/ +mt76_tx_complete_skb (dev,0xffff , tx_info.skb); + goto err_ret; + }mt76u_fill_bulk_urb (dev,USB_DIR_OUT , q->ep, q->entry[idx].urb, mt76u_complete_tx, &q->entry[idx]);
@@ -921,6 +934,14 @@ mt76u_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, q->queued++;return idx; + +err_free_skb: + status.skb = tx_info.skb; +spin_lock_bh (&dev->rx_lock); +ieee80211_tx_status_ext (dev->hw, &status); +spin_unlock_bh (&dev->rx_lock); +err_ret: +return err; }static void mt76u_tx_kick (struct mt76_dev *dev,struct mt76_queue *q)
Signature · 1 line
2.53.0