Skip to content

Commit 8005b09

Browse files
Dan Carpenterdavem330
authored andcommitted
net: ethernet: davinci_emac: fix error handling in probe()
The current error handling code has an issue where it does: if (priv->txchan) cpdma_chan_destroy(priv->txchan); The problem is that ->txchan is either valid or an error pointer (which would lead to an Oops). I've changed it to use multiple error labels so that the test can be removed. Also there were some missing calls to netif_napi_del(). Fixes: 3ef0fdb ("net: davinci_emac: switch to new cpdma layer") Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0f51f35 commit 8005b09

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

drivers/net/ethernet/ti/davinci_emac.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,22 +1873,22 @@ static int davinci_emac_probe(struct platform_device *pdev)
18731873
if (IS_ERR(priv->txchan)) {
18741874
dev_err(&pdev->dev, "error initializing tx dma channel\n");
18751875
rc = PTR_ERR(priv->txchan);
1876-
goto no_cpdma_chan;
1876+
goto err_free_dma;
18771877
}
18781878

18791879
priv->rxchan = cpdma_chan_create(priv->dma, EMAC_DEF_RX_CH,
18801880
emac_rx_handler, 1);
18811881
if (IS_ERR(priv->rxchan)) {
18821882
dev_err(&pdev->dev, "error initializing rx dma channel\n");
18831883
rc = PTR_ERR(priv->rxchan);
1884-
goto no_cpdma_chan;
1884+
goto err_free_txchan;
18851885
}
18861886

18871887
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
18881888
if (!res) {
18891889
dev_err(&pdev->dev, "error getting irq res\n");
18901890
rc = -ENOENT;
1891-
goto no_cpdma_chan;
1891+
goto err_free_rxchan;
18921892
}
18931893
ndev->irq = res->start;
18941894

@@ -1914,7 +1914,7 @@ static int davinci_emac_probe(struct platform_device *pdev)
19141914
pm_runtime_put_noidle(&pdev->dev);
19151915
dev_err(&pdev->dev, "%s: failed to get_sync(%d)\n",
19161916
__func__, rc);
1917-
goto no_cpdma_chan;
1917+
goto err_napi_del;
19181918
}
19191919

19201920
/* register the network device */
@@ -1924,7 +1924,7 @@ static int davinci_emac_probe(struct platform_device *pdev)
19241924
dev_err(&pdev->dev, "error in register_netdev\n");
19251925
rc = -ENODEV;
19261926
pm_runtime_put(&pdev->dev);
1927-
goto no_cpdma_chan;
1927+
goto err_napi_del;
19281928
}
19291929

19301930

@@ -1937,11 +1937,13 @@ static int davinci_emac_probe(struct platform_device *pdev)
19371937

19381938
return 0;
19391939

1940-
no_cpdma_chan:
1941-
if (priv->txchan)
1942-
cpdma_chan_destroy(priv->txchan);
1943-
if (priv->rxchan)
1944-
cpdma_chan_destroy(priv->rxchan);
1940+
err_napi_del:
1941+
netif_napi_del(&priv->napi);
1942+
err_free_rxchan:
1943+
cpdma_chan_destroy(priv->rxchan);
1944+
err_free_txchan:
1945+
cpdma_chan_destroy(priv->txchan);
1946+
err_free_dma:
19451947
cpdma_ctlr_destroy(priv->dma);
19461948
no_pdata:
19471949
if (of_phy_is_fixed_link(np))

0 commit comments

Comments
 (0)