gemini: Add kernel v6.1 patches
[openwrt/openwrt.git] / target / linux / gemini / patches-6.1 / 0013-usb-fotg210-udc-fix-potential-memory-leak-in-fotg210.patch
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
5 fotg210_udc_probe()
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
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.
13
14 In addition,we can use "return -ENOMEM" instead of "goto err"
15 to simplify the code.
16
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>
23 ---
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
27 return -ENODEV;
28 }
29
30 - ret = -ENOMEM;
31 -
32 /* initialize udc */
33 fotg210 = kzalloc(sizeof(struct fotg210_udc), GFP_KERNEL);
34 if (fotg210 == NULL)
35 - goto err;
36 + return -ENOMEM;
37
38 fotg210->dev = dev;
39
40 @@ -1191,7 +1189,7 @@ int fotg210_udc_probe(struct platform_de
41 ret = clk_prepare_enable(fotg210->pclk);
42 if (ret) {
43 dev_err(dev, "failed to enable PCLK\n");
44 - return ret;
45 + goto err;
46 }
47 } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
48 /*
49 @@ -1317,8 +1315,7 @@ err_pclk:
50 if (!IS_ERR(fotg210->pclk))
51 clk_disable_unprepare(fotg210->pclk);
52
53 - kfree(fotg210);
54 -
55 err:
56 + kfree(fotg210);
57 return ret;
58 }