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

Charles Han posted 1 patch 3 months, 3 weeks ago
drivers/dma/dw/rzn1-dmamux.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
[PATCH] dmaengine: dw: dmamux: Add NULL check in rzn1_dmamux_route_allocate()
Posted by Charles Han 3 months, 3 weeks ago
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 <hanchunchao@inspur.com>
---
 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
Re: [PATCH] dmaengine: dw: dmamux: Add NULL check in rzn1_dmamux_route_allocate()
Posted by Krzysztof Kozlowski 3 months, 3 weeks ago
On 16/06/2025 12:48, Charles Han wrote:
> 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 <hanchunchao@inspur.com>
> ---
>  drivers/dma/dw/rzn1-dmamux.c | 10 ++++++++--


Don't send patches for a subsystem patch by patch, but organize your
work correctly into patchset so we can reply in one thread (instead of
10) that you are fixing non-existing problems.

Best regards,
Krzysztof