Skip to contentSkip to conversation

fix: i2c: i2c_mux_add_adapter: fix child device_node reference leak on adapter registration failure

PATCH In review WenTao Liang 1 participant 2 messages Jun 26 – Jun 28

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

PATCH 1/1 fix: i2c: i2c_mux_add_adapter: fix child device_node reference leak on adapter registration failure

When the OF block successfully acquires a child device_node reference and
stores it in priv->adap.dev.of_node, but the subsequent i2c_add_numbered_adapter or i2c_add_adapter call fails, the error path jumps to err_free_priv which only kfree's the priv without calling of_node_put on the stored child node, leaking the reference.

Add of_node_put(priv->adap.dev.of_node) in the err_free_priv error path.

Fixes a7ab72390b77 ("i2c: mux: add common data for every i2c-mux instance")
---
 drivers/i2c/i2c-mux.c | 1 +
 1 file changed, 1 insertion(+)
drivers/i2c/i2c-mux.c +1 -0
index 681a201c239b..68a4c34b5987 100644
@@ -408,6 +408,7 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
 	return 0;
 
 err_free_priv:
+	of_node_put(priv->adap.dev.of_node);
 	kfree(priv);
 	return ret;
 }
Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw
Quoted 28 lines

2026年6月26日 23:03,WenTao Liang <[email protected]> 写道:

When the OF block successfully acquires a child device_node reference and
stores it in priv->adap.dev.of_node, but the subsequent i2c_add_numbered_adapter or i2c_add_adapter call fails, the error path jumps to err_free_priv which only kfree's the priv without calling of_node_put on the stored child node, leaking the reference.

Add of_node_put(priv->adap.dev.of_node) in the err_free_priv error path.

Fixes a7ab72390b77 ("i2c: mux: add common data for every i2c-mux instance")

---
drivers/i2c/i2c-mux.c | 1 +

1 file changed, 1 insertion(+)
drivers/i2c/i2c-mux.c +0 -0
index 681a201c239b..68a4c34b5987 100644
@@ -408,6 +408,7 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
 	return 0;
 

err_free_priv:

drivers/i2c/i2c-mux.c +1 -0
+	of_node_put(priv->adap.dev.of_node);
Quoted 5 lines
	kfree(priv);
	return ret;
}
Signature · 1 line
2.39.5 (Apple Git-154)

Please ignore this patch. I will resend a proper version after learning the kernel submission process.

Apologies for the noise.

Best regards,
WenTao Liang