* [PATCH v2 1/1] i3c: fix refcount inconsistency in i3c_master_register
@ 2025-10-14 16:28 Frank Li
2025-10-15 15:43 ` Markus Elfring
0 siblings, 1 reply; 2+ messages in thread
From: Frank Li @ 2025-10-14 16:28 UTC (permalink / raw)
To: Alexandre Belloni, moderated list:I3C SUBSYSTEM, open list; +Cc: imx
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.
Move call i3c_bus_init() after device_initialize() to let callback
i3c_masterdev_release() release of_node.
Reported-by: Shuhao Fu <sfual@cse.ust.hk>
Closes: https://lore.kernel.org/linux-i3c/aO2tjp_FsV_WohPG@osx.local/T/#m2c05a982beeb14e7bf039c1d8db856734bf234c7
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
Change in v2:
use i3c_masterdev_release() to put of_node to align other error path
v1 by Shuhao Fu <sfual@cse.ust.hk>
https://lore.kernel.org/linux-i3c/aO2tjp_FsV_WohPG@osx.local/T/#m2c05a982beeb14e7bf039c1d8db856734bf234c7
---
drivers/i3c/master.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index f5f44bd4f4839..b36d4ffadeff2 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -2814,10 +2814,6 @@ int i3c_master_register(struct i3c_master_controller *master,
INIT_LIST_HEAD(&master->boardinfo.i2c);
INIT_LIST_HEAD(&master->boardinfo.i3c);
- ret = i3c_bus_init(i3cbus, master->dev.of_node);
- if (ret)
- return ret;
-
device_initialize(&master->dev);
dev_set_name(&master->dev, "i3c-%d", i3cbus->id);
@@ -2825,6 +2821,10 @@ int i3c_master_register(struct i3c_master_controller *master,
master->dev.coherent_dma_mask = parent->coherent_dma_mask;
master->dev.dma_parms = parent->dma_parms;
+ ret = i3c_bus_init(i3cbus, master->dev.of_node);
+ if (ret)
+ goto err_put_dev;
+
ret = of_populate_i3c_bus(master);
if (ret)
goto err_put_dev;
--
2.34.1
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2 1/1] i3c: fix refcount inconsistency in i3c_master_register
2025-10-14 16:28 [PATCH v2 1/1] i3c: fix refcount inconsistency in i3c_master_register Frank Li
@ 2025-10-15 15:43 ` Markus Elfring
0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2025-10-15 15:43 UTC (permalink / raw)
To: Frank Li, linux-i3c, imx, Alexandre Belloni
Cc: LKML, kernel-janitors, Shuhao Fu
> In `i3c_master_register`, a possible refcount inconsistency has been
> identified, causing possible resource leak.
…
How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
Regards,
Markus
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-15 15:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-14 16:28 [PATCH v2 1/1] i3c: fix refcount inconsistency in i3c_master_register Frank Li
2025-10-15 15:43 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox