U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
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: sunxi: Free the controller if the host probe fails
Date: Fri,  6 Nov 2026 14:36:13 -0500	[thread overview]
Message-ID: <20261106193635.507619-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.

Commit 7c22e26ec5ba ("sunxi: musb: Re-init musb controller on repeated
probe calls") made the probe call musb_usb_remove() on this error, but
the call was dropped when the driver was converted to driver model.

Free the struct musb when musb_lowlevel_init() fails.

Fixes: 3a61b080acee ("musb: sunxi: switch to the device model")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
Build-tested only, with A33-OLinuXino_defconfig.

When musb_start() fails, as it does when no host cable is detected,
musb_lowlevel_init() returns without calling musb_stop(), so the
platform init done by musb_init_controller() is not undone either. That
is not changed here.

 drivers/usb/musb-new/sunxi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c
index 0747f025f2a..1f1c33a6672 100644
--- a/drivers/usb/musb-new/sunxi.c
+++ b/drivers/usb/musb-new/sunxi.c
@@ -481,6 +481,8 @@ static int musb_usb_probe(struct udevice *dev)
 	ret = musb_lowlevel_init(host);
 	if (!ret)
 		printf("Allwinner 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


                 reply	other threads:[~2026-11-06 21:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261106193635.507619-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox