From: Frank Li <Frank.li@oss.nxp.com>
To: Zhang Yuwei <zhangyuwei20@huawei.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
Frank Li <Frank.Li@nxp.com>,
linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, chenjun102@huawei.com
Subject: Re: [PATCH] i3c: master: Skip IDR cleanup if bus ID allocation fails
Date: Tue, 17 Nov 2026 12:44:16 -0500 [thread overview]
Message-ID: <avyScPjAFgr_DjHE@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20261116035317.132490-1-zhangyuwei20@huawei.com>
On Mon, Nov 16, 2026 at 11:53:17AM +0800, Zhang Yuwei wrote:
> 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>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.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
>
prev parent reply other threads:[~2026-11-17 17:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 3:53 Zhang Yuwei
2026-11-17 17:44 ` Frank Li [this message]
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=avyScPjAFgr_DjHE@lizhi-Precision-Tower-5810 \
--to=frank.li@oss.nxp.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 \
--cc=zhangyuwei20@huawei.com \
/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®