Skip to content

Commit 1cd5384

Browse files
tititiou36davem330
authored andcommitted
net: ag71xx: Fix a potential double free in error handling paths
'ndev' is a managed resource allocated with devm_alloc_etherdev(), so there is no need to call free_netdev() explicitly or there will be a double free(). Simplify all error handling paths accordingly. Fixes: d51b6ce ("net: ethernet: add ag71xx driver") Signed-off-by: Christophe JAILLET <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8b5fdfc commit 1cd5384

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

drivers/net/ethernet/atheros/ag71xx.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,23 +1913,20 @@ static int ag71xx_probe(struct platform_device *pdev)
19131913
ag->mac_reset = devm_reset_control_get(&pdev->dev, "mac");
19141914
if (IS_ERR(ag->mac_reset)) {
19151915
netif_err(ag, probe, ndev, "missing mac reset\n");
1916-
err = PTR_ERR(ag->mac_reset);
1917-
goto err_free;
1916+
return PTR_ERR(ag->mac_reset);
19181917
}
19191918

19201919
ag->mac_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
1921-
if (!ag->mac_base) {
1922-
err = -ENOMEM;
1923-
goto err_free;
1924-
}
1920+
if (!ag->mac_base)
1921+
return -ENOMEM;
19251922

19261923
ndev->irq = platform_get_irq(pdev, 0);
19271924
err = devm_request_irq(&pdev->dev, ndev->irq, ag71xx_interrupt,
19281925
0x0, dev_name(&pdev->dev), ndev);
19291926
if (err) {
19301927
netif_err(ag, probe, ndev, "unable to request IRQ %d\n",
19311928
ndev->irq);
1932-
goto err_free;
1929+
return err;
19331930
}
19341931

19351932
ndev->netdev_ops = &ag71xx_netdev_ops;
@@ -1957,10 +1954,8 @@ static int ag71xx_probe(struct platform_device *pdev)
19571954
ag->stop_desc = dmam_alloc_coherent(&pdev->dev,
19581955
sizeof(struct ag71xx_desc),
19591956
&ag->stop_desc_dma, GFP_KERNEL);
1960-
if (!ag->stop_desc) {
1961-
err = -ENOMEM;
1962-
goto err_free;
1963-
}
1957+
if (!ag->stop_desc)
1958+
return -ENOMEM;
19641959

19651960
ag->stop_desc->data = 0;
19661961
ag->stop_desc->ctrl = 0;
@@ -1975,15 +1970,15 @@ static int ag71xx_probe(struct platform_device *pdev)
19751970
err = of_get_phy_mode(np, &ag->phy_if_mode);
19761971
if (err) {
19771972
netif_err(ag, probe, ndev, "missing phy-mode property in DT\n");
1978-
goto err_free;
1973+
return err;
19791974
}
19801975

19811976
netif_napi_add(ndev, &ag->napi, ag71xx_poll, AG71XX_NAPI_WEIGHT);
19821977

19831978
err = clk_prepare_enable(ag->clk_eth);
19841979
if (err) {
19851980
netif_err(ag, probe, ndev, "Failed to enable eth clk.\n");
1986-
goto err_free;
1981+
return err;
19871982
}
19881983

19891984
ag71xx_wr(ag, AG71XX_REG_MAC_CFG1, 0);
@@ -2019,8 +2014,6 @@ static int ag71xx_probe(struct platform_device *pdev)
20192014
ag71xx_mdio_remove(ag);
20202015
err_put_clk:
20212016
clk_disable_unprepare(ag->clk_eth);
2022-
err_free:
2023-
free_netdev(ndev);
20242017
return err;
20252018
}
20262019

0 commit comments

Comments
 (0)