mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: alexandre.belloni@bootlin.com
To: Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Frank Li <Frank.Li@nxp.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Boris Brezillon <bbrezillon@kernel.org>
Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] i3c: master: Release fwnode reference of I2C boardinfo at unregistration
Date: Wed,  2 Dec 2026 23:30:12 +0100	[thread overview]
Message-ID: <20261202223014.696672-1-alexandre.belloni@bootlin.com> (raw)

From: Alexandre Belloni <alexandre.belloni@bootlin.com>

i3c_master_add_i2c_boardinfo() takes a reference on the fwnode of each
I2C device described on the bus to keep it alive while the boardinfo
stores a pointer to it: the bus enumeration loop only holds the child
node while it iterates.  However, the reference is never released: the
boardinfo entries are devm-allocated and freed with the master device,
so one device node reference is leaked per I2C device when the master
controller goes away.

Drop the reference through a devm action, which runs when the devm
resources of the master device are released, that is at master
unregistration or when i3c_master_register_fwnode() fails.  The
reference cannot be dropped from the master device release callback
because device_release() frees the devm resources before calling it,
which would make the boardinfo list a use-after-free.

fwnode_handle_get()/fwnode_handle_put() are no-ops on ACPI nodes, so
the ACPI enumeration path is unaffected.

Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure")
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
 drivers/i3c/master.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 2bd1bd25c674..677d547bc12f 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -3140,6 +3140,13 @@ static inline int i3c_acpi_add_i2c_boardinfo(struct i2c_dev_boardinfo *boardinfo
 }
 #endif
 
+static void i3c_master_i2c_boardinfo_fwnode_put(void *data)
+{
+	struct i2c_dev_boardinfo *boardinfo = data;
+
+	fwnode_handle_put(boardinfo->base.fwnode);
+}
+
 static int
 i3c_master_add_i2c_boardinfo(struct i3c_master_controller *master,
 			     struct fwnode_handle *fwnode, u32 *reg)
@@ -3179,8 +3186,13 @@ i3c_master_add_i2c_boardinfo(struct i3c_master_controller *master,
 		return -EOPNOTSUPP;
 	}
 
-	list_add_tail(&boardinfo->node, &master->boardinfo.i2c);
 	fwnode_handle_get(fwnode);
+	ret = devm_add_action_or_reset(dev, i3c_master_i2c_boardinfo_fwnode_put,
+				       boardinfo);
+	if (ret)
+		return ret;
+
+	list_add_tail(&boardinfo->node, &master->boardinfo.i2c);
 
 	return 0;
 }
-- 
2.56.0


             reply	other threads:[~2026-12-02 22:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 22:30 alexandre.belloni [this message]
2026-12-02 22:30 ` [PATCH 2/2] i3c: master: Give I3C devices their own fwnode reference alexandre.belloni

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=20261202223014.696672-1-alexandre.belloni@bootlin.com \
    --to=alexandre.belloni@bootlin.com \
    --cc=Frank.Li@nxp.com \
    --cc=arnd@arndb.de \
    --cc=bbrezillon@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --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®