public inbox for linux-i3c@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] i3c: fix refcount inconsistency in i3c_master_register
@ 2025-10-08  7:27 Shuhao Fu
  2025-10-09 16:17 ` Frank Li
  0 siblings, 1 reply; 7+ messages in thread
From: Shuhao Fu @ 2025-10-08  7:27 UTC (permalink / raw)
  To: Alexandre Belloni; +Cc: Frank Li, linux-i3c, linux-kernel

In `i3c_master_register`, a possible refcount inconsistency has been
identified, causing possible resource leak.

Function `of_node_get` increases the refcount of `parent->of_node`. If 
function `i3c_bus_init` fails, the function returns immediately without
a corresponding decrease, resulting in an inconsistent refcounter.

In this patch, an extra goto label is added to ensure the balance of
refcount when `i3c_bus_init` fails.

Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure")
Signed-off-by: Shuhao Fu <sfual@cse.ust.hk>
---
 drivers/i3c/master.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index d946db75d..9f4fe98d2 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -2885,7 +2885,7 @@ int i3c_master_register(struct i3c_master_controller *master,
 
 	ret = i3c_bus_init(i3cbus, master->dev.of_node);
 	if (ret)
-		return ret;
+		goto err_put_of_node;
 
 	device_initialize(&master->dev);
 	dev_set_name(&master->dev, "i3c-%d", i3cbus->id);
@@ -2973,6 +2973,9 @@ int i3c_master_register(struct i3c_master_controller *master,
 err_put_dev:
 	put_device(&master->dev);
 
+err_put_of_node:
+	of_node_put(master->dev.of_node);
+
 	return ret;
 }
 EXPORT_SYMBOL_GPL(i3c_master_register);
-- 
2.39.5 (Apple Git-154)


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-10-14  1:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-08  7:27 [PATCH] i3c: fix refcount inconsistency in i3c_master_register Shuhao Fu
2025-10-09 16:17 ` Frank Li
2025-10-10  6:34   ` Shuhao Fu
2025-10-13 20:19     ` Frank Li
2025-10-13 21:09       ` Shuhao Fu
2025-10-13 22:01         ` Frank Li
2025-10-14  1:55           ` Shuhao Fu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox