diff mbox series

[net,1/3] net: ethernet: mtk_eth_soc: fix possible memory leak in mtk_probe()

Message ID 20221017035156.2497448-2-yangyingliang@huawei.com (mailing list archive)
State Accepted
Commit b3d0d98179d62f9d55635a600679c4fa362baf8d
Delegated to: Netdev Maintainers
Headers show
Series net: ethernet: mtk_eth_wed: fixe some leaks | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/cc_maintainers warning 9 maintainers not CCed: kuba@kernel.org linux@armlinux.org.uk pabeni@redhat.com sean.wang@mediatek.com Mark-MC.Lee@mediatek.com matthias.bgg@gmail.com john@phrozen.org edumazet@google.com linux-arm-kernel@lists.infradead.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 50 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yang Yingliang Oct. 17, 2022, 3:51 a.m. UTC
If mtk_wed_add_hw() has been called, mtk_wed_exit() needs be called
in error path or removing module to free the memory allocated in
mtk_wed_add_hw().

Fixes: 804775dfc288 ("net: ethernet: mtk_eth_soc: add support for Wireless Ethernet Dispatch (WED)")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

Comments

AngeloGioacchino Del Regno Oct. 17, 2022, 9:55 a.m. UTC | #1
Il 17/10/22 05:51, Yang Yingliang ha scritto:
> If mtk_wed_add_hw() has been called, mtk_wed_exit() needs be called
> in error path or removing module to free the memory allocated in
> mtk_wed_add_hw().
> 
> Fixes: 804775dfc288 ("net: ethernet: mtk_eth_soc: add support for Wireless Ethernet Dispatch (WED)")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>   drivers/net/ethernet/mediatek/mtk_eth_soc.c | 17 ++++++++++++-----
>   1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 4fba7cb0144b..7cd381530aa4 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -4060,19 +4060,23 @@ static int mtk_probe(struct platform_device *pdev)
>   			eth->irq[i] = platform_get_irq(pdev, i);
>   		if (eth->irq[i] < 0) {
>   			dev_err(&pdev->dev, "no IRQ%d resource found\n", i);
> -			return -ENXIO;
> +			err = -ENXIO;
> +			goto err_wed_exit;
>   		}
>   	}
>   	for (i = 0; i < ARRAY_SIZE(eth->clks); i++) {
>   		eth->clks[i] = devm_clk_get(eth->dev,
>   					    mtk_clks_source_name[i]);
>   		if (IS_ERR(eth->clks[i])) {
> -			if (PTR_ERR(eth->clks[i]) == -EPROBE_DEFER)
> -				return -EPROBE_DEFER;
> +			if (PTR_ERR(eth->clks[i]) == -EPROBE_DEFER) {
> +				err = -EPROBE_DEFER;
> +				goto err_wed_exit;
> +			}
>   			if (eth->soc->required_clks & BIT(i)) {
>   				dev_err(&pdev->dev, "clock %s not found\n",
>   					mtk_clks_source_name[i]);
> -				return -EINVAL;
> +				err = -EINVAL;
> +				goto err_wed_exit;
>   			}
>   			eth->clks[i] = NULL;
>   		}
> @@ -4083,7 +4087,7 @@ static int mtk_probe(struct platform_device *pdev)
>   
>   	err = mtk_hw_init(eth);
>   	if (err)
> -		return err;
> +		goto err_wed_exit;
>   
>   	eth->hwlro = MTK_HAS_CAPS(eth->soc->caps, MTK_HWLRO);
>   
> @@ -4179,6 +4183,8 @@ static int mtk_probe(struct platform_device *pdev)
>   	mtk_free_dev(eth);
>   err_deinit_hw:
>   	mtk_hw_deinit(eth);
> +err_wed_exit:
> +	mtk_wed_exit();

mtk_wed_add_hw() happens *only* if eth->soc->offload_version == true.
To make this clean, mtk_wed_exit() should be called only if mtk_wed_add_hw()
was ever called, so you have to add a check here.


>   
>   	return err;
>   }
> @@ -4198,6 +4204,7 @@ static int mtk_remove(struct platform_device *pdev)
>   		phylink_disconnect_phy(mac->phylink);
>   	}
>   
> +	mtk_wed_exit();

...and here as well.

Regards,
Angelo

>   	mtk_hw_deinit(eth);
>   
>   	netif_napi_del(&eth->tx_napi);
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 4fba7cb0144b..7cd381530aa4 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -4060,19 +4060,23 @@  static int mtk_probe(struct platform_device *pdev)
 			eth->irq[i] = platform_get_irq(pdev, i);
 		if (eth->irq[i] < 0) {
 			dev_err(&pdev->dev, "no IRQ%d resource found\n", i);
-			return -ENXIO;
+			err = -ENXIO;
+			goto err_wed_exit;
 		}
 	}
 	for (i = 0; i < ARRAY_SIZE(eth->clks); i++) {
 		eth->clks[i] = devm_clk_get(eth->dev,
 					    mtk_clks_source_name[i]);
 		if (IS_ERR(eth->clks[i])) {
-			if (PTR_ERR(eth->clks[i]) == -EPROBE_DEFER)
-				return -EPROBE_DEFER;
+			if (PTR_ERR(eth->clks[i]) == -EPROBE_DEFER) {
+				err = -EPROBE_DEFER;
+				goto err_wed_exit;
+			}
 			if (eth->soc->required_clks & BIT(i)) {
 				dev_err(&pdev->dev, "clock %s not found\n",
 					mtk_clks_source_name[i]);
-				return -EINVAL;
+				err = -EINVAL;
+				goto err_wed_exit;
 			}
 			eth->clks[i] = NULL;
 		}
@@ -4083,7 +4087,7 @@  static int mtk_probe(struct platform_device *pdev)
 
 	err = mtk_hw_init(eth);
 	if (err)
-		return err;
+		goto err_wed_exit;
 
 	eth->hwlro = MTK_HAS_CAPS(eth->soc->caps, MTK_HWLRO);
 
@@ -4179,6 +4183,8 @@  static int mtk_probe(struct platform_device *pdev)
 	mtk_free_dev(eth);
 err_deinit_hw:
 	mtk_hw_deinit(eth);
+err_wed_exit:
+	mtk_wed_exit();
 
 	return err;
 }
@@ -4198,6 +4204,7 @@  static int mtk_remove(struct platform_device *pdev)
 		phylink_disconnect_phy(mac->phylink);
 	}
 
+	mtk_wed_exit();
 	mtk_hw_deinit(eth);
 
 	netif_napi_del(&eth->tx_napi);