mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wentao Liang <vulab@iscas.ac.cn>
To: Alexandre Belloni <alexandre.belloni@bootlin.com>,
	linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org
Cc: Frank Li <Frank.li@oss.nxp.com>, Frank Li <Frank.Li@kernel.org>,
	vulab@iscas.ac.cn
Subject: [PATCH v2] i3c: master: Fix fwnode reference leak in i3c_master_register_fwnode()
Date: Sun, 08 Nov 2026 09:29:20 +0000	[thread overview]
Message-ID: <20261108092920.314161-1-vulab@iscas.ac.cn> (raw)

i3c_master_register_fwnode() takes a reference on the bus firmware node
with fwnode_handle_get() and stores it in master->dev. That reference is
normally dropped by i3c_masterdev_release(), which runs when the last
reference on the master device is put.

If i3c_master_rpm_get() fails, the function returns before
device_initialize(), so put_device() is never called, the release
callback never runs, and the reference is leaked.

Release the reference explicitly on that path. of_node_put() is not
enough here: it only acts on Open Firmware nodes, so the reference would
still leak on ACPI and software node systems.

The candidate was found with static analysis tools; DeepSeek and GPT-6.1
Sol were used to audit it and to help prepare this fix.

Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
Changes in v2:
- Sorry for the delay. v1 used of_node_put() on a reference taken with
  fwnode_handle_get(), which Frank pointed out.
- Use fwnode_handle_put(dev_fwnode(&master->dev)) instead.
- Rebased on current mainline (fa4ad798f6f6), where this code lives in
  i3c_master_register_fwnode().
- Dropped Cc: stable@vger.kernel.org. This only leaks when the runtime PM
  resume fails during registration, so I leave the backport decision to
  you.
- Build-tested with an x86_64 defconfig, including W=1: drivers/i3c/
  compiles without warnings and checkpatch.pl is clean. I could not make
  i3c_master_rpm_get() fail at runtime, so the failing path itself was not
  exercised on hardware.
- Link to v1: https://lore.kernel.org/all/20260916160358.2081087-1-vulab@iscas.ac.cn/

 drivers/i3c/master.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 01e05bad8661..c532693f8463 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -3897,8 +3897,10 @@ int i3c_master_register_fwnode(struct i3c_master_controller *master,
 	INIT_LIST_HEAD(&master->boardinfo.i3c);
 
 	ret = i3c_master_rpm_get(master);
-	if (ret)
+	if (ret) {
+		fwnode_handle_put(dev_fwnode(&master->dev));
 		return ret;
+	}
 
 	device_initialize(&master->dev);
 
-- 
2.34.1


                 reply	other threads:[~2026-11-08  9:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261108092920.314161-1-vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --cc=Frank.Li@kernel.org \
    --cc=Frank.li@oss.nxp.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-i3c@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®