2017-12-06 11:19:44

by Andreas Platschek

[permalink] [raw]
Subject: [PATCH] dmaengine: fsl-edma: disable clks on all error paths

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 <[email protected]>
---
drivers/dma/fsl-edma.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/fsl-edma.c b/drivers/dma/fsl-edma.c
index 6775f2c74e25..ccb447253cd2 100644
--- a/drivers/dma/fsl-edma.c
+++ b/drivers/dma/fsl-edma.c
@@ -904,12 +904,23 @@ 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 */
+ i--;
+ for (; i >= 0; i--)
+ clk_disable_unprepare(fsl_edma->muxclk[i]);
+
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 */
+ i--;
+ for (; i >= 0; i--)
+ clk_disable_unprepare(fsl_edma->muxclk[i]);
+
dev_err(&pdev->dev, "Missing DMAMUX block clock.\n");
return PTR_ERR(fsl_edma->muxclk[i]);
}
--
2.11.0


2017-12-06 13:20:55

by Andreas Platschek

[permalink] [raw]
Subject: Re: [PATCH] dmaengine: fsl-edma: disable clks on all error paths

Hi,

On Wed, 06 Dec 2017, 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 <[email protected]>
> ---
> drivers/dma/fsl-edma.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/dma/fsl-edma.c b/drivers/dma/fsl-edma.c
> index 6775f2c74e25..ccb447253cd2 100644
> --- a/drivers/dma/fsl-edma.c
> +++ b/drivers/dma/fsl-edma.c
> @@ -904,12 +904,23 @@ 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 */
> + i--;
> + for (; i >= 0; i--)
> + clk_disable_unprepare(fsl_edma->muxclk[i]);
> +
> return PTR_ERR(fsl_edma->muxbase[i]);

just realized that I made a stupid mistake and overlooked that i is used again...

sorry for the noise I'll go over this again.

thx!
andi

> + }
>
> 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 */
> + i--;
> + for (; i >= 0; i--)
> + clk_disable_unprepare(fsl_edma->muxclk[i]);
> +
> dev_err(&pdev->dev, "Missing DMAMUX block clock.\n");
> return PTR_ERR(fsl_edma->muxclk[i]);
> }
> --
> 2.11.0
>