Skip to content

Commit

Permalink
net: fec: fix the potential memory leak in fec_enet_init()
Browse files Browse the repository at this point in the history
[ Upstream commit 619fee9 ]

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: 59d0f74 ("net: fec: init multi queue date structure")
Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
fugangduan authored and gregkh committed Jun 3, 2021
1 parent 9c38601 commit 8ee7ef4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions drivers/net/ethernet/freescale/fec_main.c
Expand Up @@ -3277,15 +3277,18 @@ static int fec_enet_init(struct net_device *ndev)
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;

/* Allocate memory for buffer descriptors. */
cbd_base = dmam_alloc_coherent(&fep->pdev->dev, bd_size, &bd_dma,
GFP_KERNEL);
if (!cbd_base) {
return -ENOMEM;
ret = -ENOMEM;
goto free_queue_mem;
}

/* Get the Ethernet address */
Expand Down Expand Up @@ -3363,6 +3366,10 @@ static int fec_enet_init(struct net_device *ndev)
fec_enet_update_ethtool_stats(ndev);

return 0;

free_queue_mem:
fec_enet_free_queue(ndev);
return ret;
}

#ifdef CONFIG_OF
Expand Down

0 comments on commit 8ee7ef4

Please sign in to comment.