Skip to content

Commit

Permalink
moxa: fix the error handling in moxart_mac_probe()
Browse files Browse the repository at this point in the history
This patch fix the error handling in moxart_mac_probe():
 - return -ENOMEM in some memory alloc fail cases
 - add missing free_netdev() in the error handling case

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Wei Yongjun authored and David S. Miller committed Oct 8, 2013
1 parent c33a39c commit bdfd630
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions drivers/net/ethernet/moxa/moxart_ether.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ static int moxart_mac_probe(struct platform_device *pdev)
irq = irq_of_parse_and_map(node, 0);
if (irq <= 0) {
netdev_err(ndev, "irq_of_parse_and_map failed\n");
return -EINVAL;
ret = -EINVAL;
goto irq_map_fail;
}

priv = netdev_priv(ndev);
Expand All @@ -472,24 +473,32 @@ static int moxart_mac_probe(struct platform_device *pdev)
priv->tx_desc_base = dma_alloc_coherent(NULL, TX_REG_DESC_SIZE *
TX_DESC_NUM, &priv->tx_base,
GFP_DMA | GFP_KERNEL);
if (priv->tx_desc_base == NULL)
if (priv->tx_desc_base == NULL) {
ret = -ENOMEM;
goto init_fail;
}

priv->rx_desc_base = dma_alloc_coherent(NULL, RX_REG_DESC_SIZE *
RX_DESC_NUM, &priv->rx_base,
GFP_DMA | GFP_KERNEL);
if (priv->rx_desc_base == NULL)
if (priv->rx_desc_base == NULL) {
ret = -ENOMEM;
goto init_fail;
}

priv->tx_buf_base = kmalloc(priv->tx_buf_size * TX_DESC_NUM,
GFP_ATOMIC);
if (!priv->tx_buf_base)
if (!priv->tx_buf_base) {
ret = -ENOMEM;
goto init_fail;
}

priv->rx_buf_base = kmalloc(priv->rx_buf_size * RX_DESC_NUM,
GFP_ATOMIC);
if (!priv->rx_buf_base)
if (!priv->rx_buf_base) {
ret = -ENOMEM;
goto init_fail;
}

platform_set_drvdata(pdev, ndev);

Expand Down Expand Up @@ -522,7 +531,8 @@ static int moxart_mac_probe(struct platform_device *pdev)
init_fail:
netdev_err(ndev, "init failed\n");
moxart_mac_free_memory(ndev);

irq_map_fail:
free_netdev(ndev);
return ret;
}

Expand Down

0 comments on commit bdfd630

Please sign in to comment.