[PATCH] dmaengine: Add NULL check in lpc32xx_dmamux_reserve()

Charles Han hanchunchao at inspur.com
Mon Jun 16 03:46:39 PDT 2025


The function of_find_device_by_node() may return NULL if the device
node cannot be found or if 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: 5d318b595982 ("dmaengine: Add dma router for pl08x in LPC32XX SoC")
Signed-off-by: Charles Han <hanchunchao at inspur.com>
---
 drivers/dma/lpc32xx-dmamux.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/lpc32xx-dmamux.c b/drivers/dma/lpc32xx-dmamux.c
index 351d7e23e615..6dc67d2f3335 100644
--- a/drivers/dma/lpc32xx-dmamux.c
+++ b/drivers/dma/lpc32xx-dmamux.c
@@ -90,13 +90,20 @@ static void lpc32xx_dmamux_release(struct device *dev, void *route_data)
 static void *lpc32xx_dmamux_reserve(struct of_phandle_args *dma_spec,
 				    struct of_dma *ofdma)
 {
-	struct platform_device *pdev = of_find_device_by_node(ofdma->of_node);
-	struct device *dev = &pdev->dev;
-	struct lpc32xx_dmamux_data *dmamux = platform_get_drvdata(pdev);
+	struct platform_device *pdev;
+	struct device *dev;
+	struct lpc32xx_dmamux_data *dmamux;
 	unsigned long flags;
 	struct lpc32xx_dmamux *mux = NULL;
 	int i;
 
+	pdev = of_find_device_by_node(ofdma->of_node);
+	if (!pdev)
+		return ERR_PTR(-ENODEV);
+
+	dev = &pdev->dev;
+	dmamux = platform_get_drvdata(pdev);
+
 	if (dma_spec->args_count != 3) {
 		dev_err(&pdev->dev, "invalid number of dma mux args\n");
 		return ERR_PTR(-EINVAL);
-- 
2.43.0




More information about the linux-arm-kernel mailing list