public inbox for linux-i3c@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v3 1/1] i3c: fix refcount inconsistency in i3c_master_register
@ 2025-10-16 14:38 Frank Li
  2025-10-16 15:07 ` [PATCH v3] " Markus Elfring
  2025-10-30 23:43 ` [PATCH v3 1/1] " Alexandre Belloni
  0 siblings, 2 replies; 4+ messages in thread
From: Frank Li @ 2025-10-16 14:38 UTC (permalink / raw)
  To: Alexandre Belloni, Boris Brezillon, Arnd Bergmann,
	Greg Kroah-Hartman, moderated list:I3C SUBSYSTEM, open list
  Cc: markus.elfring, 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
Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure")
Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
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 <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 2ef898a8fd806..8efec085d396c 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -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;
-- 
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] 4+ messages in thread

* Re: [PATCH v3] i3c: fix refcount inconsistency in i3c_master_register
  2025-10-16 14:38 [PATCH v3 1/1] i3c: fix refcount inconsistency in i3c_master_register Frank Li
@ 2025-10-16 15:07 ` Markus Elfring
  2025-10-16 15:11   ` Greg Kroah-Hartman
  2025-10-30 23:43 ` [PATCH v3 1/1] " Alexandre Belloni
  1 sibling, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2025-10-16 15:07 UTC (permalink / raw)
  To: Frank Li, linux-i3c, Alexandre Belloni, Arnd Bergmann,
	Boris Brezillon, Greg Kroah-Hartman
  Cc: imx, LKML, kernel-janitors, Shuhao Fu

> 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

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

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

* Re: [PATCH v3] i3c: fix refcount inconsistency in i3c_master_register
  2025-10-16 15:07 ` [PATCH v3] " Markus Elfring
@ 2025-10-16 15:11   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2025-10-16 15:11 UTC (permalink / raw)
  To: Markus Elfring
  Cc: Frank Li, linux-i3c, Alexandre Belloni, Arnd Bergmann,
	Boris Brezillon, imx, LKML, kernel-janitors, Shuhao Fu

On Thu, Oct 16, 2025 at 05:07:38PM +0200, Markus Elfring wrote:
> > 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

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

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

* Re: [PATCH v3 1/1] i3c: fix refcount inconsistency in i3c_master_register
  2025-10-16 14:38 [PATCH v3 1/1] i3c: fix refcount inconsistency in i3c_master_register Frank Li
  2025-10-16 15:07 ` [PATCH v3] " Markus Elfring
@ 2025-10-30 23:43 ` Alexandre Belloni
  1 sibling, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2025-10-30 23:43 UTC (permalink / raw)
  To: linux-i3c, linux-kernel, Frank Li; +Cc: imx

On Thu, 16 Oct 2025 10:38:13 -0400, Frank Li wrote:
> 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,

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

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

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

end of thread, other threads:[~2025-10-30 23:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-16 14:38 [PATCH v3 1/1] i3c: fix refcount inconsistency in i3c_master_register Frank Li
2025-10-16 15:07 ` [PATCH v3] " Markus Elfring
2025-10-16 15:11   ` Greg Kroah-Hartman
2025-10-30 23:43 ` [PATCH v3 1/1] " Alexandre Belloni

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