drivers/dma/lpc32xx-dmamux.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
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@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
Hi Charles, On 6/16/25 13:46, Charles Han wrote: > 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 please see my comments provided for lpc18xx-dmamux.c driver, all of them are applicable here as well. There is no problem to be fixed, the change also shall be dropped in my opinion. > 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@inspur.com> -- Best wishes, Vladimir
© 2016 - 2025 Red Hat, Inc.