]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
net: ethernet: ti: cpdma: correct error handling for chan create
authorIvan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Tue, 12 Dec 2017 21:06:35 +0000 (23:06 +0200)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 5 Sep 2018 08:30:45 +0000 (10:30 +0200)
BugLink: http://bugs.launchpad.net/bugs/1789666
It's not correct to return NULL when that is actually an error and
function returns errors in any other wrong case. In the same time,
the cpsw driver and davinci emac doesn't check error case while
creating channel and it can miss actual error. Also remove WARNs
replacing them on dev_err msgs.

Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 8a83c5d7969b8433584e3cf658a8d76c4dc37f4d)
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/net/ethernet/ti/cpsw.c
drivers/net/ethernet/ti/davinci_cpdma.c
drivers/net/ethernet/ti/davinci_emac.c

index 771021e237012d6ee1b149c9d19e91dfacd27bd2..60a263b365c2d34a88f2c6263f81c3ce8d6a1bd5 100644 (file)
@@ -3065,10 +3065,16 @@ static int cpsw_probe(struct platform_device *pdev)
        }
 
        cpsw->txv[0].ch = cpdma_chan_create(cpsw->dma, 0, cpsw_tx_handler, 0);
+       if (IS_ERR(cpsw->txv[0].ch)) {
+               dev_err(priv->dev, "error initializing tx dma channel\n");
+               ret = PTR_ERR(cpsw->txv[0].ch);
+               goto clean_dma_ret;
+       }
+
        cpsw->rxv[0].ch = cpdma_chan_create(cpsw->dma, 0, cpsw_rx_handler, 1);
-       if (WARN_ON(!cpsw->rxv[0].ch || !cpsw->txv[0].ch)) {
-               dev_err(priv->dev, "error initializing dma channels\n");
-               ret = -ENOMEM;
+       if (IS_ERR(cpsw->rxv[0].ch)) {
+               dev_err(priv->dev, "error initializing rx dma channel\n");
+               ret = PTR_ERR(cpsw->rxv[0].ch);
                goto clean_dma_ret;
        }
 
index e4d6edf387b34571242b720306602528ddf94fe3..6f9173ff941495564a1567d5fe1c3b2962188857 100644 (file)
@@ -893,7 +893,7 @@ struct cpdma_chan *cpdma_chan_create(struct cpdma_ctlr *ctlr, int chan_num,
        chan_num = rx_type ? rx_chan_num(chan_num) : tx_chan_num(chan_num);
 
        if (__chan_linear(chan_num) >= ctlr->num_chan)
-               return NULL;
+               return ERR_PTR(-EINVAL);
 
        chan = devm_kzalloc(ctlr->dev, sizeof(*chan), GFP_KERNEL);
        if (!chan)
index 4bb561856af53c0165e1d052a7ebfa2bd279ce68..74e71e760901093110662d7f292a867a04b68c7c 100644 (file)
@@ -1875,10 +1875,17 @@ static int davinci_emac_probe(struct platform_device *pdev)
 
        priv->txchan = cpdma_chan_create(priv->dma, EMAC_DEF_TX_CH,
                                         emac_tx_handler, 0);
+       if (IS_ERR(priv->txchan)) {
+               dev_err(&pdev->dev, "error initializing tx dma channel\n");
+               rc = PTR_ERR(priv->txchan);
+               goto no_cpdma_chan;
+       }
+
        priv->rxchan = cpdma_chan_create(priv->dma, EMAC_DEF_RX_CH,
                                         emac_rx_handler, 1);
-       if (WARN_ON(!priv->txchan || !priv->rxchan)) {
-               rc = -ENOMEM;
+       if (IS_ERR(priv->rxchan)) {
+               dev_err(&pdev->dev, "error initializing rx dma channel\n");
+               rc = PTR_ERR(priv->rxchan);
                goto no_cpdma_chan;
        }