Commit 1cd5384c authored by Christophe JAILLET's avatar Christophe JAILLET Committed by David S. Miller

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: d51b6ce4 ("net: ethernet: add ag71xx driver")
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8b5fdfc5
...@@ -1913,15 +1913,12 @@ static int ag71xx_probe(struct platform_device *pdev) ...@@ -1913,15 +1913,12 @@ static int ag71xx_probe(struct platform_device *pdev)
ag->mac_reset = devm_reset_control_get(&pdev->dev, "mac"); ag->mac_reset = devm_reset_control_get(&pdev->dev, "mac");
if (IS_ERR(ag->mac_reset)) { if (IS_ERR(ag->mac_reset)) {
netif_err(ag, probe, ndev, "missing mac reset\n"); netif_err(ag, probe, ndev, "missing mac reset\n");
err = PTR_ERR(ag->mac_reset); return PTR_ERR(ag->mac_reset);
goto err_free;
} }
ag->mac_base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); ag->mac_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
if (!ag->mac_base) { if (!ag->mac_base)
err = -ENOMEM; return -ENOMEM;
goto err_free;
}
ndev->irq = platform_get_irq(pdev, 0); ndev->irq = platform_get_irq(pdev, 0);
err = devm_request_irq(&pdev->dev, ndev->irq, ag71xx_interrupt, err = devm_request_irq(&pdev->dev, ndev->irq, ag71xx_interrupt,
...@@ -1929,7 +1926,7 @@ static int ag71xx_probe(struct platform_device *pdev) ...@@ -1929,7 +1926,7 @@ static int ag71xx_probe(struct platform_device *pdev)
if (err) { if (err) {
netif_err(ag, probe, ndev, "unable to request IRQ %d\n", netif_err(ag, probe, ndev, "unable to request IRQ %d\n",
ndev->irq); ndev->irq);
goto err_free; return err;
} }
ndev->netdev_ops = &ag71xx_netdev_ops; ndev->netdev_ops = &ag71xx_netdev_ops;
...@@ -1957,10 +1954,8 @@ static int ag71xx_probe(struct platform_device *pdev) ...@@ -1957,10 +1954,8 @@ static int ag71xx_probe(struct platform_device *pdev)
ag->stop_desc = dmam_alloc_coherent(&pdev->dev, ag->stop_desc = dmam_alloc_coherent(&pdev->dev,
sizeof(struct ag71xx_desc), sizeof(struct ag71xx_desc),
&ag->stop_desc_dma, GFP_KERNEL); &ag->stop_desc_dma, GFP_KERNEL);
if (!ag->stop_desc) { if (!ag->stop_desc)
err = -ENOMEM; return -ENOMEM;
goto err_free;
}
ag->stop_desc->data = 0; ag->stop_desc->data = 0;
ag->stop_desc->ctrl = 0; ag->stop_desc->ctrl = 0;
...@@ -1975,7 +1970,7 @@ static int ag71xx_probe(struct platform_device *pdev) ...@@ -1975,7 +1970,7 @@ static int ag71xx_probe(struct platform_device *pdev)
err = of_get_phy_mode(np, &ag->phy_if_mode); err = of_get_phy_mode(np, &ag->phy_if_mode);
if (err) { if (err) {
netif_err(ag, probe, ndev, "missing phy-mode property in DT\n"); netif_err(ag, probe, ndev, "missing phy-mode property in DT\n");
goto err_free; return err;
} }
netif_napi_add(ndev, &ag->napi, ag71xx_poll, AG71XX_NAPI_WEIGHT); netif_napi_add(ndev, &ag->napi, ag71xx_poll, AG71XX_NAPI_WEIGHT);
...@@ -1983,7 +1978,7 @@ static int ag71xx_probe(struct platform_device *pdev) ...@@ -1983,7 +1978,7 @@ static int ag71xx_probe(struct platform_device *pdev)
err = clk_prepare_enable(ag->clk_eth); err = clk_prepare_enable(ag->clk_eth);
if (err) { if (err) {
netif_err(ag, probe, ndev, "Failed to enable eth clk.\n"); netif_err(ag, probe, ndev, "Failed to enable eth clk.\n");
goto err_free; return err;
} }
ag71xx_wr(ag, AG71XX_REG_MAC_CFG1, 0); ag71xx_wr(ag, AG71XX_REG_MAC_CFG1, 0);
...@@ -2019,8 +2014,6 @@ static int ag71xx_probe(struct platform_device *pdev) ...@@ -2019,8 +2014,6 @@ static int ag71xx_probe(struct platform_device *pdev)
ag71xx_mdio_remove(ag); ag71xx_mdio_remove(ag);
err_put_clk: err_put_clk:
clk_disable_unprepare(ag->clk_eth); clk_disable_unprepare(ag->clk_eth);
err_free:
free_netdev(ndev);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment