[PATCH net 4/5] net: ll_temac: fix rx_skb leak in temac_dma_bd_init()

Arina Kharlamova via B4 Relay devnull+arina.kharlamova.mbzuai.ac.ae at kernel.org
Tue Dec 1 11:13:40 PST 2026


From: Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>

temac_dma_bd_init() runs on every ndo_open and allocates the rx_skb
array with devm on the net device. temac_dma_bd_release() does not
free it, so every open leaves one array allocated until the device is
removed.

Allocate the array once in temac_probe(), sized for RX_BD_NUM_MAX, the
largest ring that set_ringparam accepts, and clear the entries in use
in temac_dma_bd_init(). temac_dma_bd_release() stops at the first NULL
entry, so stale pointers from the previous open must not remain.

Fixes: a63625d2a0e7 ("net: ll_temac: Fix and simplify error handling by using devres functions")
Signed-off-by: Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>
---
 drivers/net/ethernet/xilinx/ll_temac_main.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c
index 45d16464c2e8..2ce4f8e944df 100644
--- a/drivers/net/ethernet/xilinx/ll_temac_main.c
+++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
@@ -329,9 +329,7 @@ static int temac_dma_bd_init(struct net_device *ndev)
 	dma_addr_t skb_dma_addr;
 	int i;
 
-	lp->rx_skb = devm_kzalloc_objs(&ndev->dev, *lp->rx_skb, lp->rx_bd_num);
-	if (!lp->rx_skb)
-		goto out;
+	memset(lp->rx_skb, 0, sizeof(*lp->rx_skb) * lp->rx_bd_num);
 
 	/* allocate the tx and rx ring buffer descriptors. */
 	/* returns a virtual address and a physical address. */
@@ -1424,6 +1422,10 @@ static int temac_probe(struct platform_device *pdev)
 	spin_lock_init(&lp->rx_lock);
 	INIT_DELAYED_WORK(&lp->restart_work, ll_temac_restart_work_func);
 
+	lp->rx_skb = devm_kzalloc_objs(&pdev->dev, *lp->rx_skb, RX_BD_NUM_MAX);
+	if (!lp->rx_skb)
+		return -ENOMEM;
+
 	/* Setup mutex for synchronization of indirect register access */
 	if (pdata) {
 		if (!pdata->indirect_lock) {

-- 
Git-157)





More information about the linux-arm-kernel mailing list