Skip to contentSkip to conversation

drivers: usb: host: fix prevent memory leak in interrupt message submission

PATCH Superseded [email protected] 2 participants 3 messages May 16, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: usb: host: fix prevent memory leak in interrupt message submission

From: Anton Moryakov <[email protected]>

Ensure int_queue is properly destroyed when receiving wrong buffer by adding error handling path. Fixes memory leak that occurred when backbuffer validation failed.

---
 drivers/usb/host/ehci-hcd.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/usb/host/ehci-hcd.c +5 -0
index 7d5519c65a9..765d8b327ee 100644
@@ -1557,6 +1557,7 @@ static int _ehci_submit_int_msg(struct usb_device *dev, unsigned long pipe,
 		debug("got wrong buffer back (%p instead of %p)\n",
 		      backbuffer, buffer);
 		result = -EINVAL;
+		goto err;
 	}
 
 	ret = _ehci_destroy_int_queue(dev, queue);
@@ -1565,6 +1566,10 @@ static int _ehci_submit_int_msg(struct usb_device *dev, unsigned long pipe,
 
 	/* everything worked out fine */
 	return result;
+	
+err:
+    _ehci_destroy_int_queue(dev, queue);  // Освобождаем очередь перед выходом
+    return result;
 }
 
 static int _ehci_lock_async(struct ehci_ctrl *ctrl, int lock)
Signature · 1 line
2.30.2
#1 lore raw

drivers/usb/host/ehci-hcd.c static int _ehci_submit_int_msg(struct usb_device *dev, unsigned long pipe, · line 1560

Quoted 5 lines · On Fri, May 16, 2025 at 4:43 PM <[email protected]> wrote:
drivers/usb/host/ehci-hcd.c +1 -0
@@ -1557,6 +1557,7 @@ static int _ehci_submit_int_msg(struct usb_device *dev, unsigned long pipe,
                debug("got wrong buffer back (%p instead of %p)\n",
                      backbuffer, buffer);
                result = -EINVAL;
+               goto err;

Was this supposed to be a v2? The error Tim pointed out is still here.

     ret = _ehci_destroy_int_queue(dev, queue);

drivers/usb/host/ehci-hcd.c static int _ehci_submit_int_msg(struct usb_device *dev, unsigned long pipe, · line 1571

Quoted 7 lines
drivers/usb/host/ehci-hcd.c +3 -0
@@ -1565,6 +1566,10 @@ static int _ehci_submit_int_msg(struct usb_device *dev, unsigned long pipe,
 
        /* everything worked out fine */
        return result;
+
+err:
+    _ehci_destroy_int_queue(dev, queue);  // Освобождаем очередь перед выходом

Please remove the comment.

#2 lore raw

Hi Fabio,

Thanks for the review. Yes, this is v2 — the issue Tom pointed out (unreachable goto after return) was fixed by replacing it with result = -EINVAL; goto err;.

In v3 I’ve now removed the leftover comment. No other functional changes.

Best regards,
Anton

пт, 16 мая 2025 г. в 22:59, Fabio Estevam <[email protected]>:

Quoted 24 lines · On Fri, May 16, 2025 at 4:43 PM <[email protected]> wrote:

Review static int _ehci_submit_int_msg(struct usb_device

Quoted 2 lines
(quoted diff) +0 -0
@@ -1557,6 +1557,7 @@ static int _ehci_submit_int_msg(struct usb_device

*dev, unsigned long pipe,

drivers/usb/host/ehci-hcd.c static int _ehci_submit_int_msg(struct usb_device *dev, unsigned long pipe, · line 1560

Quoted 4 lines
drivers/usb/host/ehci-hcd.c +1 -0
                debug("got wrong buffer back (%p instead of %p)\n",
                      backbuffer, buffer);
                result = -EINVAL;
+               goto err;

Was this supposed to be a v2? The error Tim pointed out is still here.

     ret = _ehci_destroy_int_queue(dev, queue);

Review static int _ehci_submit_int_msg(struct usb_device

Quoted 1 line
(quoted diff) +0 -0
@@ -1565,6 +1566,10 @@ static int _ehci_submit_int_msg(struct usb_device

*dev, unsigned long pipe,

drivers/usb/host/ehci-hcd.c static int _ehci_submit_int_msg(struct usb_device *dev, unsigned long pipe,

Quoted 6 lines
drivers/usb/host/ehci-hcd.c +3 -0
        /* everything worked out fine */
        return result;
+
+err:
+    _ehci_destroy_int_queue(dev, queue);  // Освобождаем очередь перед

выходом

Please remove the comment.