Skip to contentSkip to conversation

dma: qcom: hidma_mgmt: Add of_node_put() before goto

PATCH In review Nishka Dasgupta 3 participants 3 messages Jul 24, 2019 – Aug 8, 2019

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

PATCH v2 1/1 dma: qcom: hidma_mgmt: Add of_node_put() before goto

Each iteration of for_each_available_child_of_node puts the previous node, but in the case of a goto from the middle of the loop, there is no put, thus causing a memory leak.
Hence add an of_node_put under the label that the gotos point to. In order to avoid decrementing an already-decremented refcount, copy the original contents of the label (including the return statement) to just above the label, so that the code under the label is executed only when a goto exit from the loop occurs.
Additionally, remove an unnecessary get/put pair from the loop, as the loop itself already keeps track of refcount.
Issue found with Coccinelle.

---
Changes in v2:
- Move the put under the label instead of above each individual goto. -Remove the get/put pair.

 drivers/dma/qcom/hidma_mgmt.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/dma/qcom/hidma_mgmt.c +6 -2
index 3022d66e7a33..43f806c8b51e 100644
@@ -388,7 +388,6 @@ static int __init hidma_mgmt_of_populate_channels(struct device_node *np)
 			ret = PTR_ERR(new_pdev);
 			goto out;
 		}
-		of_node_get(child);
 		new_pdev->dev.of_node = child;
 		of_dma_configure(&new_pdev->dev, child, true);
 		/*
@@ -396,9 +395,14 @@ static int __init hidma_mgmt_of_populate_channels(struct device_node *np)
 		 * platforms with or without MSI support.
 		 */
 		of_msi_configure(&new_pdev->dev, child);
-		of_node_put(child);
 	}
+
+	kfree(res);
+
+	return ret;
+
 out:
+	of_node_put(child);
 	kfree(res);
 
 	return ret;
Signature · 1 line
2.19.1
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 12 lines · Nishka Dasgupta

Each iteration of for_each_available_child_of_node puts the previous node, but in the case of a goto from the middle of the loop, there is no put, thus causing a memory leak.
Hence add an of_node_put under the label that the gotos point to. In order to avoid decrementing an already-decremented refcount, copy the original contents of the label (including the return statement) to just above the label, so that the code under the label is executed only when a goto exit from the loop occurs.
Additionally, remove an unnecessary get/put pair from the loop, as the loop itself already keeps track of refcount.
Issue found with Coccinelle.

Quoted 1 line

nit: please post v3 with dmaengine:qcom:hidma_mgmt:....

Vinod doesn't like commit subjectss in this directory to have dma name on it. You can keep my acked-by.

maintainer
#2 lore raw
Quoted 13 lines · Sinan Kaya
Quoted 12 lines · Nishka Dasgupta

Each iteration of for_each_available_child_of_node puts the previous node, but in the case of a goto from the middle of the loop, there is no put, thus causing a memory leak.
Hence add an of_node_put under the label that the gotos point to. In order to avoid decrementing an already-decremented refcount, copy the original contents of the label (including the return statement) to just above the label, so that the code under the label is executed only when a goto exit from the loop occurs.
Additionally, remove an unnecessary get/put pair from the loop, as the loop itself already keeps track of refcount.
Issue found with Coccinelle.

Quoted 6 lines
Quoted 1 line

nit: please post v3 with dmaengine:qcom:hidma_mgmt:....

Vinod doesn't like commit subjectss in this directory to have dma name on it. You can keep my acked-by.

That's right but I am okay to hand edit while applying for drive by contributors :) so applied with you ack

Quoted 2 lines
Signature · 1 line
~Vinod