linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: dw: fix potential memory leak in dw_dma_parse_dt()
@ 2015-12-17 23:30 Mans Rullgard
  2015-12-18  1:59 ` Viresh Kumar
  2015-12-18  5:30 ` Vinod Koul
  0 siblings, 2 replies; 3+ messages in thread
From: Mans Rullgard @ 2015-12-17 23:30 UTC (permalink / raw)
  To: Viresh Kumar, Andy Shevchenko, Dan Williams, Vinod Koul,
	dmaengine, linux-kernel
  Cc: Julian Margetson

If the "dma-channels" DT property is missing, the dw_dma_parse_dt()
function return NULL, but not before allocating memory for a struct
dw_dma_platform_data through devres.  If the device supports parameter
detection, the probe still succeeds and the allocated memory is not
released until the device is removed.

Fix this by deferring the allocation until after checking the
"dma-channels" property.

Signed-off-by: Mans Rullgard <mans@mansr.com>
---
This has only been compile-tested as I have no suitable hardware.
---
 drivers/dma/dw/platform.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/dw/platform.c b/drivers/dma/dw/platform.c
index 68a4815..5a417bb 100644
--- a/drivers/dma/dw/platform.c
+++ b/drivers/dma/dw/platform.c
@@ -103,18 +103,21 @@ dw_dma_parse_dt(struct platform_device *pdev)
 	struct device_node *np = pdev->dev.of_node;
 	struct dw_dma_platform_data *pdata;
 	u32 tmp, arr[DW_DMA_MAX_NR_MASTERS];
+	u32 nr_channels;
 
 	if (!np) {
 		dev_err(&pdev->dev, "Missing DT data\n");
 		return NULL;
 	}
 
+	if (of_property_read_u32(np, "dma-channels", &nr_channels))
+		return NULL;
+
 	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
 		return NULL;
 
-	if (of_property_read_u32(np, "dma-channels", &pdata->nr_channels))
-		return NULL;
+	pdata->nr_channels = nr_channels;
 
 	if (of_property_read_bool(np, "is_private"))
 		pdata->is_private = true;
-- 
2.6.3


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

* Re: [PATCH] dmaengine: dw: fix potential memory leak in dw_dma_parse_dt()
  2015-12-17 23:30 [PATCH] dmaengine: dw: fix potential memory leak in dw_dma_parse_dt() Mans Rullgard
@ 2015-12-18  1:59 ` Viresh Kumar
  2015-12-18  5:30 ` Vinod Koul
  1 sibling, 0 replies; 3+ messages in thread
From: Viresh Kumar @ 2015-12-18  1:59 UTC (permalink / raw)
  To: Mans Rullgard
  Cc: Viresh Kumar, Andy Shevchenko, Dan Williams, Vinod Koul,
	dmaengine, linux-kernel, Julian Margetson

On 17-12-15, 23:30, Mans Rullgard wrote:
> If the "dma-channels" DT property is missing, the dw_dma_parse_dt()
> function return NULL, but not before allocating memory for a struct
> dw_dma_platform_data through devres.  If the device supports parameter
> detection, the probe still succeeds and the allocated memory is not
> released until the device is removed.
> 
> Fix this by deferring the allocation until after checking the
> "dma-channels" property.
> 
> Signed-off-by: Mans Rullgard <mans@mansr.com>
> ---
> This has only been compile-tested as I have no suitable hardware.
> ---
>  drivers/dma/dw/platform.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

-- 
viresh

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

* Re: [PATCH] dmaengine: dw: fix potential memory leak in dw_dma_parse_dt()
  2015-12-17 23:30 [PATCH] dmaengine: dw: fix potential memory leak in dw_dma_parse_dt() Mans Rullgard
  2015-12-18  1:59 ` Viresh Kumar
@ 2015-12-18  5:30 ` Vinod Koul
  1 sibling, 0 replies; 3+ messages in thread
From: Vinod Koul @ 2015-12-18  5:30 UTC (permalink / raw)
  To: Mans Rullgard
  Cc: Viresh Kumar, Andy Shevchenko, Dan Williams, dmaengine,
	linux-kernel, Julian Margetson

On Thu, Dec 17, 2015 at 11:30:57PM +0000, Mans Rullgard wrote:
> If the "dma-channels" DT property is missing, the dw_dma_parse_dt()
> function return NULL, but not before allocating memory for a struct
> dw_dma_platform_data through devres.  If the device supports parameter
> detection, the probe still succeeds and the allocated memory is not
> released until the device is removed.
> 
> Fix this by deferring the allocation until after checking the
> "dma-channels" property.

Applied, thanks

-- 
~Vinod

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

end of thread, other threads:[~2015-12-18  5:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-17 23:30 [PATCH] dmaengine: dw: fix potential memory leak in dw_dma_parse_dt() Mans Rullgard
2015-12-18  1:59 ` Viresh Kumar
2015-12-18  5:30 ` 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).