Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bdfd6304 authored by Wei Yongjun's avatar Wei Yongjun Committed by David S. Miller
Browse files

moxa: fix the error handling in moxart_mac_probe()



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: default avatarWei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c33a39c5
Loading
Loading
Loading
Loading
+16 −6
Original line number Original line Diff line number Diff line
@@ -448,7 +448,8 @@ static int moxart_mac_probe(struct platform_device *pdev)
	irq = irq_of_parse_and_map(node, 0);
	irq = irq_of_parse_and_map(node, 0);
	if (irq <= 0) {
	if (irq <= 0) {
		netdev_err(ndev, "irq_of_parse_and_map failed\n");
		netdev_err(ndev, "irq_of_parse_and_map failed\n");
		return -EINVAL;
		ret = -EINVAL;
		goto irq_map_fail;
	}
	}


	priv = netdev_priv(ndev);
	priv = netdev_priv(ndev);
@@ -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 *
	priv->tx_desc_base = dma_alloc_coherent(NULL, TX_REG_DESC_SIZE *
						TX_DESC_NUM, &priv->tx_base,
						TX_DESC_NUM, &priv->tx_base,
						GFP_DMA | GFP_KERNEL);
						GFP_DMA | GFP_KERNEL);
	if (priv->tx_desc_base == NULL)
	if (priv->tx_desc_base == NULL) {
		ret = -ENOMEM;
		goto init_fail;
		goto init_fail;
	}


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


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


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


	platform_set_drvdata(pdev, ndev);
	platform_set_drvdata(pdev, ndev);


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

irq_map_fail:
	free_netdev(ndev);
	return ret;
	return ret;
}
}