2018-04-04 03:23:38

by Xidong Wang

[permalink] [raw]
Subject: [PATCH 1/1] dmaengine:jz4740:fix memory leak

In function jz4740_dma_probe(), the memory allocated by
clk_get() is not released on the error path that ret, which holds
the return value of dma_async_device_register(), is not NULL.
This will result in a memory leak bug.

Signed-off-by: Xidong Wang <[email protected]>
---
drivers/dma/dma-jz4740.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/dma/dma-jz4740.c b/drivers/dma/dma-jz4740.c
index afd5e10..082c158 100644
--- a/drivers/dma/dma-jz4740.c
+++ b/drivers/dma/dma-jz4740.c
@@ -570,6 +570,7 @@ static int jz4740_dma_probe(struct platform_device *pdev)
dma_async_device_unregister(dd);
err_clk:
clk_disable_unprepare(dmadev->clk);
+ clk_put(dmadev->clk);
return ret;
}

--
2.7.4




2018-04-04 05:58:00

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH 1/1] dmaengine:jz4740:fix memory leak

On Wed, Apr 04, 2018 at 11:21:58AM +0800, Xidong Wang wrote:
> In function jz4740_dma_probe(), the memory allocated by
> clk_get() is not released on the error path that ret, which holds
> the return value of dma_async_device_register(), is not NULL.
> This will result in a memory leak bug.

I dont think we cna cal it mem leak, it seems your ref counting of clock
resource is imbalance as you dont free up which eventually would lead to mem
leak. Also dabove description needs a bit of cleanup please

>
> Signed-off-by: Xidong Wang <[email protected]>
> ---
> drivers/dma/dma-jz4740.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/dma/dma-jz4740.c b/drivers/dma/dma-jz4740.c
> index afd5e10..082c158 100644
> --- a/drivers/dma/dma-jz4740.c
> +++ b/drivers/dma/dma-jz4740.c
> @@ -570,6 +570,7 @@ static int jz4740_dma_probe(struct platform_device *pdev)
> dma_async_device_unregister(dd);
> err_clk:
> clk_disable_unprepare(dmadev->clk);
> + clk_put(dmadev->clk);
> return ret;
> }
>
> --
> 2.7.4
>
>

--
~Vinod

2018-04-04 12:47:11

by Lars-Peter Clausen

[permalink] [raw]
Subject: Re: [PATCH 1/1] dmaengine:jz4740:fix memory leak

On 04/04/2018 05:21 AM, Xidong Wang wrote:
> In function jz4740_dma_probe(), the memory allocated by
> clk_get() is not released on the error path that ret, which holds
> the return value of dma_async_device_register(), is not NULL.
> This will result in a memory leak bug.
>
> Signed-off-by: Xidong Wang <[email protected]>

Maybe use devm_clk_get() since the same clk_put() call is missing in the
remove callback.

> ---
> drivers/dma/dma-jz4740.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/dma/dma-jz4740.c b/drivers/dma/dma-jz4740.c
> index afd5e10..082c158 100644
> --- a/drivers/dma/dma-jz4740.c
> +++ b/drivers/dma/dma-jz4740.c
> @@ -570,6 +570,7 @@ static int jz4740_dma_probe(struct platform_device *pdev)
> dma_async_device_unregister(dd);
> err_clk:
> clk_disable_unprepare(dmadev->clk);
> + clk_put(dmadev->clk);
> return ret;
> }
>
>