From: Yuho Choi <oss.patchbox@gmail.com>
To: Marek Vasut <marek.vasut+usb@mailbox.org>
Cc: Tom Rini <trini@konsulko.com>,
u-boot@lists.u-boot-project.org,
Yuho Choi <oss.patchbox@gmail.com>
Subject: [PATCH] usb: musb-new: mt85xx: Free the controller if the host probe fails
Date: Fri, 6 Nov 2026 14:37:52 -0500 [thread overview]
Message-ID: <20261106193807.507911-1-oss.patchbox@gmail.com> (raw)
In host mode, musb_usb_probe() allocates the struct musb with
musb_init_controller() and returns the error when musb_lowlevel_init()
fails, for example when no device is connected. The struct musb is not
freed on this path, and the driver core then frees the private data that
holds the only pointer to it. Each 'usb reset', or 'usb start' after
'usb stop', probes the controller again and leaks another one.
Free the struct musb when musb_lowlevel_init() fails.
Fixes: 7d017d607eaa ("usb: musb-new: mt85xx: add musb-new gadget driver.")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
Build-tested only, with mt8518_ap1_emmc_defconfig and
CONFIG_USB_MUSB_HOST=y.
drivers/usb/musb-new/mt85xx.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/usb/musb-new/mt85xx.c b/drivers/usb/musb-new/mt85xx.c
index 14b28bbae6b..2e13b2a30d8 100644
--- a/drivers/usb/musb-new/mt85xx.c
+++ b/drivers/usb/musb-new/mt85xx.c
@@ -365,6 +365,8 @@ static int musb_usb_probe(struct udevice *dev)
ret = musb_lowlevel_init(host);
if (!ret)
printf("MTK MUSB OTG (Host)\n");
+ else
+ free(host->host);
#else
pdata.mode = MUSB_PERIPHERAL;
host->host = musb_register(&pdata, &glue->dev, base);
base-commit: feb8913982e4462c01fd914271f92254a25dc101
--
2.43.0
next reply other threads:[~2026-11-06 21:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 19:37 Yuho Choi [this message]
2026-11-06 20:52 ` [PATCH] usb: musb-new: mt85xx: Free the controller if the host probe fails Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261106193807.507911-1-oss.patchbox@gmail.com \
--to=oss.patchbox@gmail.com \
--cc=marek.vasut+usb@mailbox.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.