Skip to contentSkip to conversation

soc: qcom: smp2p: Add of_node_put() at goto

PATCH New Nishka Dasgupta 1 participant 1 message Aug 8, 2019

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

PATCH v2 1/1 soc: qcom: smp2p: Add of_node_put() at 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() before each mid-loop goto.
Issue found with Coccinelle.

---
Changes in v2:
- Remove the extra label.
- Add the of_node_put() statements individually before each goto.

 drivers/soc/qcom/smp2p.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/soc/qcom/smp2p.c +10 -3
index c7300d54e444..c51b392f4000 100644
@@ -501,6 +501,7 @@ static int qcom_smp2p_probe(struct platform_device *pdev)
 		entry = devm_kzalloc(&pdev->dev, sizeof(*entry), GFP_KERNEL);
 		if (!entry) {
 			ret = -ENOMEM;
+			of_node_put(node);
 			goto unwind_interfaces;
 		}
 
@@ -508,19 +509,25 @@ static int qcom_smp2p_probe(struct platform_device *pdev)
 		spin_lock_init(&entry->lock);
 
 		ret = of_property_read_string(node, "qcom,entry-name", &entry->name);
-		if (ret < 0)
+		if (ret < 0) {
+			of_node_put(node);
 			goto unwind_interfaces;
+		}
 
 		if (of_property_read_bool(node, "interrupt-controller")) {
 			ret = qcom_smp2p_inbound_entry(smp2p, entry, node);
-			if (ret < 0)
+			if (ret < 0) {
+				of_node_put(node);
 				goto unwind_interfaces;
+			}
 
 			list_add(&entry->node, &smp2p->inbound);
 		} else  {
 			ret = qcom_smp2p_outbound_entry(smp2p, entry, node);
-			if (ret < 0)
+			if (ret < 0) {
+				of_node_put(node);
 				goto unwind_interfaces;
+			}
 
 			list_add(&entry->node, &smp2p->outbound);
 		}
Signature · 1 line
2.19.1