提交 4de8e686 编写于 作者: F Fugang Duan 提交者: Yang Yingliang

net: fec: fix the potential memory leak in fec_enet_init()

[ Upstream commit 619fee9e ]

If the memory allocated for cbd_base is failed, it should
free the memory allocated for the queues, otherwise it causes
memory leak.

And if the memory allocated for the queues is failed, it can
return error directly.

Fixes: 59d0f746 ("net: fec: init multi queue date structure")
Signed-off-by: NFugang Duan <fugang.duan@nxp.com>
Signed-off-by: NJoakim Zhang <qiangqing.zhang@nxp.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 83153694
...@@ -3221,7 +3221,9 @@ static int fec_enet_init(struct net_device *ndev) ...@@ -3221,7 +3221,9 @@ static int fec_enet_init(struct net_device *ndev)
return ret; return ret;
} }
fec_enet_alloc_queue(ndev); ret = fec_enet_alloc_queue(ndev);
if (ret)
return ret;
bd_size = (fep->total_tx_ring_size + fep->total_rx_ring_size) * dsize; bd_size = (fep->total_tx_ring_size + fep->total_rx_ring_size) * dsize;
...@@ -3229,7 +3231,8 @@ static int fec_enet_init(struct net_device *ndev) ...@@ -3229,7 +3231,8 @@ static int fec_enet_init(struct net_device *ndev)
cbd_base = dmam_alloc_coherent(&fep->pdev->dev, bd_size, &bd_dma, cbd_base = dmam_alloc_coherent(&fep->pdev->dev, bd_size, &bd_dma,
GFP_KERNEL); GFP_KERNEL);
if (!cbd_base) { if (!cbd_base) {
return -ENOMEM; ret = -ENOMEM;
goto free_queue_mem;
} }
memset(cbd_base, 0, bd_size); memset(cbd_base, 0, bd_size);
...@@ -3309,6 +3312,10 @@ static int fec_enet_init(struct net_device *ndev) ...@@ -3309,6 +3312,10 @@ static int fec_enet_init(struct net_device *ndev)
fec_enet_update_ethtool_stats(ndev); fec_enet_update_ethtool_stats(ndev);
return 0; return 0;
free_queue_mem:
fec_enet_free_queue(ndev);
return ret;
} }
#ifdef CONFIG_OF #ifdef CONFIG_OF
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册