]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
wifi: rtw88: usb: fix memory leaks on USB write failures
authorLuka Gejak <luka.gejak@linux.dev>
Mon, 18 May 2026 14:23:11 +0000 (16:23 +0200)
committerPing-Ke Shih <pkshih@realtek.com>
Mon, 25 May 2026 06:33:43 +0000 (14:33 +0800)
commit6b964941bbfe6e0f18b1a5e008486dbb62df440a
tree8b275f9d4659352054e678e063522839fe3c19ce
parentc80788f7c5aed8d420366b821f867a8a353d83a5
wifi: rtw88: usb: fix memory leaks on USB write failures

When rtw_usb_write_port() fails to submit a USB Request Block (URB)
(e.g., due to device disconnect or ENOMEM), the completion callback is
never executed.

Currently, the driver ignores the return value of rtw_usb_write_port()
in rtw_usb_write_data() and rtw_usb_tx_agg_skb(). Because these
functions rely on the completion callback to free the socket buffers
(skbs) and the transaction control block (txcb), a submission failure
results in:
1. A memory leak of the allocated skb in rtw_usb_write_data().
2. A memory leak of the txcb structure and all aggregated skbs in
   rtw_usb_tx_agg_skb().

Fix this by checking the return value of rtw_usb_write_port(). If it
fails, explicitly free the skb in rtw_usb_write_data(), and properly
purge the tx_ack_queue and free the txcb in rtw_usb_tx_agg_skb().

The issue was discovered in practice during device disconnect/reconnect
scenarios and memory pressure conditions. Tested by verifying normal TX
operation continues after the fix without regressions.

Fixes: a82dfd33d123 ("wifi: rtw88: Add common USB chip support")
Cc: stable@vger.kernel.org
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
Tested-by: Luka Gejak <luka.gejak@linux.dev>
Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Link: https://patch.msgid.link/20260518142311.10328-2-luka.gejak@linux.dev
drivers/net/wireless/realtek/rtw88/usb.c