Commit 1efb597d authored by Zhao Qiang's avatar Zhao Qiang Committed by David S. Miller

wan/fsl_ucc_hdlc: rewrite error handling to make it clearer

It was used err_xxx for labeled statement, it is
not easy to understand, now use free_xxx for labeled
statement.
Signed-off-by: default avatarZhao Qiang <qiang.zhao@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 18210510
...@@ -143,7 +143,7 @@ static int uhdlc_init(struct ucc_hdlc_private *priv) ...@@ -143,7 +143,7 @@ static int uhdlc_init(struct ucc_hdlc_private *priv)
if (!priv->rx_bd_base) { if (!priv->rx_bd_base) {
dev_err(priv->dev, "Cannot allocate MURAM memory for RxBDs\n"); dev_err(priv->dev, "Cannot allocate MURAM memory for RxBDs\n");
ret = -ENOMEM; ret = -ENOMEM;
goto rxbd_alloc_error; goto free_uccf;
} }
/* Alloc Tx BD */ /* Alloc Tx BD */
...@@ -154,7 +154,7 @@ static int uhdlc_init(struct ucc_hdlc_private *priv) ...@@ -154,7 +154,7 @@ static int uhdlc_init(struct ucc_hdlc_private *priv)
if (!priv->tx_bd_base) { if (!priv->tx_bd_base) {
dev_err(priv->dev, "Cannot allocate MURAM memory for TxBDs\n"); dev_err(priv->dev, "Cannot allocate MURAM memory for TxBDs\n");
ret = -ENOMEM; ret = -ENOMEM;
goto txbd_alloc_error; goto free_rx_bd;
} }
/* Alloc parameter ram for ucc hdlc */ /* Alloc parameter ram for ucc hdlc */
...@@ -164,18 +164,18 @@ static int uhdlc_init(struct ucc_hdlc_private *priv) ...@@ -164,18 +164,18 @@ static int uhdlc_init(struct ucc_hdlc_private *priv)
if (priv->ucc_pram_offset < 0) { if (priv->ucc_pram_offset < 0) {
dev_err(priv->dev, "Can not allocate MURAM for hdlc prameter.\n"); dev_err(priv->dev, "Can not allocate MURAM for hdlc prameter.\n");
ret = -ENOMEM; ret = -ENOMEM;
goto pram_alloc_error; goto free_tx_bd;
} }
priv->rx_skbuff = kzalloc(priv->rx_ring_size * sizeof(*priv->rx_skbuff), priv->rx_skbuff = kzalloc(priv->rx_ring_size * sizeof(*priv->rx_skbuff),
GFP_KERNEL); GFP_KERNEL);
if (!priv->rx_skbuff) if (!priv->rx_skbuff)
goto rx_skb_alloc_error; goto free_ucc_pram;
priv->tx_skbuff = kzalloc(priv->tx_ring_size * sizeof(*priv->tx_skbuff), priv->tx_skbuff = kzalloc(priv->tx_ring_size * sizeof(*priv->tx_skbuff),
GFP_KERNEL); GFP_KERNEL);
if (!priv->tx_skbuff) if (!priv->tx_skbuff)
goto tx_skb_alloc_error; goto free_rx_skbuff;
priv->skb_curtx = 0; priv->skb_curtx = 0;
priv->skb_dirtytx = 0; priv->skb_dirtytx = 0;
...@@ -200,14 +200,14 @@ static int uhdlc_init(struct ucc_hdlc_private *priv) ...@@ -200,14 +200,14 @@ static int uhdlc_init(struct ucc_hdlc_private *priv)
if (riptr < 0) { if (riptr < 0) {
dev_err(priv->dev, "Cannot allocate MURAM mem for Receive internal temp data pointer\n"); dev_err(priv->dev, "Cannot allocate MURAM mem for Receive internal temp data pointer\n");
ret = -ENOMEM; ret = -ENOMEM;
goto riptr_alloc_error; goto free_tx_skbuff;
} }
tiptr = qe_muram_alloc(32, 32); tiptr = qe_muram_alloc(32, 32);
if (tiptr < 0) { if (tiptr < 0) {
dev_err(priv->dev, "Cannot allocate MURAM mem for Transmit internal temp data pointer\n"); dev_err(priv->dev, "Cannot allocate MURAM mem for Transmit internal temp data pointer\n");
ret = -ENOMEM; ret = -ENOMEM;
goto tiptr_alloc_error; goto free_riptr;
} }
/* Set RIPTR, TIPTR */ /* Set RIPTR, TIPTR */
...@@ -247,7 +247,7 @@ static int uhdlc_init(struct ucc_hdlc_private *priv) ...@@ -247,7 +247,7 @@ static int uhdlc_init(struct ucc_hdlc_private *priv)
if (!bd_buffer) { if (!bd_buffer) {
dev_err(priv->dev, "Could not allocate buffer descriptors\n"); dev_err(priv->dev, "Could not allocate buffer descriptors\n");
ret = -ENOMEM; ret = -ENOMEM;
goto bd_alloc_error; goto free_tiptr;
} }
memset(bd_buffer, 0, (RX_BD_RING_LEN + TX_BD_RING_LEN) memset(bd_buffer, 0, (RX_BD_RING_LEN + TX_BD_RING_LEN)
...@@ -283,25 +283,25 @@ static int uhdlc_init(struct ucc_hdlc_private *priv) ...@@ -283,25 +283,25 @@ static int uhdlc_init(struct ucc_hdlc_private *priv)
return 0; return 0;
bd_alloc_error: free_tiptr:
qe_muram_free(tiptr); qe_muram_free(tiptr);
tiptr_alloc_error: free_riptr:
qe_muram_free(riptr); qe_muram_free(riptr);
riptr_alloc_error: free_tx_skbuff:
kfree(priv->tx_skbuff); kfree(priv->tx_skbuff);
tx_skb_alloc_error: free_rx_skbuff:
kfree(priv->rx_skbuff); kfree(priv->rx_skbuff);
rx_skb_alloc_error: free_ucc_pram:
qe_muram_free(priv->ucc_pram_offset); qe_muram_free(priv->ucc_pram_offset);
pram_alloc_error: free_tx_bd:
dma_free_coherent(priv->dev, dma_free_coherent(priv->dev,
TX_BD_RING_LEN * sizeof(struct qe_bd), TX_BD_RING_LEN * sizeof(struct qe_bd),
priv->tx_bd_base, priv->dma_tx_bd); priv->tx_bd_base, priv->dma_tx_bd);
txbd_alloc_error: free_rx_bd:
dma_free_coherent(priv->dev, dma_free_coherent(priv->dev,
RX_BD_RING_LEN * sizeof(struct qe_bd), RX_BD_RING_LEN * sizeof(struct qe_bd),
priv->rx_bd_base, priv->dma_rx_bd); priv->rx_bd_base, priv->dma_rx_bd);
rxbd_alloc_error: free_uccf:
ucc_fast_free(priv->uccf); ucc_fast_free(priv->uccf);
return ret; return ret;
...@@ -1067,9 +1067,7 @@ static int ucc_hdlc_probe(struct platform_device *pdev) ...@@ -1067,9 +1067,7 @@ static int ucc_hdlc_probe(struct platform_device *pdev)
uhdlc_priv = kzalloc(sizeof(*uhdlc_priv), GFP_KERNEL); uhdlc_priv = kzalloc(sizeof(*uhdlc_priv), GFP_KERNEL);
if (!uhdlc_priv) { if (!uhdlc_priv) {
ret = -ENOMEM; return -ENOMEM;
dev_err(&pdev->dev, "No mem to alloc hdlc private data\n");
goto err_alloc_priv;
} }
dev_set_drvdata(&pdev->dev, uhdlc_priv); dev_set_drvdata(&pdev->dev, uhdlc_priv);
...@@ -1087,25 +1085,25 @@ static int ucc_hdlc_probe(struct platform_device *pdev) ...@@ -1087,25 +1085,25 @@ static int ucc_hdlc_probe(struct platform_device *pdev)
if (!utdm) { if (!utdm) {
ret = -ENOMEM; ret = -ENOMEM;
dev_err(&pdev->dev, "No mem to alloc ucc tdm data\n"); dev_err(&pdev->dev, "No mem to alloc ucc tdm data\n");
goto err_alloc_utdm; goto free_uhdlc_priv;
} }
uhdlc_priv->utdm = utdm; uhdlc_priv->utdm = utdm;
ret = ucc_of_parse_tdm(np, utdm, ut_info); ret = ucc_of_parse_tdm(np, utdm, ut_info);
if (ret) if (ret)
goto err_miss_tsa_property; goto free_utdm;
} }
ret = uhdlc_init(uhdlc_priv); ret = uhdlc_init(uhdlc_priv);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to init uhdlc\n"); dev_err(&pdev->dev, "Failed to init uhdlc\n");
goto err_hdlc_init; goto free_utdm;
} }
dev = alloc_hdlcdev(uhdlc_priv); dev = alloc_hdlcdev(uhdlc_priv);
if (!dev) { if (!dev) {
ret = -ENOMEM; ret = -ENOMEM;
pr_err("ucc_hdlc: unable to allocate memory\n"); pr_err("ucc_hdlc: unable to allocate memory\n");
goto err_hdlc_init; goto undo_uhdlc_init;
} }
uhdlc_priv->ndev = dev; uhdlc_priv->ndev = dev;
...@@ -1119,18 +1117,19 @@ static int ucc_hdlc_probe(struct platform_device *pdev) ...@@ -1119,18 +1117,19 @@ static int ucc_hdlc_probe(struct platform_device *pdev)
ret = -ENOBUFS; ret = -ENOBUFS;
pr_err("ucc_hdlc: unable to register hdlc device\n"); pr_err("ucc_hdlc: unable to register hdlc device\n");
free_netdev(dev); free_netdev(dev);
goto err_hdlc_init; goto free_dev;
} }
return 0; return 0;
err_hdlc_init: free_dev:
err_miss_tsa_property: free_netdev(dev);
undo_uhdlc_init:
free_utdm:
if (uhdlc_priv->tsa) if (uhdlc_priv->tsa)
kfree(utdm); kfree(utdm);
err_alloc_utdm: free_uhdlc_priv:
kfree(uhdlc_priv); kfree(uhdlc_priv);
err_alloc_priv:
return ret; return ret;
} }
......
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