[lvc-project] [PATCH v2] dma: k3-udma - fix potential null dereference in k3_udma_glue_request_rx_chn_priv()

Pavel Zhigulin Pavel.Zhigulin at kaspersky.com
Mon Oct 6 15:43:44 MSK 2025


In function k3_udma_glue_request_rx_chn_priv(), the pointer rx_chn->flows,
after being compared to NULL, is passed to k3_udma_glue_release_rx_chn(),
where it is dereferenced unconditionally after being passed to
k3_udma_glue_release_rx_flow() in a for loop. This happens because
rx_chn->flow_num is set before successful allocation.

This fix sets rx_chn->flow_num only after rx_chn->flows is successfully
allocated, preventing the for loop from running if allocation fails.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: d70241913413 ("dmaengine: ti: k3-udma: Add glue layer for non DMAengine users")
Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin at kaspersky.com>
---
v2: Fix passing uninitialized rx_chn->flow_num to devm_kcalloc. Add
proper subject to patch.

 drivers/dma/ti/k3-udma-glue.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/ti/k3-udma-glue.c b/drivers/dma/ti/k3-udma-glue.c
index f87d244cc2d6..03679f61c241 100644
--- a/drivers/dma/ti/k3-udma-glue.c
+++ b/drivers/dma/ti/k3-udma-glue.c
@@ -1031,15 +1031,15 @@ k3_udma_glue_request_rx_chn_priv(struct device *dev, const char *name,
 			rx_chn->flow_id_base = rx_chn->udma_rchan_id;
 	}

-	rx_chn->flow_num = cfg->flow_id_num;
-
-	rx_chn->flows = devm_kcalloc(dev, rx_chn->flow_num,
+	rx_chn->flows = devm_kcalloc(dev, cfg->flow_id_num,
 				     sizeof(*rx_chn->flows), GFP_KERNEL);
 	if (!rx_chn->flows) {
 		ret = -ENOMEM;
 		goto err;
 	}

+	rx_chn->flow_num = cfg->flow_id_num;
+
 	ret = k3_udma_glue_allocate_rx_flows(rx_chn, cfg);
 	if (ret)
 		goto err;
--
2.43.0




More information about the lvc-project mailing list