mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: fotg210-udc: fix potential memory leak in fotg210_udc_probe()
@ 2022-11-30 10:12 Yi Yang
  2022-12-01  9:38 ` Andrzej Pietrasiewicz
  2022-12-04 18:19 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Yi Yang @ 2022-11-30 10:12 UTC (permalink / raw)
  To: linus.walleij, gregkh, yiyang13; +Cc: linux-usb, linux-kernel

In fotg210_udc_probe(), if devm_clk_get() or clk_prepare_enable()
fails, 'fotg210' will not be freed, which will lead to a memory leak.
Fix it by moving kfree() to a proper location.

Fixes: 718a38d092ec ("fotg210-udc: Handle PCLK")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
 drivers/usb/fotg210/fotg210-udc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/fotg210/fotg210-udc.c b/drivers/usb/fotg210/fotg210-udc.c
index b9ea6c6d931c..a366d69c1818 100644
--- a/drivers/usb/fotg210/fotg210-udc.c
+++ b/drivers/usb/fotg210/fotg210-udc.c
@@ -1178,7 +1178,7 @@ int fotg210_udc_probe(struct platform_device *pdev)
 		ret = clk_prepare_enable(fotg210->pclk);
 		if (ret) {
 			dev_err(dev, "failed to enable PCLK\n");
-			return ret;
+			goto err;
 		}
 	} else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
 		/*
@@ -1302,8 +1302,7 @@ int fotg210_udc_probe(struct platform_device *pdev)
 	if (!IS_ERR(fotg210->pclk))
 		clk_disable_unprepare(fotg210->pclk);
 
-	kfree(fotg210);
-
 err:
+	kfree(fotg210);
 	return ret;
 }
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-04 18:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-30 10:12 [PATCH] usb: fotg210-udc: fix potential memory leak in fotg210_udc_probe() Yi Yang
2022-12-01  9:38 ` Andrzej Pietrasiewicz
2022-12-04 18:19 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®