The mt76 queue ops take ownership of the skb handed to tx_queue_skb(): the DMA implementation releases it through ieee80211_tx_status_ext() on every error path, and the USB implementation was changed to do the same by commit 82856da2d3b6 ("wifi: mt76: fix memory leak in USB TX path"). mt76s_tx_queue_skb() still returns -ENOSPC without releasing the skb. The queue full check runs before tx_prepare_skb(), so no pktid has been registered in wcid->pktid at that point; the skb only has to be completed through ieee80211_tx_status_ext(), which also frees it. Release the skb on the queue full path as well. Fixes: d39b52e31aa6 ("mt76: introduce mt76_sdio module") Cc: stable@vger.kernel.org Signed-off-by: Wentao Liang --- Changes in v2: - Sorry for the long delay in following up. - Rebased on v7.4-rc1 and dropped the USB hunk, which is already fixed by 82856da2d3b6 ("wifi: mt76: fix memory leak in USB TX path"). - Dropped the tx_prepare_skb() hunk, which is already fixed by 808f2767d421 ("wifi: mt76: mt792x: Fix memory leak in SDIO TX path"). - Only the tx queue full path is handled now. Disclosure: the candidate was found with our static analysis tooling, and the audit and the fix were assisted by DeepSeek and GPT 6.1 sol. drivers/net/wireless/mediatek/mt76/sdio.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/sdio.c b/drivers/net/wireless/mediatek/mt76/sdio.c index ba5f123f7e39..c59553b29df3 100644 --- a/drivers/net/wireless/mediatek/mt76/sdio.c +++ b/drivers/net/wireless/mediatek/mt76/sdio.c @@ -530,18 +530,15 @@ mt76s_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, int err, len = skb->len; u16 idx = q->head; - if (q->queued == q->ndesc) - return -ENOSPC; + if (q->queued == q->ndesc) { + err = -ENOSPC; + goto free_skb; + } skb->prev = skb->next = NULL; err = dev->drv->tx_prepare_skb(dev, NULL, qid, wcid, sta, &tx_info); - if (err < 0) { - status.skb = tx_info.skb; - spin_lock_bh(&dev->rx_lock); - ieee80211_tx_status_ext(dev->hw, &status); - spin_unlock_bh(&dev->rx_lock); - return err; - } + if (err < 0) + goto free_skb; q->entry[q->head].skb = tx_info.skb; q->entry[q->head].buf_sz = len; @@ -553,6 +550,14 @@ mt76s_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q, q->queued++; return idx; + +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); + + return err; } static int -- 2.34.1