mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] i3c: master: Skip IDR cleanup if bus ID allocation fails
@ 2026-11-16  3:53 Zhang Yuwei
  2026-11-17 17:44 ` Frank Li
  0 siblings, 1 reply; 2+ messages in thread
From: Zhang Yuwei @ 2026-11-16  3:53 UTC (permalink / raw)
  To: Alexandre Belloni, Frank Li; +Cc: linux-i3c, linux-kernel, stable, chenjun102

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


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

end of thread, other threads:[~2026-11-17 17:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16  3:53 [PATCH] i3c: master: Skip IDR cleanup if bus ID allocation fails Zhang Yuwei
2026-11-17 17:44 ` Frank Li

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®