Skip to contentSkip to conversation

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

PATCH New [email protected] 1 participant 1 message May 16, 2025

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

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

From: AntonMoryakov <[email protected]>

Static analyzer detected a potential memory leak in _ehci_submit_int_msg() when backbuffer returned from _ehci_poll_int_queue does not match the original buffer. In this case, the allocated interrupt queue was not destroyed before returning, leading to a memory leak.

Correction:
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 | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/usb/host/ehci-hcd.c +6 -1
index 7d5519c65a9..75cd0ec71ed 100644
@@ -1556,7 +1556,8 @@ static int _ehci_submit_int_msg(struct usb_device *dev, unsigned long pipe,
 	if (backbuffer != buffer) {
 		debug("got wrong buffer back (%p instead of %p)\n",
 		      backbuffer, buffer);
-		return -EINVAL;
+		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.34.1