Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH] rtlwifi: usb: Fix a memory leak on URB submission failure
@ 2026-11-30  6:04 Wanhui Fu
  2026-11-30  7:20 ` Ping-Ke Shih
  0 siblings, 1 reply; 2+ messages in thread
From: Wanhui Fu @ 2026-11-30  6:04 UTC (permalink / raw)
  To: pkshih, linville, jussi.kivilinna; +Cc: linux-wireless, Wanhui Fu

_rtl_prep_rx_urb() allocates a buffer. If usb_submit_urb()
fails, this buffer is not anchored in rx_cleanup_urbs,
thus no cleaup callback invoked, casuing a memory leak.

Free the coherent buffer before freeing the URB on this
error path.

Found it by a self-developed static analysis tool and
compile-test passed.

Fixes: 872de8ff0492 ("rtlwifi: usb: use usb_alloc_coherent for RX buffers")
Signed-off-by: Wanhui Fu <fuwh1120@163.com>
---
 drivers/net/wireless/realtek/rtlwifi/usb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtlwifi/usb.c b/drivers/net/wireless/realtek/rtlwifi/usb.c
index d013e5986948..2119cb3086ed 100644
--- a/drivers/net/wireless/realtek/rtlwifi/usb.c
+++ b/drivers/net/wireless/realtek/rtlwifi/usb.c
@@ -666,6 +666,8 @@ static int _rtl_usb_receive(struct ieee80211_hw *hw)
 		err = usb_submit_urb(urb, GFP_KERNEL);
 		if (err) {
 			usb_unanchor_urb(urb);
+			usb_free_coherent(urb->dev, urb->transfer_buffer_length,
+					  urb->transfer_buffer, urb->transfer_dma);
 			usb_free_urb(urb);
 			goto err_out;
 		}
-- 
2.25.1


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

end of thread, other threads:[~2026-11-30  7:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  6:04 [PATCH] rtlwifi: usb: Fix a memory leak on URB submission failure Wanhui Fu
2026-11-30  7:20 ` Ping-Ke Shih

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