hwmon: ina3221.c: Add of_node_put() before return
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
@@ -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
Quoted 7 lines · Nishka Dasgupta
Each iteration of
for_each_child_of_nodeputs 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 anof_node_putbefore the return.
Issue found with Coccinelle.Signed-off-by Nishka Dasgupta <[email protected]>
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@@ -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 ;
Quoted 11 lines · Guenter Roeck
Quoted 7 lines · Nishka Dasgupta
Each iteration of
for_each_child_of_nodeputs 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 anof_node_putbefore the return.
Issue found with Coccinelle.Signed-off-by Nishka Dasgupta <[email protected]>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,
GuenterQuoted 20 lines
--- drivers/hwmon/ina3221.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/hwmon/ina3221.c +3
-1@@ -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 ;