drivers: usb: host: fix prevent memory leak in interrupt message submission
Subsystems (2)
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
@@ -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);return -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
Quoted 16 lines · On Fri, May 16, 2025 at 08:54:34PM +0300, [email protected] wrote:
From: Anton Moryakov <[email protected]>
Ensure
int_queueis properly destroyed when receiving wrong buffer by adding error handling path. Fixes memory leak that occurred when backbuffer validation failed.Signed-off-by Anton Moryakov <[email protected]>--- drivers/usb/host/ehci-hcd.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/usb/host/ehci-hcd.c +0
-0
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@@ -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);return -EINVAL ; + goto err;
A goto after return cannot be right, and should have had some compiler warnings too.
Signature · 1 line
Tom
Thanks Tom — you're right, that goto after return is unreachable. I'll fix that and resend with the corrected flow.
пт, 16 мая 2025 г. в 21:31, Tom Rini <[email protected]>:
Quoted 30 lines · On Fri, May 16, 2025 at 08:54:34PM +0300, [email protected] wrote:
drivers/usb/host/ehci-hcd.c static int _ehci_submit_int_msg(struct usb_device
Quoted 17 lines
From: Anton Moryakov <[email protected]>
Ensure
int_queueis properly destroyed when receiving wrong buffer by adding error handling path. Fixes memory leak that occurred when backbuffer validation failed.Signed-off-by Anton Moryakov <[email protected]>--- drivers/usb/host/ehci-hcd.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/usb/host/ehci-hcd.c +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
-0debug ("got wrong buffer back (%p instead of %p)\n" , backbuffer, buffer);return -EINVAL ; + goto err;A goto after return cannot be right, and should have had some compiler warnings too.
--
Tom
Quoted 2 lines · Anton Moryakov
Thanks Tom — you're right, that
gotoafterreturnis unreachable. I'll fix that and resend with the corrected flow.
OK. Please make sure that for all of the patches you're posting, you're not adding warnings. You can enable CONFIG_WERROR to make the easier.
Signature · 1 line
Tom