linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] dmaengine: Add NULL check in lpc18xx_dmamux_reserve()
@ 2025-06-16 10:44 Charles Han
  2025-06-16 11:24 ` Eugen Hristev
  2025-06-16 15:23 ` Vladimir Zapolskiy
  0 siblings, 2 replies; 3+ messages in thread
From: Charles Han @ 2025-06-16 10:44 UTC (permalink / raw)
  To: eugen.hristev, vkoul, vz, manabian
  Cc: dmaengine, linux-arm-kernel, linux-kernel, Charles Han

The function of_find_device_by_node() may return NULL if the device
node is not found or CONFIG_OF not defined.
Add  check whether the return value is NULL and set the error code
to be returned as -ENODEV.

Fixes: e5f4ae84be74 ("dmaengine: add driver for lpc18xx dmamux")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
 drivers/dma/lpc18xx-dmamux.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/lpc18xx-dmamux.c b/drivers/dma/lpc18xx-dmamux.c
index 2b6436f4b193..f61183a1d0ba 100644
--- a/drivers/dma/lpc18xx-dmamux.c
+++ b/drivers/dma/lpc18xx-dmamux.c
@@ -53,11 +53,17 @@ static void lpc18xx_dmamux_free(struct device *dev, void *route_data)
 static void *lpc18xx_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 lpc18xx_dmamux_data *dmamux = platform_get_drvdata(pdev);
+	struct platform_device *pdev;
+	struct lpc18xx_dmamux_data *dmamux;
 	unsigned long flags;
 	unsigned mux;
 
+	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 != 3) {
 		dev_err(&pdev->dev, "invalid number of dma mux args\n");
 		return ERR_PTR(-EINVAL);
-- 
2.43.0


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

* Re: [PATCH V2] dmaengine: Add NULL check in lpc18xx_dmamux_reserve()
  2025-06-16 10:44 [PATCH V2] dmaengine: Add NULL check in lpc18xx_dmamux_reserve() Charles Han
@ 2025-06-16 11:24 ` Eugen Hristev
  2025-06-16 15:23 ` Vladimir Zapolskiy
  1 sibling, 0 replies; 3+ messages in thread
From: Eugen Hristev @ 2025-06-16 11:24 UTC (permalink / raw)
  To: Charles Han, vkoul, vz, manabian
  Cc: dmaengine, linux-arm-kernel, linux-kernel



On 6/16/25 13:44, Charles Han wrote:
> The function of_find_device_by_node() may return NULL if the device
> node is not found or CONFIG_OF not defined.
> Add  check whether the return value is NULL and set the error code
> to be returned as -ENODEV.
> 
> Fixes: e5f4ae84be74 ("dmaengine: add driver for lpc18xx dmamux")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>

Can you have the subject include the driver which you are modifying ? if
you say `dmaengine: Add...` it looks like you are modifying the core.
> ---
>  drivers/dma/lpc18xx-dmamux.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/lpc18xx-dmamux.c b/drivers/dma/lpc18xx-dmamux.c
> index 2b6436f4b193..f61183a1d0ba 100644
> --- a/drivers/dma/lpc18xx-dmamux.c
> +++ b/drivers/dma/lpc18xx-dmamux.c
> @@ -53,11 +53,17 @@ static void lpc18xx_dmamux_free(struct device *dev, void *route_data)
>  static void *lpc18xx_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 lpc18xx_dmamux_data *dmamux = platform_get_drvdata(pdev);
> +	struct platform_device *pdev;
> +	struct lpc18xx_dmamux_data *dmamux;
>  	unsigned long flags;
>  	unsigned mux;
>  
> +	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 != 3) {
>  		dev_err(&pdev->dev, "invalid number of dma mux args\n");
>  		return ERR_PTR(-EINVAL);


As I see it, the function lpc18xx_dmamux_reserve is only used as passed
to of_dma_router_register . In every driver, functions that have a
similar role are written in the same way, not checking if
of_find_device_by_node fails.
Can you detail what happens in your case that of_find_device_by_node
would fail ?
Would it be required to have this check in all the other drivers ?

Eugen

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

* Re: [PATCH V2] dmaengine: Add NULL check in lpc18xx_dmamux_reserve()
  2025-06-16 10:44 [PATCH V2] dmaengine: Add NULL check in lpc18xx_dmamux_reserve() Charles Han
  2025-06-16 11:24 ` Eugen Hristev
@ 2025-06-16 15:23 ` Vladimir Zapolskiy
  1 sibling, 0 replies; 3+ messages in thread
From: Vladimir Zapolskiy @ 2025-06-16 15:23 UTC (permalink / raw)
  To: Charles Han, eugen.hristev, vkoul, manabian
  Cc: dmaengine, linux-arm-kernel, linux-kernel

On 6/16/25 13:44, Charles Han wrote:
> The function of_find_device_by_node() may return NULL if the device
> node is not found or CONFIG_OF not defined.

DMA_OF depends on OF, and the driver depends on OF as it's stated
in the drivers/dma/Kconfig, so this is not an issue.

Next, is it possible here to get of_find_device_by_node() returning
NULL? I don't think so, and then it's unclear which problem is supposed
to be fixed by this change, and therefore the change should be dropped.

> Add  check whether the return value is NULL and set the error code
> to be returned as -ENODEV.
> 
> Fixes: e5f4ae84be74 ("dmaengine: add driver for lpc18xx dmamux")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>
> ---
>   drivers/dma/lpc18xx-dmamux.c | 10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/lpc18xx-dmamux.c b/drivers/dma/lpc18xx-dmamux.c
> index 2b6436f4b193..f61183a1d0ba 100644
> --- a/drivers/dma/lpc18xx-dmamux.c
> +++ b/drivers/dma/lpc18xx-dmamux.c
> @@ -53,11 +53,17 @@ static void lpc18xx_dmamux_free(struct device *dev, void *route_data)
>   static void *lpc18xx_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 lpc18xx_dmamux_data *dmamux = platform_get_drvdata(pdev);
> +	struct platform_device *pdev;
> +	struct lpc18xx_dmamux_data *dmamux;

The list of declared/initialized local variables is deliberately sorted
in so called reverse Christmas tree order, please keep the sorting order.

>   	unsigned long flags;
>   	unsigned mux;
>   
> +	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 != 3) {
>   		dev_err(&pdev->dev, "invalid number of dma mux args\n");
>   		return ERR_PTR(-EINVAL);

--
Best wishes,
Vladimir

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

end of thread, other threads:[~2025-06-16 15:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-16 10:44 [PATCH V2] dmaengine: Add NULL check in lpc18xx_dmamux_reserve() Charles Han
2025-06-16 11:24 ` Eugen Hristev
2025-06-16 15:23 ` Vladimir Zapolskiy

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).