Skip to contentSkip to conversation

i3c: fix refcount inconsistency in i3c_master_register

PATCH Applied Frank Li 4 participants 4 messages Oct 16, 2025 – Oct 30, 2025

Subsystems (3)
lore
Share & tools
lore

Frank Li

author maintainer
#0 lore raw

PATCH v3 1/1 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.

---
Change in v3:
- add fixes tags

Change in v2:
- use i3c_masterdev_release() to put of_node to align other error path

v1 by Shuhao Fu <[email protected]>

https://lore.kernel.org/linux-i3c/[email protected]/T/#m2c05a982beeb14e7bf039c1d8db856734bf234c7

---
 drivers/i3c/master.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i3c/master.c +4 -4
index 2ef898a8fd806..8efec085d396c 100644
@@ -2811,10 +2811,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);
 
@@ -2822,6 +2818,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;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 2 lines

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

…

* Can it be preferred to refer to the term “reference count”?

* Would it be helpful to append parentheses to function names at more places?

Regards,
Markus

#2 lore raw
Quoted 11 lines · Markus Elfring
Quoted 2 lines

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

…

* Can it be preferred to refer to the term “reference count”?

* Would it be helpful to append parentheses to function names at more places?

Regards,
Markus

Hi,

This is the semi-friendly patch-bot of Greg Kroah-Hartman.

Markus, you seem to have sent a nonsensical or otherwise pointless review comment to a patch submission on a Linux kernel developer mailing list. I strongly suggest that you not do this anymore. Please do not bother developers who are actively working to produce patches and features with comments that, in the end, are a waste of time.

Patch submitter, please ignore Markus's suggestion; you do not need to follow it at all. The person/bot/AI that sent it is being ignored by almost all Linux kernel maintainers for having a persistent pattern of behavior of producing distracting and pointless commentary, and inability to adapt to feedback. Please feel free to also ignore emails from them.

thanks,

greg k-h's patch email bot

maintainer Applied
#3 lore raw
In reply to Frank Li
Quoted 8 lines · Frank Li

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.

[...]

Applied, thanks!

[1/1] i3c: fix refcount inconsistency in i3c_master_register

      https://git.kernel.org/abelloni/c/9d4f219807d5

Best regards,

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com