Skip to contentSkip to conversation

i2c: busses: i2c-fsi.c: Add of_put_node() before break

PATCH Applied Nishka Dasgupta 3 participants 4 messages Jul 6, 2019 – Sep 3, 2019

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

PATCH 1/1 i2c: busses: i2c-fsi.c: Add of_put_node() before break

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

---
 drivers/i2c/busses/i2c-fsi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-fsi.c +3 -1
index 1e2be2219a60..5e01875082c3 100644
@@ -685,8 +685,10 @@ static int fsi_i2c_probe(struct device *dev)
 			continue;
 
 		port = kzalloc(sizeof(*port), GFP_KERNEL);
-		if (!port)
+		if (!port) {
+			of_node_put(np);
 			break;
+		}
 
 		port->master = i2c;
 		port->port = port_no;
Signature · 1 line
2.19.1
#1 lore raw
Quoted 8 lines · Nishka Dasgupta

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

---

Eddie, are you okay with this change?

Quoted 22 lines
 drivers/i2c/busses/i2c-fsi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-fsi.c +3 -1
index 1e2be2219a60..5e01875082c3 100644
@@ -685,8 +685,10 @@ static int fsi_i2c_probe(struct device *dev)
 			continue;
 
 		port = kzalloc(sizeof(*port), GFP_KERNEL);
-		if (!port)
+		if (!port) {
+			of_node_put(np);
 			break;
+		}
 
 		port->master = i2c;
 		port->port = port_no;
Signature · 1 line
2.19.1
Reviewed-by
#2 lore raw
Quoted 10 lines · Wolfram Sang
Quoted 8 lines · Nishka Dasgupta

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

---

Eddie, are you okay with this change?

Yes, sorry must have missed this when it first came in.

Thanks.

Quoted 23 lines
Quoted 23 lines
  drivers/i2c/busses/i2c-fsi.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-fsi.c +3 -1
index 1e2be2219a60..5e01875082c3 100644
@@ -685,8 +685,10 @@ static int fsi_i2c_probe(struct device *dev)
  			continue;
 
  		port = kzalloc(sizeof(*port), GFP_KERNEL);
-		if (!port)
+		if (!port) {
+			of_node_put(np);
  			break;
+		}
 
  		port->master = i2c;
  		port->port = port_no;
Signature · 1 line
2.19.1
Applied
#3 lore raw
In reply to Nishka Dasgupta
Quoted 7 lines · Nishka Dasgupta

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

Applied to for-next, thanks!