From: sashiko-bot@kernel.org
To: "Chen-Yu Tsai" <wenst@chromium.org>
Cc: conor+dt@kernel.org, dmitry.torokhov@gmail.com, robh@kernel.org,
linux-input@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 1/9] regulator: core: Add "enable and wait" functions
Date: Tue, 21 Jul 2026 08:08:28 +0000 [thread overview]
Message-ID: <20260721080829.4153C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260721075226.2347933-2-wenst@chromium.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The prototype for `regulator_enable_and_wait` in `consumer.h` incorrectly names the delay parameter `ms` instead of `wait_us`, inviting developers to pass millisecond values that will be incorrectly interpreted as microseconds.
- [High] Sleeping for the consumer delay while holding the recursive `ww_mutex` for the regulator and its entire parent supply chain severely degrades concurrency, blocking shared regulators and serializing async bulk enablement.
--
--- Patch [1]: [PATCH v3 1/9] regulator: core: Add "enable and wait" functions ---
commit 73793dc0bdc3050ff22074a860d438d5d9cc0b49
Author: Chen-Yu Tsai <wenst@chromium.org>
regulator: core: Add "enable and wait" functions
This commit introduces new "enable and wait" functions to the regulator core,
allowing consumers to ensure a minimum amount of time has passed since a
regulator was actually turned on. It adds a last_on timestamp to the
regulator device and updates single and bulk enable APIs to accept a wait time.
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index 1797929dfe566..d14ce86d8f7bb 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
[ ... ]
> @@ -3159,13 +3162,24 @@ static int _regulator_enable(struct regulator *regulator)
> } else if (ret < 0) {
> rdev_err(rdev, "is_enabled() failed: %pe\n", ERR_PTR(ret));
> goto err_consumer_disable;
> + } else {
> + /* regulator already enabled somehow, but timestamp might be invalid */
> + if (!rdev->last_on)
> + rdev->last_on = ktime_get_boottime();
> }
> - /* Fallthrough on positive return values - already enabled */
> }
>
> if (regulator->enable_count == 1)
> rdev->use_count++;
>
> + if (wait_us) {
> + ktime_t end = ktime_add_us(rdev->last_on, wait_us);
> + s64 remaining = ktime_us_delta(end, ktime_get_boottime());
> +
> + if (remaining > 0)
> + fsleep(remaining);
> + }
> +
[Severity: High]
Does sleeping here while holding the recursive ww_mutex for the regulator and
its parent supply chain cause concurrency issues?
Since regulator_enable_and_wait() acquires these locks via
regulator_lock_dependent() before calling _regulator_enable_and_wait(), this
sleep happens while the locks are held.
In cases like regulator_bulk_enable_and_wait() where async workers are created
to enable regulators in parallel, won't this serialize the wait times for any
consumers sharing a parent supply, defeating the purpose of the async design?
> return 0;
>
> err_consumer_disable:
[ ... ]
> diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
> index 56fe2693d9b22..a69157c9b5b51 100644
> --- a/include/linux/regulator/consumer.h
> +++ b/include/linux/regulator/consumer.h
[ ... ]
> @@ -192,7 +193,7 @@ int devm_regulator_bulk_register_supply_alias(struct device *dev,
> int num_id);
>
> /* regulator output control and status */
> -int __must_check regulator_enable(struct regulator *regulator);
> +int __must_check regulator_enable_and_wait(struct regulator *regulator, unsigned int ms);
[Severity: High]
Could the naming of this parameter cause consumers to inadvertently pass
millisecond values that get interpreted as microseconds?
The prototype here defines the parameter as ms, but the implementation and
the parameter passed to ktime_add_us() inside _regulator_enable_and_wait()
treat it strictly as microseconds.
If a driver developer passes 10 expecting a 10-millisecond delay based on this
header, the core will interpret it as 10 microseconds. Could this lead to
hardware initialization failures due to premature access to unstable power
supplies?
> int regulator_disable(struct regulator *regulator);
> int regulator_force_disable(struct regulator *regulator);
> int regulator_is_enabled(struct regulator *regulator);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260721075226.2347933-1-wenst@chromium.org?part=1
next prev parent reply other threads:[~2026-07-21 8:08 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 7:52 [PATCH v3 0/9] arm64: mediatek: Chromebook trackpad supply fixes Chen-Yu Tsai
2026-07-21 7:52 ` [PATCH v3 1/9] regulator: core: Add "enable and wait" functions Chen-Yu Tsai
2026-07-21 8:08 ` sashiko-bot [this message]
2026-07-21 8:22 ` Chen-Yu Tsai
2026-07-21 9:54 ` Andy Shevchenko
2026-07-21 7:52 ` [PATCH v3 2/9] Input: elan_i2c - sort include statements Chen-Yu Tsai
2026-07-21 10:20 ` Andy Shevchenko
2026-07-21 7:52 ` [PATCH v3 3/9] Input: elan_i2c - Wait for initialization after enabling regulator supply Chen-Yu Tsai
2026-07-21 8:07 ` sashiko-bot
2026-07-21 7:52 ` [PATCH v3 4/9] HID: i2c-hid-of: skip post-power-on delay if powered on sufficiently long Chen-Yu Tsai
2026-07-21 8:06 ` sashiko-bot
2026-07-21 7:52 ` [PATCH v3 5/9] i2c: of-prober: " Chen-Yu Tsai
2026-07-21 7:52 ` [PATCH v3 6/9] i2c: of-prober: Defer regulator_disable() on successful probe in simple helper Chen-Yu Tsai
2026-07-21 8:06 ` sashiko-bot
2026-07-21 10:24 ` Andy Shevchenko
2026-07-22 8:34 ` Chen-Yu Tsai
2026-07-21 7:52 ` [PATCH v3 7/9] platform/chrome: of_hw_prober: Add delay for hana trackpads Chen-Yu Tsai
2026-07-21 10:27 ` Andy Shevchenko
2026-07-22 3:33 ` Chen-Yu Tsai
2026-07-21 7:52 ` [PATCH v3 8/9] arm64: dts: mediatek: mt8173-elm-hana: Unmark trackpad supply as always-on Chen-Yu Tsai
2026-07-21 7:52 ` [PATCH v3 9/9] arm64: dts: mediatek: mt8192-asurada-spherion: Add Synaptics trackpad's supply Chen-Yu Tsai
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=20260721080829.4153C1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=wenst@chromium.org \
/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