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

Nishka Dasgupta nishkadg.linux at gmail.com
Sat Jul 6 23:19:11 AEST 2019


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.

Signed-off-by: Nishka Dasgupta <nishkadg.linux at gmail.com>
---
 drivers/i2c/busses/i2c-fsi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c
index 1e2be2219a60..5e01875082c3 100644
--- a/drivers/i2c/busses/i2c-fsi.c
+++ b/drivers/i2c/busses/i2c-fsi.c
@@ -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;
-- 
2.19.1



More information about the openbmc mailing list