From: sashiko-bot@kernel.org
To: "Lakshay Piplani" <lakshay.piplani@nxp.com>
Cc: conor+dt@kernel.org, robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v10 2/9] i3c: master: Expose the APIs to support I3C hub
Date: Mon, 25 May 2026 07:39:39 +0000 [thread overview]
Message-ID: <20260525073940.9EC7E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260525064209.2263045-3-lakshay.piplani@nxp.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [Medium] `i3c_master_reattach_i3c_dev_locked()` does not validate slot availability despite documentation claiming it returns `-EBUSY`.
Pre-existing issues:
- [High] `i3c_master_reattach_i3c_dev_locked` corrupts the bus address state if the reattach operation fails.
- [High] Missing synchronization and improper error handling in `i3c_dev_disable_ibi_locked` and `i3c_dev_free_ibi_locked` lead to Use-After-Free.
- [High] Missing memory barrier between `reinit_completion()` and `atomic_read()` can lead to a deadlock in `i3c_dev_disable_ibi_locked`.
--
commit 9189e89cd793462892bddcec9432ec1ed64052bf
Author: Aman Kumar Pandey <aman.kumarpandey@nxp.com>
i3c: master: Expose the APIs to support I3C hub
This commit exposes several internal static I3C functions as public APIs
to support a new I3C hub driver. It adds EXPORT_SYMBOL_GPL and kernel-doc
comments for functions handling IBI operations and device reattachment.
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index c45b450af319d..ec3547f75469e 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
[ ... ]
> -static int i3c_master_reattach_i3c_dev_locked(struct i3c_dev_desc *dev,
> - u8 old_dyn_addr)
> +/**
> + * i3c_master_reattach_i3c_dev_locked() - reattach an I3C device with a new address
> + * @dev: I3C device descriptor to reattach
> + * @old_dyn_addr: previous dynamic address of the device
> + *
> + * This function reattaches an existing I3C device to the bus when its dynamic
> + * address has changed. It updates the bus address slot status accordingly:
> + * - Marks the new dynamic address as occupied by an I3C device.
> + * - Frees the old dynamic address slot if applicable.
> + *
> + * This function must be called with the bus lock held in write mode.
> + *
> + * Return: 0 on success, or a negative error code if reattachment fails
> + * (e.g. -EBUSY if the new address slot is not free).
> + */
> +int i3c_master_reattach_i3c_dev_locked(struct i3c_dev_desc *dev,
> + u8 old_dyn_addr)
> {
> struct i3c_master_controller *master = i3c_dev_get_master(dev);
> int ret;
[Severity: Medium]
The kernel-doc mentions returning -EBUSY if the new address slot is not free.
Does the implementation actually check this?
It appears i3c_bus_set_addr_slot_status() is called unconditionally,
overwriting the slot status without validating if it was previously occupied.
Since external driver authors may rely on this documented contract, could this
lead to masking conflicts if they omit their own slot availability checks?
[ ... ]
> @@ -1677,6 +1692,7 @@ static int i3c_master_reattach_i3c_dev_locked(struct i3c_dev_desc *dev,
>
> return 0;
> }
> +EXPORT_SYMBOL_GPL(i3c_master_reattach_i3c_dev_locked);
[Severity: High]
This is a pre-existing issue, but exporting this function exposes an error
handling path that can corrupt the bus address state. If the hardware reattach
callback fails:
i3c_master_reattach_i3c_dev_locked() {
...
if (master->ops->reattach_i3c_dev) {
ret = master->ops->reattach_i3c_dev(dev, old_dyn_addr);
if (ret) {
i3c_master_put_i3c_addrs(dev);
return ret;
}
...
}
Calling i3c_master_put_i3c_addrs() marks the device's dynamic and static
address slots as I3C_ADDR_SLOT_FREE. However, the device is not logically
detached, remains in the bus list, and retains its dyn_addr.
Since the bus allocator now views the slot as free, can subsequent dynamic
address assignments or hot-joins assign this address to another device, leading
to address collisions on the bus?
[ ... ]
> +/**
> + * i3c_dev_disable_ibi_locked() - Disable IBIs coming from a specific device
> + * @dev: device on which IBIs should be disabled
> + *
> + * This function disable IBIs coming from a specific device and wait for
> + * all pending IBIs to be processed.
> + *
> + * Context: Must be called with mutex_lock(&dev->desc->ibi_lock) held.
> + * Return: 0 in case of success, a negative error core otherwise.
> + */
> int i3c_dev_disable_ibi_locked(struct i3c_dev_desc *dev)
> {
> struct i3c_master_controller *master;
> @@ -3216,7 +3242,22 @@ int i3c_dev_disable_ibi_locked(struct i3c_dev_desc *dev)
>
> return 0;
> }
> +EXPORT_SYMBOL_GPL(i3c_dev_disable_ibi_locked);
[Severity: High]
This isn't a bug introduced by this patch, but does the lack of a memory
barrier here risk a deadlock?
i3c_dev_disable_ibi_locked() {
...
reinit_completion(&dev->ibi->all_ibis_handled);
if (atomic_read(&dev->ibi->pending_ibis))
wait_for_completion(&dev->ibi->all_ibis_handled);
...
}
Because there is no full memory barrier between writing the completion state in
reinit_completion() and reading the atomic counter, could store-load reordering
occur?
If a concurrent IBI workqueue handler decrements pending_ibis to 0 and calls
complete() before the completion reset is globally visible, the
wait_for_completion() call would block indefinitely.
[Severity: High]
Also a pre-existing issue, but does this lack synchronization with in-flight
interrupts?
If an IRQ handler is executing on another CPU right before
atomic_inc(&dev->ibi->pending_ibis) is called, i3c_dev_disable_ibi_locked()
could read pending_ibis as 0 and return early.
If i3c_dev_free_ibi_locked() is subsequently called to free dev->ibi, would the
delayed IRQ handler then access freed memory?
[ ... ]
> +/**
> + * i3c_dev_free_ibi_locked() - Free all resources needed for IBI handling
> + * @dev: device on which you want to release IBI resources
> + *
> + * This function is responsible for de-allocating resources previously
> + * allocated by i3c_device_request_ibi(). It should be called after disabling
> + * IBIs with i3c_device_disable_ibi().
> + *
> + * Context: Must be called with mutex_lock(&dev->desc->ibi_lock) held.
> + */
> void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev)
> {
> struct i3c_master_controller *master = i3c_dev_get_master(dev);
> @@ -3301,6 +3366,7 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev)
> kfree(dev->ibi);
> dev->ibi = NULL;
> }
> +EXPORT_SYMBOL_GPL(i3c_dev_free_ibi_locked);
[Severity: High]
This isn't a bug introduced by this patch, but exporting these APIs highlights
a potential use-after-free vector.
i3c_dev_free_ibi_locked() {
...
if (dev->ibi->enabled) {
...
ret = i3c_dev_disable_ibi_locked(dev);
...
if (ret)
dev_err(&master->dev, "Failed to disable IBI before freeing\n");
}
...
kfree(dev->ibi);
}
If i3c_dev_disable_ibi_locked() fails to disable hardware IBIs, this function
logs an error but proceeds to call kfree(dev->ibi) and destroy the workqueue.
Since the hardware might still be enabled and firing interrupts, won't the
master's IRQ handler attempt to access the freed dev->ibi when it receives the
next interrupt?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260525064209.2263045-1-lakshay.piplani@nxp.com?part=2
next prev parent reply other threads:[~2026-05-25 7:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 6:42 [PATCH v10 0/9] Add support for NXP P3H2x4x I3C hub driver Lakshay Piplani
2026-05-25 6:42 ` [PATCH v10 1/9] i3c: master: rename i3c_master_reattach_i3c_dev() to *_locked Lakshay Piplani
2026-05-25 7:05 ` sashiko-bot
2026-05-25 6:42 ` [PATCH v10 2/9] i3c: master: Expose the APIs to support I3C hub Lakshay Piplani
2026-05-25 7:39 ` sashiko-bot [this message]
2026-05-25 6:42 ` [PATCH v10 3/9] i3c: master: Add APIs for I3C hub support Lakshay Piplani
2026-05-25 8:00 ` sashiko-bot
2026-05-25 6:42 ` [PATCH v10 4/9] dt-bindings: i3c: Add NXP P3H2x4x i3c-hub support Lakshay Piplani
2026-05-25 8:08 ` sashiko-bot
2026-05-25 6:42 ` [PATCH v10 5/9] mfd: p3h2x4x: Add driver for NXP P3H2x4x i3c hub and on-die regulator Lakshay Piplani
2026-05-25 8:43 ` sashiko-bot
2026-05-25 6:42 ` [PATCH v10 6/9] regulator: p3h2x4x: Add driver for on-die regulators in NXP P3H2x4x i3c hub Lakshay Piplani
2026-05-25 9:06 ` sashiko-bot
2026-05-25 6:42 ` [PATCH v10 7/9] i3c: hub: Add support for the I3C interface in the I3C hub Lakshay Piplani
2026-05-25 9:31 ` sashiko-bot
2026-05-25 6:42 ` [PATCH v10 8/9] i3c: hub: p3h2x4x: Add support for NXP P3H2x4x I3C hub functionality Lakshay Piplani
2026-05-25 9:56 ` sashiko-bot
2026-05-25 6:42 ` [PATCH v10 9/9] i3c: hub: p3h2x4x: Add SMBus slave mode support Lakshay Piplani
2026-05-25 10:29 ` sashiko-bot
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=20260525073940.9EC7E1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=lakshay.piplani@nxp.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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