[PATCH] most: usb: fix memory leak on most_register_interface failure

From: Zhao Dongdong

Date: Wed Jun 17 2026 - 04:41:40 EST


From: Zhao Dongdong <zhaodongdong@xxxxxxxxxx>

In hdm_probe(), when most_register_interface() fails, the function returns
the error code directly without freeing the previously allocated memory
(mdev->busy_urbs, mdev->ep_address, mdev->cap, mdev->conf, and mdev).

Add an err_free_busy_urbs label and use goto to properly clean up all
allocated resources on failure.

Fixes: 97a6f772f36b ("drivers: most: add USB adapter driver")
Signed-off-by: Zhao Dongdong <zhaodongdong@xxxxxxxxxx>
---
drivers/most/most_usb.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/most/most_usb.c b/drivers/most/most_usb.c
index 6437733afee0..c20901e1ce6c 100644
--- a/drivers/most/most_usb.c
+++ b/drivers/most/most_usb.c
@@ -1056,7 +1056,7 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)

ret = most_register_interface(&mdev->iface);
if (ret)
- return ret;
+ goto err_free_busy_urbs;

mutex_lock(&mdev->io_mutex);
if (le16_to_cpu(usb_dev->descriptor.idProduct) == USB_DEV_ID_OS81118 ||
@@ -1084,6 +1084,8 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
mutex_unlock(&mdev->io_mutex);
return 0;

+err_free_busy_urbs:
+ kfree(mdev->busy_urbs);
err_free_ep_address:
kfree(mdev->ep_address);
err_free_cap:
--
2.25.1