1 From 7b95ade85ac18eec63e81ac58a482b3e88361ffd Mon Sep 17 00:00:00 2001
2 From: Yi Yang <yiyang13@huawei.com>
3 Date: Fri, 2 Dec 2022 09:21:26 +0800
4 Subject: [PATCH 13/29] usb: fotg210-udc: fix potential memory leak in
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 In fotg210_udc_probe(), if devm_clk_get() or clk_prepare_enable()
11 fails, 'fotg210' will not be freed, which will lead to a memory leak.
12 Fix it by moving kfree() to a proper location.
14 In addition,we can use "return -ENOMEM" instead of "goto err"
17 Fixes: 718a38d092ec ("fotg210-udc: Handle PCLK")
18 Reviewed-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
19 Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
20 Signed-off-by: Yi Yang <yiyang13@huawei.com>
21 Link: https://lore.kernel.org/r/20221202012126.246953-1-yiyang13@huawei.com
22 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24 --- a/drivers/usb/fotg210/fotg210-udc.c
25 +++ b/drivers/usb/fotg210/fotg210-udc.c
26 @@ -1176,12 +1176,10 @@ int fotg210_udc_probe(struct platform_de
33 fotg210 = kzalloc(sizeof(struct fotg210_udc), GFP_KERNEL);
40 @@ -1191,7 +1189,7 @@ int fotg210_udc_probe(struct platform_de
41 ret = clk_prepare_enable(fotg210->pclk);
43 dev_err(dev, "failed to enable PCLK\n");
47 } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
49 @@ -1317,8 +1315,7 @@ err_pclk:
50 if (!IS_ERR(fotg210->pclk))
51 clk_disable_unprepare(fotg210->pclk);