Thread (2 messages) 2 messages, 2 authors, 2025-06-17

[PATCH] dmaengine: dw: dmamux: Add NULL check in rzn1_dmamux_route_allocate()

From: Charles Han <hidden>
Date: 2025-06-16 10:48:15
Also in: lkml
Subsystem: dma generic offload engine subsystem, synopsys designware dmac driver, the rest · Maintainers: Vinod Koul, Viresh Kumar, Linus Torvalds

The function of_find_device_by_node() may return NULL if the device
node cannot be found or CONFIG_OF is not defined, dereferencing
it without NULL check may lead to NULL dereference.
Add a check to verify whether the return value is NULL.

Fixes: 134d9c52fca2 ("dmaengine: dw: dmamux: Introduce RZN1 DMA router support")
Signed-off-by: Charles Han <redacted>
---
 drivers/dma/dw/rzn1-dmamux.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/dma/dw/rzn1-dmamux.c b/drivers/dma/dw/rzn1-dmamux.c
index 4fb8508419db..a21623d98e41 100644
--- a/drivers/dma/dw/rzn1-dmamux.c
+++ b/drivers/dma/dw/rzn1-dmamux.c
@@ -41,13 +41,19 @@ static void rzn1_dmamux_free(struct device *dev, void *route_data)
 static void *rzn1_dmamux_route_allocate(struct of_phandle_args *dma_spec,
 					struct of_dma *ofdma)
 {
-	struct platform_device *pdev = of_find_device_by_node(ofdma->of_node);
-	struct rzn1_dmamux_data *dmamux = platform_get_drvdata(pdev);
+	struct platform_device *pdev;
+	struct rzn1_dmamux_data *dmamux;
 	struct rzn1_dmamux_map *map;
 	unsigned int dmac_idx, chan, val;
 	u32 mask;
 	int ret;
 
+	pdev = of_find_device_by_node(ofdma->of_node);
+	if (!pdev)
+		return ERR_PTR(-ENODEV);
+
+	dmamux = platform_get_drvdata(pdev);
+
 	if (dma_spec->args_count != RNZ1_DMAMUX_NCELLS)
 		return ERR_PTR(-EINVAL);
 
-- 
2.43.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help