Skip to content

Commit 104eb27

Browse files
jwrdegoededavem330
authored andcommitted
net: sun4i-emac: Properly free resources on probe failure and remove
Fix sun4i-emac not releasing the following resources: -iomapped memory not released on probe-failure nor on remove -clock not getting disabled on probe-failure nor on remove -sram not being released on remove And while at it also add error checking to the clk_prepare_enable call done on probe. Signed-off-by: Hans de Goede <[email protected]> Acked-by: Maxime Ripard <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e754ec6 commit 104eb27

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

drivers/net/ethernet/allwinner/sun4i-emac.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -847,21 +847,25 @@ static int emac_probe(struct platform_device *pdev)
847847
if (ndev->irq == -ENXIO) {
848848
netdev_err(ndev, "No irq resource\n");
849849
ret = ndev->irq;
850-
goto out;
850+
goto out_iounmap;
851851
}
852852

853853
db->clk = devm_clk_get(&pdev->dev, NULL);
854854
if (IS_ERR(db->clk)) {
855855
ret = PTR_ERR(db->clk);
856-
goto out;
856+
goto out_iounmap;
857857
}
858858

859-
clk_prepare_enable(db->clk);
859+
ret = clk_prepare_enable(db->clk);
860+
if (ret) {
861+
dev_err(&pdev->dev, "Error couldn't enable clock (%d)\n", ret);
862+
goto out_iounmap;
863+
}
860864

861865
ret = sunxi_sram_claim(&pdev->dev);
862866
if (ret) {
863867
dev_err(&pdev->dev, "Error couldn't map SRAM to device\n");
864-
goto out;
868+
goto out_clk_disable_unprepare;
865869
}
866870

867871
db->phy_node = of_parse_phandle(np, "phy", 0);
@@ -910,6 +914,10 @@ static int emac_probe(struct platform_device *pdev)
910914

911915
out_release_sram:
912916
sunxi_sram_release(&pdev->dev);
917+
out_clk_disable_unprepare:
918+
clk_disable_unprepare(db->clk);
919+
out_iounmap:
920+
iounmap(db->membase);
913921
out:
914922
dev_err(db->dev, "not found (%d).\n", ret);
915923

@@ -921,8 +929,12 @@ static int emac_probe(struct platform_device *pdev)
921929
static int emac_remove(struct platform_device *pdev)
922930
{
923931
struct net_device *ndev = platform_get_drvdata(pdev);
932+
struct emac_board_info *db = netdev_priv(ndev);
924933

925934
unregister_netdev(ndev);
935+
sunxi_sram_release(&pdev->dev);
936+
clk_disable_unprepare(db->clk);
937+
iounmap(db->membase);
926938
free_netdev(ndev);
927939

928940
dev_dbg(&pdev->dev, "released and freed device\n");

0 commit comments

Comments
 (0)