Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lakshay Piplani" <lakshay.piplani@nxp.com>
Cc: linux-i3c@lists.infradead.org, Frank.Li@kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	conor+dt@kernel.org, robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v16 2/8] i3c: master: Add controller-only device operation helpers
Date: Wed, 26 Aug 2026 10:50:45 +0000	[thread overview]
Message-ID: <20260826105045.B3DA21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260826103819.1614843-3-lakshay.piplani@nxp.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Medium] Unnecessary heavy workqueue allocation and teardown when a controller does not support IBIs.

Pre-existing issues:
- [Critical] Potential use-after-free of generic IBI pool slots and `dev->ibi` when disabling an active IBI fails during teardown.
--

commit f38c11b5d94a35f5b99f6a1f23bbb449f122ded4
Author: Lakshay Piplani <lakshay.piplani@nxp.com>

i3c: master: Add controller-only device operation helpers

The generic I3C device attach and IBI paths perform both core-level
bookkeeping and controller-specific operations. Add controller-only helpers
that invoke the controller callbacks without updating the bus device list,
address-slot state, or generic IBI lifecycle. Also release the generic IBI
workqueue and state when the controller request callback fails.

> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 03fb41f0786c5..88379b6809a64 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
[ ... ]
> @@ -3600,13 +3752,9 @@ EXPORT_SYMBOL_GPL(i3c_dev_enable_ibi_locked);
>  int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev,
>  			       const struct i3c_ibi_setup *req)
>  {
> -	struct i3c_master_controller *master = i3c_dev_get_master(dev);
>  	struct i3c_device_ibi_info *ibi;
>  	int ret;
>  
> -	if (!master->ops->request_ibi)
> -		return -EOPNOTSUPP;
> -
>  	if (dev->ibi)
>  		return -EBUSY;
>  
[ ... ]
> @@ -3627,8 +3775,15 @@ int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev,
>  	ibi->num_slots = req->num_slots;
>  
>  	dev->ibi = ibi;
> -	ret = master->ops->request_ibi(dev, req);
> +	ret = i3c_dev_request_ibi_controller_locked(dev, req);
>  	if (ret) {
> +		/*
> +		 * The controller request callback failed, so tear down the
> +		 * workqueue allocated above before freeing the IBI object.
> +		 * This is the owner of the workqueue, so it must destroy it
> +		 * here to avoid leaking it on the error path.
> +		 */
> +		destroy_workqueue(ibi->wq);
>  		kfree(ibi);
>  		dev->ibi = NULL;
>  	}

[Severity: Medium]
Since the check for master->ops->request_ibi was moved into
i3c_dev_request_ibi_controller_locked(), this code now unconditionally
creates a new ordered workqueue during device probe even when the
underlying controller doesn't support IBIs.

Does this unnecessary allocation and destruction of a workqueue thread
(which involves sysfs registration and RCU synchronization) add a noticeable
performance delay for devices on controllers without IBI support?

[ ... ]
> @@ -3667,7 +3843,7 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev)
>  			dev_err(&master->dev, "Failed to disable IBI before freeing\n");
>  	}
>  
> -	master->ops->free_ibi(dev);
> +	i3c_dev_free_ibi_controller_locked(dev);
>  
>  	if (dev->ibi->wq) {
>  		destroy_workqueue(dev->ibi->wq);

[Severity: Critical]
This is a pre-existing issue, but can calling
i3c_dev_free_ibi_controller_locked() before destroy_workqueue(dev->ibi->wq)
cause a use-after-free?

If i3c_dev_disable_ibi_locked() fails (e.g. due to a bus timeout), the
teardown continues and invokes the controller's free_ibi callback, which
immediately frees the generic IBI pool memory.

If there are still pending IBI work items because destroy_workqueue() hasn't
been called to drain them yet, will the workqueue process them and
dereference the freed generic IBI slots?

Additionally, could an active hardware interrupt still fire and race with
the controller's free_ibi callback, leading to memory corruption inside the
interrupt handler?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260826103819.1614843-1-lakshay.piplani@nxp.com?part=2

  reply	other threads:[~2026-08-26 10:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26 10:38 [PATCH v16 0/8] Add support for NXP P3H2x4x I3C hub driver Lakshay Piplani
2026-08-26 10:38 ` [PATCH v16 1/8] i3c: master: Add APIs for I3C hub support Lakshay Piplani
2026-08-26 10:52   ` sashiko-bot
2026-08-26 16:36   ` Frank Li
2026-08-26 10:38 ` [PATCH v16 2/8] i3c: master: Add controller-only device operation helpers Lakshay Piplani
2026-08-26 10:50   ` sashiko-bot [this message]
2026-08-26 16:42   ` Frank Li
2026-08-27  7:02     ` Lakshay Piplani
2026-08-26 10:38 ` [PATCH v16 3/8] dt-bindings: i3c: Add NXP P3H2x4x i3c-hub support Lakshay Piplani
2026-08-26 10:38 ` [PATCH v16 4/8] mfd: p3h2x4x: Add driver for NXP P3H2x4x i3c hub and on-die regulator Lakshay Piplani
2026-08-26 10:56   ` sashiko-bot
2026-08-27 10:03   ` Krzysztof Kozlowski
2026-08-26 10:38 ` [PATCH v16 5/8] regulator: p3h2x4x: Add driver for on-die regulators in NXP P3H2x4x i3c hub Lakshay Piplani
2026-08-26 10:48   ` sashiko-bot
2026-08-26 10:38 ` [PATCH v16 6/8] i3c: hub: Add support for the I3C interface in the I3C hub Lakshay Piplani
2026-08-26 11:04   ` sashiko-bot
2026-08-26 17:02     ` Frank Li
2026-08-27  7:07       ` Lakshay Piplani
2026-08-27 10:09   ` Krzysztof Kozlowski
2026-08-26 10:38 ` [PATCH v16 7/8] i3c: hub: p3h2x4x: Add support for NXP P3H2x4x I3C hub functionality Lakshay Piplani
2026-08-27 10:16   ` Krzysztof Kozlowski
2026-08-26 10:38 ` [PATCH v16 8/8] i3c: hub: p3h2x4x: Add SMBus slave mode support Lakshay Piplani

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=20260826105045.B3DA21F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=lakshay.piplani@nxp.com \
    --cc=linux-i3c@lists.infradead.org \
    --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