Skip to content

Commit d3bacdd

Browse files
nxpfrankligregkh
authored andcommitted
i3c: fix refcount inconsistency in i3c_master_register
[ Upstream commit 9d4f219 ] 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 Fixes: 3a379bb ("i3c: Add core I3C infrastructure") Signed-off-by: Frank Li <Frank.Li@nxp.com> Link: https://patch.msgid.link/20251016143814.2551256-1-Frank.Li@nxp.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6b860ae commit d3bacdd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/i3c/master.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,17 +2809,17 @@ int i3c_master_register(struct i3c_master_controller *master,
28092809
INIT_LIST_HEAD(&master->boardinfo.i2c);
28102810
INIT_LIST_HEAD(&master->boardinfo.i3c);
28112811

2812-
ret = i3c_bus_init(i3cbus, master->dev.of_node);
2813-
if (ret)
2814-
return ret;
2815-
28162812
device_initialize(&master->dev);
28172813
dev_set_name(&master->dev, "i3c-%d", i3cbus->id);
28182814

28192815
master->dev.dma_mask = parent->dma_mask;
28202816
master->dev.coherent_dma_mask = parent->coherent_dma_mask;
28212817
master->dev.dma_parms = parent->dma_parms;
28222818

2819+
ret = i3c_bus_init(i3cbus, master->dev.of_node);
2820+
if (ret)
2821+
goto err_put_dev;
2822+
28232823
ret = of_populate_i3c_bus(master);
28242824
if (ret)
28252825
goto err_put_dev;

0 commit comments

Comments
 (0)