Skip to contentSkip to conversation

net: usb: rtl8150: fix memory leak on usb_submit_urb() failure

PATCH In review Deepakkumar Karn 2 participants 2 messages Dec 16, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: usb: rtl8150: fix memory leak on usb_submit_urb() failure

In async_set_registers(), when usb_submit_urb() fails, the allocated async_req structure and URB are not freed, causing a memory leak.

The completion callback async_set_reg_cb() is responsible for freeing these allocations, but it is only called after the URB is successfully submitted and completes (successfully or with error). If submission fails, the callback never runs and the memory is leaked.

Fix this by freeing both the URB and the request structure in the error path when usb_submit_urb() fails.

Reported-by [email protected]
Fixes 4d12997a9bb3 ("drivers: net: usb: rtl8150: concurrent URB bugfix")
---
 drivers/net/usb/rtl8150.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/usb/rtl8150.c +2 -0
index 278e6cb6f4d9..e40b0669d9f4 100644
@@ -211,6 +211,8 @@ static int async_set_registers(rtl8150_t *dev, u16 indx, u16 size, u16 reg)
 		if (res == -ENODEV)
 			netif_device_detach(dev->netdev);
 		dev_err(&dev->udev->dev, "%s failed with %d\n", __func__, res);
+		kfree(req);
+		usb_free_urb(async_urb);
 	}
 	return res;
 }
Signature · 1 line
2.52.0
maintainer
#1 lore raw
Quoted 34 lines · Deepakkumar Karn

In async_set_registers(), when usb_submit_urb() fails, the allocated async_req structure and URB are not freed, causing a memory leak.

The completion callback async_set_reg_cb() is responsible for freeing these allocations, but it is only called after the URB is successfully submitted and completes (successfully or with error). If submission fails, the callback never runs and the memory is leaked.

Fix this by freeing both the URB and the request structure in the error path when usb_submit_urb() fails.

Reported-by [email protected]
Fixes 4d12997a9bb3 ("drivers: net: usb: rtl8150: concurrent URB bugfix")
---
 drivers/net/usb/rtl8150.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/usb/rtl8150.c +2 -0
index 278e6cb6f4d9..e40b0669d9f4 100644
@@ -211,6 +211,8 @@ static int async_set_registers(rtl8150_t *dev, u16 indx, u16 size, u16 reg)
 		if (res == -ENODEV)
 			netif_device_detach(dev->netdev);
 		dev_err(&dev->udev->dev, "%s failed with %d\n", __func__, res);
+		kfree(req);
+		usb_free_urb(async_urb);
 	}
 	return res;
 }
Signature · 1 line
2.52.0

ACK.

Nice catch. This bug has been lurking for a very long time... :)

cheers,
Petko