In host mode, omap2430_musb_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: 1a35526e1d54 ("usb: musb-new: omap2430: Enable DM_USB and OF support")
Signed-off-by: Yuho Choi <[email protected]>
---
Build-tested only, with omap3_evm_defconfig and CONFIG_USB_MUSB_HOST=y.

omap2430_musb_remove() does not free the struct musb either; that is
not changed here.

 drivers/usb/musb-new/omap2430.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/musb-new/omap2430.c b/drivers/usb/musb-new/omap2430.c
index c8c6bf0c84f..c5607fd388e 100644
--- a/drivers/usb/musb-new/omap2430.c
+++ b/drivers/usb/musb-new/omap2430.c
@@ -229,7 +229,11 @@ static int omap2430_musb_probe(struct udevice *dev)
                if (!host->host)
                        return -EIO;
 
-               return musb_lowlevel_init(host);
+               ret = musb_lowlevel_init(host);
+               if (ret)
+                       free(host->host);
+
+               return ret;
        } else if (CONFIG_IS_ENABLED(DM_USB_GADGET)) {
                struct musb_host_data *host = dev_get_priv(dev);
 
-- 
2.43.0

Reply via email to