linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: dw: dmamux: Add NULL check in rzn1_dmamux_route_allocate()
@ 2025-06-16 10:48 Charles Han
  2025-06-17  6:10 ` Krzysztof Kozlowski
  0 siblings, 1 reply; 2+ messages in thread
From: Charles Han @ 2025-06-16 10:48 UTC (permalink / raw)
  To: vireshk, andriy.shevchenko, vkoul, miquel.raynal, ilpo.jarvinen
  Cc: dmaengine, linux-kernel, Charles Han

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] dmaengine: dw: dmamux: Add NULL check in rzn1_dmamux_route_allocate()
  2025-06-16 10:48 [PATCH] dmaengine: dw: dmamux: Add NULL check in rzn1_dmamux_route_allocate() Charles Han
@ 2025-06-17  6:10 ` Krzysztof Kozlowski
  0 siblings, 0 replies; 2+ messages in thread
From: Krzysztof Kozlowski @ 2025-06-17  6:10 UTC (permalink / raw)
  To: Charles Han, vireshk, andriy.shevchenko, vkoul, miquel.raynal,
	ilpo.jarvinen
  Cc: dmaengine, linux-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-17  6:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-16 10:48 [PATCH] dmaengine: dw: dmamux: Add NULL check in rzn1_dmamux_route_allocate() Charles Han
2025-06-17  6:10 ` Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).