All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Adrian Hunter" <adrian.hunter@intel.com>
Cc: Frank.Li@kernel.org, linux-i3c@lists.infradead.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH RFC 3/7] i3c: master: Add helper to query bus wakeup requirements
Date: Wed, 01 Jul 2026 20:23:01 +0000	[thread overview]
Message-ID: <20260701202302.2D1E91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260701200552.220042-4-adrian.hunter@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] `i3c_master_any_wakeup_enabled()` dereferences a dangling `desc->dev` pointer if a device previously failed to register.
- [High] Concurrent execution of `i3c_master_any_wakeup_enabled` and `i3c_master_reg_work_fn` creates a data race on `desc->dev` due to a shared read lock.
--

commit ed5405b56d89572a46136e7c93b53f6058fa4335
Author: Adrian Hunter <adrian.hunter@intel.com>

i3c: master: Add helper to query bus wakeup requirements

Add i3c_master_any_wakeup_enabled(), which iterates over the devices on
an I3C bus and reports whether any of them are enabled for system wakeup.
Controller drivers can use this helper to determine whether wakeup support
must remain available while the system is suspended.

> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index a36f9b617cbf7..979457e635bd9 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -1957,6 +1957,33 @@ static void i3c_master_reg_work_fn(struct work_struct *work)
[ ... ]
> +bool i3c_master_any_wakeup_enabled(struct i3c_master_controller *master)
> +{
> +	struct i3c_dev_desc *desc;
> +	bool wakeup = false;
> +
> +	i3c_bus_normaluse_lock(&master->bus);

[Severity: High]
Can this race with i3c_master_reg_work_fn() and access uninitialized memory or
a freed pointer?

i3c_master_reg_work_fn() executes in a workqueue and calls
i3c_master_register_new_i3c_devs() while holding i3c_bus_normaluse_lock(),
which only acquires a read lock (down_read(&bus->lock)).

Inside i3c_master_register_new_i3c_devs(), desc->dev is allocated and mutated.

Since i3c_master_any_wakeup_enabled() also acquires the same read lock,
could it run concurrently (e.g. during runtime PM suspend) and read desc->dev
while it is being allocated or freed on the failure path?

> +	i3c_bus_for_each_i3cdev(&master->bus, desc) {
> +		if (desc->dev && device_may_wakeup(&desc->dev->dev)) {

[Severity: High]
Does this code risk a use-after-free if a device failed to register?

Looking at i3c_master_register_new_i3c_devs(), if device_register() fails,
the error path calls put_device(&desc->dev->dev) which frees the device
structure, but it leaves desc->dev as a dangling pointer.

If i3c_master_any_wakeup_enabled() is called later, could desc->dev evaluate
to true and cause device_may_wakeup() to dereference the freed memory?

> +			wakeup = true;
> +			break;
> +		}
> +	}
> +	i3c_bus_normaluse_unlock(&master->bus);
> +
> +	return wakeup;
> +}
> +EXPORT_SYMBOL_GPL(i3c_master_any_wakeup_enabled);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260701200552.220042-1-adrian.hunter@intel.com?part=3

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

  reply	other threads:[~2026-07-01 20:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 20:05 [PATCH RFC 0/7] i3c: Support IBI-based system wakeup Adrian Hunter
2026-07-01 20:05 ` Adrian Hunter
2026-07-01 20:05 ` [PATCH RFC 1/7] i3c: master: Support IBI-based wakeup capability Adrian Hunter
2026-07-01 20:05   ` Adrian Hunter
2026-07-01 20:26   ` sashiko-bot
2026-07-01 20:05 ` [PATCH RFC 2/7] i3c: master: Report wakeup events for IBIs Adrian Hunter
2026-07-01 20:05   ` Adrian Hunter
2026-07-01 20:27   ` sashiko-bot
2026-07-01 20:05 ` [PATCH RFC 3/7] i3c: master: Add helper to query bus wakeup requirements Adrian Hunter
2026-07-01 20:05   ` Adrian Hunter
2026-07-01 20:23   ` sashiko-bot [this message]
2026-07-01 20:05 ` [PATCH RFC 4/7] i3c: master: Reject IBI requests from non-IBI-capable devices Adrian Hunter
2026-07-01 20:05   ` Adrian Hunter
2026-07-01 20:05 ` [PATCH RFC 5/7] i3c: mipi-i3c-hci-pci: Propagate I3C wakeup requirements to PCI Adrian Hunter
2026-07-01 20:05   ` Adrian Hunter
2026-07-01 20:26   ` sashiko-bot
2026-07-01 20:05 ` [PATCH RFC 6/7] i3c: mipi-i3c-hci: Factor out i3c_hci_sysdev() Adrian Hunter
2026-07-01 20:05   ` Adrian Hunter
2026-07-01 20:05 ` [PATCH RFC 7/7] i3c: mipi-i3c-hci: Advertise IBI wakeup capability Adrian Hunter
2026-07-01 20:05   ` Adrian Hunter
2026-07-01 20:15 ` [PATCH RFC 0/7] i3c: Support IBI-based system wakeup Adrian Hunter
2026-07-01 20:15   ` Adrian Hunter

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=20260701202302.2D1E91F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-i3c@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.