Skip to contentSkip to conversation

hwmon: ina3221.c: Add of_node_put() before return

PATCH Applied Nishka Dasgupta 2 participants 3 messages Jul 6, 2019 – Jul 11, 2019 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: ina3221.c: Add of_node_put() before return

Each iteration of for_each_child_of_node puts the previous node, but in the case of a return from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the return.
Issue found with Coccinelle.

---
 drivers/hwmon/ina3221.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwmon/ina3221.c +3 -1
index 55943b4dcc7b..0037e2bdacd6 100644
@@ -713,8 +713,10 @@ static int ina3221_probe_from_dt(struct device *dev, struct ina3221_data *ina)
 
 	for_each_child_of_node(np, child) {
 		ret = ina3221_probe_child_from_dt(dev, child, ina);
-		if (ret)
+		if (ret) {
+			of_node_put(child);
 			return ret;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.19.1
maintainer Applied
#1 lore raw
Quoted 7 lines · Nishka Dasgupta

Each iteration of for_each_child_of_node puts the previous node, but in the case of a return from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the return.
Issue found with Coccinelle.

Applied. For future patches, please don't put source file extensions into the subject line.

Thanks,
Guenter

Quoted 20 lines
---
 drivers/hwmon/ina3221.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwmon/ina3221.c +3 -1
index 55943b4dcc7b..0037e2bdacd6 100644
@@ -713,8 +713,10 @@ static int ina3221_probe_from_dt(struct device *dev, struct ina3221_data *ina)
 
 	for_each_child_of_node(np, child) {
 		ret = ina3221_probe_child_from_dt(dev, child, ina);
-		if (ret)
+		if (ret) {
+			of_node_put(child);
 			return ret;
+		}
 	}
 
 	return 0;
#2 lore raw
Quoted 11 lines · Guenter Roeck
Quoted 7 lines · Nishka Dasgupta

Each iteration of for_each_child_of_node puts the previous node, but in the case of a return from the middle of the loop, there is no put, thus causing a memory leak. Hence add an of_node_put before the return.
Issue found with Coccinelle.

Applied. For future patches, please don't put source file extensions into the subject line.

I will keep that in mind, thank you.

Thanking you,
Nishka

Quoted 23 lines

Thanks,
Guenter

Quoted 20 lines
---
  drivers/hwmon/ina3221.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwmon/ina3221.c +3 -1
index 55943b4dcc7b..0037e2bdacd6 100644
@@ -713,8 +713,10 @@ static int ina3221_probe_from_dt(struct device *dev, struct ina3221_data *ina)
 
  	for_each_child_of_node(np, child) {
  		ret = ina3221_probe_child_from_dt(dev, child, ina);
-		if (ret)
+		if (ret) {
+			of_node_put(child);
  			return ret;
+		}
  	}
 
  	return 0;