Skip to contentSkip to conversation

usb: misc: usbio: Fix URB memory leak on submit failure

PATCH In review Felix Gu 3 participants 3 messages Mar 31 – Apr 1

Subsystems (2)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH v2 1/1 usb: misc: usbio: Fix URB memory leak on submit failure

When usb_submit_urb() fails in usbio_probe(), the previously allocated URB is never freed, causing a memory leak.

Fix this by jumping to err_free_urb label to properly release the URB on the error path.

Fixes 121a0f839dbb ("usb: misc: Add Intel USBIO bridge driver")

---
Changes in v2:
- Fix Oliver's comment.
- Link to v1: https://lore.kernel.org/lkml/[email protected]

---
 drivers/usb/misc/usbio.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/misc/usbio.c +5 -2
index 2e68d48a2cc0..02d1e0760f0c 100644
@@ -614,8 +614,10 @@ static int usbio_probe(struct usb_interface *intf, const struct usb_device_id *i
 	usb_fill_bulk_urb(usbio->urb, udev, usbio->rx_pipe, usbio->rxbuf,
 			  usbio->rxbuf_len, usbio_bulk_recv, usbio);
 	ret = usb_submit_urb(usbio->urb, GFP_KERNEL);
-	if (ret)
-		return dev_err_probe(dev, ret, "Submitting usb urb\n");
+	if (ret) {
+		dev_err_probe(dev, ret, "Submitting usb urb\n");
+		goto err_free_urb;
+	}
 
 	mutex_lock(&usbio->ctrl_mutex);
 
@@ -663,6 +665,7 @@ static int usbio_probe(struct usb_interface *intf, const struct usb_device_id *i
 err_unlock:
 	mutex_unlock(&usbio->ctrl_mutex);
 	usb_kill_urb(usbio->urb);
+err_free_urb:
 	usb_free_urb(usbio->urb);
 
 	return ret;

---
base-commit: 3b058d1aeeeff27a7289529c4944291613b364e9
change-id: 20260330-usbio-d70e15c97a7a

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Felix Gu

When usb_submit_urb() fails in usbio_probe(), the previously allocated URB is never freed, causing a memory leak.

Fix this by jumping to err_free_urb label to properly release the URB on the error path.

Fixes 121a0f839dbb ("usb: misc: Add Intel USBIO bridge driver")
maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Felix Gu

Hi,

Quoted 6 lines · Felix Gu

When usb_submit_urb() fails in usbio_probe(), the previously allocated URB is never freed, causing a memory leak.

Fix this by jumping to err_free_urb label to properly release the URB on the error path.

Quoted 6 lines
Fixes 121a0f839dbb ("usb: misc: Add Intel USBIO bridge driver")

---
Changes in v2:
- Fix Oliver's comment.
- Link to v1: https://lore.kernel.org/lkml/[email protected]

Thanks, patch looks good to me:

Regards,

Hans

Quoted 35 lines
---
 drivers/usb/misc/usbio.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/misc/usbio.c +5 -3
index 2e68d48a2cc0..02d1e0760f0c 100644
@@ -614,8 +614,10 @@ static int usbio_probe(struct usb_interface *intf, const struct usb_device_id *i
 	usb_fill_bulk_urb(usbio->urb, udev, usbio->rx_pipe, usbio->rxbuf,
 			  usbio->rxbuf_len, usbio_bulk_recv, usbio);
 	ret = usb_submit_urb(usbio->urb, GFP_KERNEL);
-	if (ret)
-		return dev_err_probe(dev, ret, "Submitting usb urb\n");
+	if (ret) {
+		dev_err_probe(dev, ret, "Submitting usb urb\n");
+		goto err_free_urb;
+	}
 
 	mutex_lock(&usbio->ctrl_mutex);
 
@@ -663,6 +665,7 @@ static int usbio_probe(struct usb_interface *intf, const struct usb_device_id *i
 err_unlock:
 	mutex_unlock(&usbio->ctrl_mutex);
 	usb_kill_urb(usbio->urb);
+err_free_urb:
 	usb_free_urb(usbio->urb);
 
 	return ret;
 
---

base-commit: 3b058d1aeeeff27a7289529c4944291613b364e9
change-id: 20260330-usbio-d70e15c97a7a

Best regards,