usb: musb-new: mt85xx: Free the controller if the host probe fails
Subsystems (2)
PATCH 1/1 usb: musb-new: mt85xx: 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.
Free the struct musb when musb_lowlevel_init() fails.
---
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(+)
drivers/usb/musb-new/mt85xx.c +2 -0
@@ -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
Signature · 1 line
2.43.0
Quoted 23 lines · Yuho Choi
In host mode,
musb_usb_probe()allocates the struct musb withmusb_init_controller()and returns the error whenmusb_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 <[email protected]>---
Build-tested only, withmt8518_ap1_emmc_defconfigandCONFIG_USB_MUSB_HOST=y.drivers/usb/musb-new/mt85xx.c | 2 ++ 1 file changed, 2 insertions(+)drivers/usb/musb-new/mt85xx.c +0
-0
drivers/usb/musb-new/mt85xx.c static int musb_usb_probe(struct udevice *dev) · line 372
Quoted 8 lines
drivers/usb/musb-new/mt85xx.c +2
-0@@ -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);
As your test notes, nothing builds like this normally today. And in the failure case we have more to worry about than just a resource leak. We shouldn't bother doing this until someone is going to handle the error case correctly.
Signature · 1 line
Tom