Commit 9d4f2198 authored by Frank Li's avatar Frank Li Committed by Alexandre Belloni
Browse files

i3c: fix refcount inconsistency in i3c_master_register



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: default avatarShuhao Fu <sfual@cse.ust.hk>
Closes: https://lore.kernel.org/linux-i3c/aO2tjp_FsV_WohPG@osx.local/T/#m2c05a982beeb14e7bf039c1d8db856734bf234c7


Fixes: 3a379bbc ("i3c: Add core I3C infrastructure")
Signed-off-by: default avatarFrank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/20251016143814.2551256-1-Frank.Li@nxp.com


Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 3a866087
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -2883,10 +2883,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);

@@ -2894,6 +2890,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;