linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: rcar-dmac: refactor the error handling code of rcar_dmac_probe
@ 2021-10-20 14:35 Dongliang Mu
  2021-10-21  8:57 ` Geert Uytterhoeven
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dongliang Mu @ 2021-10-20 14:35 UTC (permalink / raw)
  To: Vinod Koul, Geert Uytterhoeven, Yoshihiro Shimoda,
	Laurent Pinchart, Wolfram Sang, Zou Wei, Dongliang Mu
  Cc: dmaengine, linux-kernel

In rcar_dmac_probe, if pm_runtime_resume_and_get fails, it forgets to
disable runtime PM. And of_dma_controller_free should only be invoked
after the success of of_dma_controller_register.

Fix this by refactoring the error handling code.

Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
---
 drivers/dma/sh/rcar-dmac.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c
index 6885b3dcd7a9..5c7716fd6bc5 100644
--- a/drivers/dma/sh/rcar-dmac.c
+++ b/drivers/dma/sh/rcar-dmac.c
@@ -1916,7 +1916,7 @@ static int rcar_dmac_probe(struct platform_device *pdev)
 	ret = pm_runtime_resume_and_get(&pdev->dev);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "runtime PM get sync failed (%d)\n", ret);
-		return ret;
+		goto err_pm_disable;
 	}
 
 	ret = rcar_dmac_init(dmac);
@@ -1924,7 +1924,7 @@ static int rcar_dmac_probe(struct platform_device *pdev)
 
 	if (ret) {
 		dev_err(&pdev->dev, "failed to reset device\n");
-		goto error;
+		goto err_pm_disable;
 	}
 
 	/* Initialize engine */
@@ -1958,14 +1958,14 @@ static int rcar_dmac_probe(struct platform_device *pdev)
 	for_each_rcar_dmac_chan(i, dmac, chan) {
 		ret = rcar_dmac_chan_probe(dmac, chan);
 		if (ret < 0)
-			goto error;
+			goto err_pm_disable;
 	}
 
 	/* Register the DMAC as a DMA provider for DT. */
 	ret = of_dma_controller_register(pdev->dev.of_node, rcar_dmac_of_xlate,
 					 NULL);
 	if (ret < 0)
-		goto error;
+		goto err_pm_disable;
 
 	/*
 	 * Register the DMA engine device.
@@ -1974,12 +1974,13 @@ static int rcar_dmac_probe(struct platform_device *pdev)
 	 */
 	ret = dma_async_device_register(engine);
 	if (ret < 0)
-		goto error;
+		goto err_dma_free;
 
 	return 0;
 
-error:
+err_dma_free:
 	of_dma_controller_free(pdev->dev.of_node);
+err_pm_disable:
 	pm_runtime_disable(&pdev->dev);
 	return ret;
 }
-- 
2.25.1


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

* Re: [PATCH] dmaengine: rcar-dmac: refactor the error handling code of rcar_dmac_probe
  2021-10-20 14:35 [PATCH] dmaengine: rcar-dmac: refactor the error handling code of rcar_dmac_probe Dongliang Mu
@ 2021-10-21  8:57 ` Geert Uytterhoeven
  2021-10-22  6:35 ` Laurent Pinchart
  2021-10-25  4:24 ` Vinod Koul
  2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2021-10-21  8:57 UTC (permalink / raw)
  To: Dongliang Mu
  Cc: Vinod Koul, Yoshihiro Shimoda, Laurent Pinchart, Wolfram Sang,
	Zou Wei, dmaengine, Linux Kernel Mailing List

Hi Dongliang,

Thanks for your patch!

On Wed, Oct 20, 2021 at 4:36 PM Dongliang Mu <mudongliangabcd@gmail.com> wrote:
> In rcar_dmac_probe, if pm_runtime_resume_and_get fails, it forgets to
> disable runtime PM. And of_dma_controller_free should only be invoked
> after the success of of_dma_controller_register.

The second issue is actually harmless, as of_dma_controller_free()
is a no-op if the DMA controller was never registered.
Of course it doesn't hurt to improve symmetry.

> Fix this by refactoring the error handling code.
>
> Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] dmaengine: rcar-dmac: refactor the error handling code of rcar_dmac_probe
  2021-10-20 14:35 [PATCH] dmaengine: rcar-dmac: refactor the error handling code of rcar_dmac_probe Dongliang Mu
  2021-10-21  8:57 ` Geert Uytterhoeven
@ 2021-10-22  6:35 ` Laurent Pinchart
  2021-10-25  4:24 ` Vinod Koul
  2 siblings, 0 replies; 4+ messages in thread
From: Laurent Pinchart @ 2021-10-22  6:35 UTC (permalink / raw)
  To: Dongliang Mu
  Cc: Vinod Koul, Geert Uytterhoeven, Yoshihiro Shimoda, Wolfram Sang,
	Zou Wei, dmaengine, linux-kernel

Hi Dongliang,

Thank you for the patch.

On Wed, Oct 20, 2021 at 10:35:33PM +0800, Dongliang Mu wrote:
> In rcar_dmac_probe, if pm_runtime_resume_and_get fails, it forgets to
> disable runtime PM. And of_dma_controller_free should only be invoked
> after the success of of_dma_controller_register.
> 
> Fix this by refactoring the error handling code.
> 
> Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/dma/sh/rcar-dmac.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c
> index 6885b3dcd7a9..5c7716fd6bc5 100644
> --- a/drivers/dma/sh/rcar-dmac.c
> +++ b/drivers/dma/sh/rcar-dmac.c
> @@ -1916,7 +1916,7 @@ static int rcar_dmac_probe(struct platform_device *pdev)
>  	ret = pm_runtime_resume_and_get(&pdev->dev);
>  	if (ret < 0) {
>  		dev_err(&pdev->dev, "runtime PM get sync failed (%d)\n", ret);
> -		return ret;
> +		goto err_pm_disable;
>  	}
>  
>  	ret = rcar_dmac_init(dmac);
> @@ -1924,7 +1924,7 @@ static int rcar_dmac_probe(struct platform_device *pdev)
>  
>  	if (ret) {
>  		dev_err(&pdev->dev, "failed to reset device\n");
> -		goto error;
> +		goto err_pm_disable;
>  	}
>  
>  	/* Initialize engine */
> @@ -1958,14 +1958,14 @@ static int rcar_dmac_probe(struct platform_device *pdev)
>  	for_each_rcar_dmac_chan(i, dmac, chan) {
>  		ret = rcar_dmac_chan_probe(dmac, chan);
>  		if (ret < 0)
> -			goto error;
> +			goto err_pm_disable;
>  	}
>  
>  	/* Register the DMAC as a DMA provider for DT. */
>  	ret = of_dma_controller_register(pdev->dev.of_node, rcar_dmac_of_xlate,
>  					 NULL);
>  	if (ret < 0)
> -		goto error;
> +		goto err_pm_disable;
>  
>  	/*
>  	 * Register the DMA engine device.
> @@ -1974,12 +1974,13 @@ static int rcar_dmac_probe(struct platform_device *pdev)
>  	 */
>  	ret = dma_async_device_register(engine);
>  	if (ret < 0)
> -		goto error;
> +		goto err_dma_free;
>  
>  	return 0;
>  
> -error:
> +err_dma_free:
>  	of_dma_controller_free(pdev->dev.of_node);
> +err_pm_disable:
>  	pm_runtime_disable(&pdev->dev);
>  	return ret;
>  }

-- 
Regards,

Laurent Pinchart

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

* Re: [PATCH] dmaengine: rcar-dmac: refactor the error handling code of rcar_dmac_probe
  2021-10-20 14:35 [PATCH] dmaengine: rcar-dmac: refactor the error handling code of rcar_dmac_probe Dongliang Mu
  2021-10-21  8:57 ` Geert Uytterhoeven
  2021-10-22  6:35 ` Laurent Pinchart
@ 2021-10-25  4:24 ` Vinod Koul
  2 siblings, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2021-10-25  4:24 UTC (permalink / raw)
  To: Dongliang Mu
  Cc: Geert Uytterhoeven, Yoshihiro Shimoda, Laurent Pinchart,
	Wolfram Sang, Zou Wei, dmaengine, linux-kernel

On 20-10-21, 22:35, Dongliang Mu wrote:
> In rcar_dmac_probe, if pm_runtime_resume_and_get fails, it forgets to
> disable runtime PM. And of_dma_controller_free should only be invoked
> after the success of of_dma_controller_register.
> 
> Fix this by refactoring the error handling code.

Applied, thanks

-- 
~Vinod

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

end of thread, other threads:[~2021-10-25  4:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-20 14:35 [PATCH] dmaengine: rcar-dmac: refactor the error handling code of rcar_dmac_probe Dongliang Mu
2021-10-21  8:57 ` Geert Uytterhoeven
2021-10-22  6:35 ` Laurent Pinchart
2021-10-25  4:24 ` Vinod Koul

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