usb: musb-new: sunxi: Free the controller if the host probe fails
Subsystems (2)
PATCH 1/1 usb: musb-new: sunxi: Free the controller if the host probe fails
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.
---
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(+)
drivers/usb/musb-new/sunxi.c +2 -0
@@ -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
Signature · 1 line
2.43.0