mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhang Yuwei <zhangyuwei20@huawei.com>
To: Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Frank Li <Frank.Li@nxp.com>
Cc: <linux-i3c@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
	<stable@vger.kernel.org>, <chenjun102@huawei.com>
Subject: [PATCH] i3c: master: Skip IDR cleanup if bus ID allocation fails
Date: Mon, 16 Nov 2026 11:53:17 +0800	[thread overview]
Message-ID: <20261116035317.132490-1-zhangyuwei20@huawei.com> (raw)

Since commit 9d4f219807d5 ("i3c: fix refcount inconsistency in
i3c_master_register"), an i3c_bus_init() failure is handled by dropping
the initialized device reference. This invokes i3c_masterdev_release(),
which unconditionally calls i3c_bus_cleanup().

However, i3c_bus_init() only assigns the bus ID after idr_alloc()
succeeds. If the allocation fails, a zero-initialized controller retains
a bus ID of zero, and i3c_bus_cleanup() removes ID zero from the IDR.
If another bus owns that ID, its mapping is incorrectly removed, allowing
the ID to be reused while that bus is still registered.

Initialize the bus ID to -1 before attempting allocation and skip IDR
cleanup when the ID is negative. Keep the put_device() error path so that
the device reference and firmware node reference are released normally.

Fixes: 9d4f219807d5 ("i3c: fix refcount inconsistency in i3c_master_register")
Cc: stable@vger.kernel.org
Signed-off-by: Zhang Yuwei <zhangyuwei20@huawei.com>
---
 drivers/i3c/master.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 9928c5dffb5b..39363c097682 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -523,6 +523,9 @@ static void i3c_bus_init_addrslots(struct i3c_bus *bus)
 
 static void i3c_bus_cleanup(struct i3c_bus *i3cbus)
 {
+	if (i3cbus->id < 0)
+		return;
+
 	mutex_lock(&i3c_core_lock);
 	idr_remove(&i3c_bus_idr, i3cbus->id);
 	mutex_unlock(&i3c_core_lock);
@@ -532,6 +535,7 @@ static int i3c_bus_init(struct i3c_bus *i3cbus, struct fwnode_handle *fwnode)
 {
 	int ret, start, end, id = -1;
 
+	i3cbus->id = -1;
 	init_rwsem(&i3cbus->lock);
 	INIT_LIST_HEAD(&i3cbus->devs.i2c);
 	INIT_LIST_HEAD(&i3cbus->devs.i3c);
-- 
2.22.0


             reply	other threads:[~2026-11-16  3:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  3:53 Zhang Yuwei [this message]
2026-11-17 17:44 ` Frank Li

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=20261116035317.132490-1-zhangyuwei20@huawei.com \
    --to=zhangyuwei20@huawei.com \
    --cc=Frank.Li@nxp.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=chenjun102@huawei.com \
    --cc=linux-i3c@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@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®