Skip to contentSkip to conversation

i2c: i2c-mux-gpmux: Add of_node_put() when breaking out of loop

PATCH Superseded Liang He 2 participants 3 messages Jul 21, 2022 – Jul 22, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Liang He

author
#0 lore raw

PATCH 1/1 i2c: i2c-mux-gpmux: Add of_node_put() when breaking out of loop

In i2c_mux_probe(), we should call of_node_put() when breaking out of for_each_child_of_node() which will automatically increase and decrease the refcount.

Fixes ac8498f0ce53 ("i2c: i2c-mux-gpmux: new driver")
---
 drivers/i2c/muxes/i2c-mux-gpmux.c | 1 +
 1 file changed, 1 insertion(+)
drivers/i2c/muxes/i2c-mux-gpmux.c +1 -0
index d3acd8d66c32..30ab2fe88c8d 100644
@@ -115,6 +115,7 @@ static int i2c_mux_probe(struct platform_device *pdev)
 		if (ret < 0) {
 			dev_err(dev, "no reg property for node '%pOFn'\n",
 				child);
+			of_node_put(child);
 			goto err_children;
 		}
 
Signature · 1 line
2.25.1
#1 lore raw

Hi!

Quoted 15 lines · Liang He

In i2c_mux_probe(), we should call of_node_put() when breaking out of for_each_child_of_node() which will automatically increase and decrease the refcount.

Fixes ac8498f0ce53 ("i2c: i2c-mux-gpmux: new driver")
---
 drivers/i2c/muxes/i2c-mux-gpmux.c | 1 +
 1 file changed, 1 insertion(+)
drivers/i2c/muxes/i2c-mux-gpmux.c +0 -0
index d3acd8d66c32..30ab2fe88c8d 100644

drivers/i2c/muxes/i2c-mux-gpmux.c static int i2c_mux_probe(struct platform_device *pdev) · line 121

Quoted 7 lines
drivers/i2c/muxes/i2c-mux-gpmux.c +1 -0
@@ -115,6 +115,7 @@ static int i2c_mux_probe(struct platform_device *pdev)
 		if (ret < 0) {
 			dev_err(dev, "no reg property for node '%pOFn'\n",
 				child);
+			of_node_put(child);
 			goto err_children;
 		}
 

Right, but this is obviously incomplete. What about the other two branches in that loop that breaks out?

Much better to have the missing of_node_put(child) statement below the
err_children: label (i.e. before i2c_mux_del_adapters) so that it is not forgotten in any code flow. child cannot be uninitialized at that point and if it happens to be NULL, of_node_put will be a nop. So that's safe.

Cheers,
Peter

author
#2 lore raw
Quoted 29 lines · Peter Rosin

Hi!

Quoted 15 lines · Liang He

In i2c_mux_probe(), we should call of_node_put() when breaking out of for_each_child_of_node() which will automatically increase and decrease the refcount.

Fixes ac8498f0ce53 ("i2c: i2c-mux-gpmux: new driver")
---
 drivers/i2c/muxes/i2c-mux-gpmux.c | 1 +
 1 file changed, 1 insertion(+)
drivers/i2c/muxes/i2c-mux-gpmux.c +0 -0
index d3acd8d66c32..30ab2fe88c8d 100644

drivers/i2c/muxes/i2c-mux-gpmux.c static int i2c_mux_probe(struct platform_device *pdev) · line 121

Quoted 7 lines
drivers/i2c/muxes/i2c-mux-gpmux.c +1 -0
@@ -115,6 +115,7 @@ static int i2c_mux_probe(struct platform_device *pdev)
 		if (ret < 0) {
 			dev_err(dev, "no reg property for node '%pOFn'\n",
 				child);
+			of_node_put(child);
 			goto err_children;
 		}
 

Right, but this is obviously incomplete. What about the other two branches in that loop that breaks out?

Quoted 7 lines

Much better to have the missing of_node_put(child) statement below the
err_children: label (i.e. before i2c_mux_del_adapters) so that it is not forgotten in any code flow. child cannot be uninitialized at that point and if it happens to be NULL, of_node_put will be a nop. So that's safe.

Cheers,
Peter

Thanks, Peter,

I have forgotten add of_node_put() in other fail path. But your advice is better, I will send a new version soon!

Thanks again,

Liang