7ebe8566a041d2330868c1176c347aaf25010fe8
[openwrt/staging/ldir.git] /
1 From b3d0d98179d62f9d55635a600679c4fa362baf8d Mon Sep 17 00:00:00 2001
2 From: Yang Yingliang <yangyingliang@huawei.com>
3 Date: Mon, 17 Oct 2022 11:51:54 +0800
4 Subject: [PATCH 1/3] net: ethernet: mtk_eth_soc: fix possible memory leak in
5 mtk_probe()
6
7 If mtk_wed_add_hw() has been called, mtk_wed_exit() needs be called
8 in error path or removing module to free the memory allocated in
9 mtk_wed_add_hw().
10
11 Fixes: 804775dfc288 ("net: ethernet: mtk_eth_soc: add support for Wireless Ethernet Dispatch (WED)")
12 Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
13 Signed-off-by: David S. Miller <davem@davemloft.net>
14 ---
15 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 17 ++++++++++++-----
16 1 file changed, 12 insertions(+), 5 deletions(-)
17
18 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
19 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
20 @@ -4007,19 +4007,23 @@ static int mtk_probe(struct platform_dev
21 eth->irq[i] = platform_get_irq(pdev, i);
22 if (eth->irq[i] < 0) {
23 dev_err(&pdev->dev, "no IRQ%d resource found\n", i);
24 - return -ENXIO;
25 + err = -ENXIO;
26 + goto err_wed_exit;
27 }
28 }
29 for (i = 0; i < ARRAY_SIZE(eth->clks); i++) {
30 eth->clks[i] = devm_clk_get(eth->dev,
31 mtk_clks_source_name[i]);
32 if (IS_ERR(eth->clks[i])) {
33 - if (PTR_ERR(eth->clks[i]) == -EPROBE_DEFER)
34 - return -EPROBE_DEFER;
35 + if (PTR_ERR(eth->clks[i]) == -EPROBE_DEFER) {
36 + err = -EPROBE_DEFER;
37 + goto err_wed_exit;
38 + }
39 if (eth->soc->required_clks & BIT(i)) {
40 dev_err(&pdev->dev, "clock %s not found\n",
41 mtk_clks_source_name[i]);
42 - return -EINVAL;
43 + err = -EINVAL;
44 + goto err_wed_exit;
45 }
46 eth->clks[i] = NULL;
47 }
48 @@ -4030,7 +4034,7 @@ static int mtk_probe(struct platform_dev
49
50 err = mtk_hw_init(eth);
51 if (err)
52 - return err;
53 + goto err_wed_exit;
54
55 eth->hwlro = MTK_HAS_CAPS(eth->soc->caps, MTK_HWLRO);
56
57 @@ -4128,6 +4132,8 @@ err_free_dev:
58 mtk_free_dev(eth);
59 err_deinit_hw:
60 mtk_hw_deinit(eth);
61 +err_wed_exit:
62 + mtk_wed_exit();
63
64 return err;
65 }
66 @@ -4147,6 +4153,7 @@ static int mtk_remove(struct platform_de
67 phylink_disconnect_phy(mac->phylink);
68 }
69
70 + mtk_wed_exit();
71 mtk_hw_deinit(eth);
72
73 netif_napi_del(&eth->tx_napi);