Skip to content

Commit

Permalink
net: ethernet: mtk_eth_soc: fix possible memory leak in mtk_probe()
Browse files Browse the repository at this point in the history
[ Upstream commit b3d0d98 ]

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: 804775d ("net: ethernet: mtk_eth_soc: add support for Wireless Ethernet Dispatch (WED)")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Yang Yingliang authored and gregkh committed Oct 29, 2022
1 parent eedddf8 commit 96bde7c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions drivers/net/ethernet/mediatek/mtk_eth_soc.c
Expand Up @@ -4028,19 +4028,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;
}
Expand All @@ -4051,7 +4055,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);

Expand Down Expand Up @@ -4140,6 +4144,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;
}
Expand All @@ -4159,6 +4165,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);
Expand Down

0 comments on commit 96bde7c

Please sign in to comment.