All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] dmaengine: fsl-edma: disable clks on all error paths
@ 2017-12-06 13:50 Andreas Platschek
  2017-12-13  4:54 ` Vinod Koul
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Platschek @ 2017-12-06 13:50 UTC (permalink / raw)
  To: vinod.koul; +Cc: dmaengine, linux-kernel, dan.j.williams, Andreas Platschek

Previously enabled clks are only disabled if clk_prepare_enable() fails.
However, there are other error paths were the previously enabled
clocks are not disabled.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Andreas Platschek <andreas.platschek@opentech.at>
---
 drivers/dma/fsl-edma.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/fsl-edma.c b/drivers/dma/fsl-edma.c
index 6775f2c74e25..9940f2f7039f 100644
--- a/drivers/dma/fsl-edma.c
+++ b/drivers/dma/fsl-edma.c
@@ -878,7 +878,7 @@ static int fsl_edma_probe(struct platform_device *pdev)
 	struct fsl_edma_chan *fsl_chan;
 	struct resource *res;
 	int len, chans;
-	int ret, i;
+	int ret, i, j;
 
 	ret = of_property_read_u32(np, "dma-channels", &chans);
 	if (ret) {
@@ -904,12 +904,21 @@ static int fsl_edma_probe(struct platform_device *pdev)
 
 		res = platform_get_resource(pdev, IORESOURCE_MEM, 1 + i);
 		fsl_edma->muxbase[i] = devm_ioremap_resource(&pdev->dev, res);
-		if (IS_ERR(fsl_edma->muxbase[i]))
+		if (IS_ERR(fsl_edma->muxbase[i])) {
+			/* disable only clks which were enabled on error */
+			for (j = i-1; j >= 0; j--)
+				clk_disable_unprepare(fsl_edma->muxclk[j]);
+
 			return PTR_ERR(fsl_edma->muxbase[i]);
+		}
 
 		sprintf(clkname, "dmamux%d", i);
 		fsl_edma->muxclk[i] = devm_clk_get(&pdev->dev, clkname);
 		if (IS_ERR(fsl_edma->muxclk[i])) {
+			/* disable only clks which were enabled on error */
+			for (j = i-1; j >= 0; j--)
+				clk_disable_unprepare(fsl_edma->muxclk[j]);
+
 			dev_err(&pdev->dev, "Missing DMAMUX block clock.\n");
 			return PTR_ERR(fsl_edma->muxclk[i]);
 		}
-- 
2.11.0

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

* Re: [PATCH v2] dmaengine: fsl-edma: disable clks on all error paths
  2017-12-06 13:50 [PATCH v2] dmaengine: fsl-edma: disable clks on all error paths Andreas Platschek
@ 2017-12-13  4:54 ` Vinod Koul
  0 siblings, 0 replies; 2+ messages in thread
From: Vinod Koul @ 2017-12-13  4:54 UTC (permalink / raw)
  To: Andreas Platschek; +Cc: dmaengine, linux-kernel, dan.j.williams

On Wed, Dec 06, 2017 at 02:50:23PM +0100, Andreas Platschek wrote:
> Previously enabled clks are only disabled if clk_prepare_enable() fails.
> However, there are other error paths were the previously enabled
> clocks are not disabled.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Andreas Platschek <andreas.platschek@opentech.at>
> ---
>  drivers/dma/fsl-edma.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/fsl-edma.c b/drivers/dma/fsl-edma.c
> index 6775f2c74e25..9940f2f7039f 100644
> --- a/drivers/dma/fsl-edma.c
> +++ b/drivers/dma/fsl-edma.c
> @@ -878,7 +878,7 @@ static int fsl_edma_probe(struct platform_device *pdev)
>  	struct fsl_edma_chan *fsl_chan;
>  	struct resource *res;
>  	int len, chans;
> -	int ret, i;
> +	int ret, i, j;
>  
>  	ret = of_property_read_u32(np, "dma-channels", &chans);
>  	if (ret) {
> @@ -904,12 +904,21 @@ static int fsl_edma_probe(struct platform_device *pdev)
>  
>  		res = platform_get_resource(pdev, IORESOURCE_MEM, 1 + i);
>  		fsl_edma->muxbase[i] = devm_ioremap_resource(&pdev->dev, res);
> -		if (IS_ERR(fsl_edma->muxbase[i]))
> +		if (IS_ERR(fsl_edma->muxbase[i])) {
> +			/* disable only clks which were enabled on error */
> +			for (j = i-1; j >= 0; j--)
				^^^
space around - pls
> +				clk_disable_unprepare(fsl_edma->muxclk[j]);

why not modify fsl_disable_clocks() and invoke that...?

>  
>  		sprintf(clkname, "dmamux%d", i);
>  		fsl_edma->muxclk[i] = devm_clk_get(&pdev->dev, clkname);
>  		if (IS_ERR(fsl_edma->muxclk[i])) {
> +			/* disable only clks which were enabled on error */
> +			for (j = i-1; j >= 0; j--)
> +				clk_disable_unprepare(fsl_edma->muxclk[j]);

ditto

-- 
~Vinod

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

end of thread, other threads:[~2017-12-13  4:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-06 13:50 [PATCH v2] dmaengine: fsl-edma: disable clks on all error paths Andreas Platschek
2017-12-13  4:54 ` Vinod Koul

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.