Skip to contentSkip to conversation

dmaengine: dw: fix potential memory leak in dw_dma_parse_dt()

PATCH Applied Mans Rullgard 3 participants 3 messages Dec 17, 2015 – Dec 18, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: dw: fix potential memory leak in dw_dma_parse_dt()

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.

---
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(-)
drivers/dma/dw/platform.c +5 -2
index 68a4815..5a417bb 100644
@@ -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;
Signature · 1 line
2.6.3
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Mans Rullgard

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.

Quoted 6 lines

---
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(-)
Signature · 1 line
viresh
Applied
#2 lore raw
In reply to Mans Rullgard
Quoted 8 lines · Mans Rullgard

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

Signature · 1 line
~Vinod