Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chen-Yu Tsai" <wenst@chromium.org>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com,
	conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v5 1/7] regulator: core: Add "enable and wait" functions
Date: Tue, 25 Aug 2026 04:47:29 +0000	[thread overview]
Message-ID: <20260825044730.29A151F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260825041628.988369-2-wenst@chromium.org>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] regulator_bulk_enable_and_wait incorrectly assigns wait_us only to the first consumer, leaving the rest uninitialized.
- [High] regulator_register accesses hardware state via _regulator_is_enabled and updates rdev->last_on without holding rdev->mutex after the device is exposed.
- [Medium] _regulator_is_enabled() and _regulator_is_enabled_recursive() can return negative error codes, but they are used in boolean contexts where negative values evaluate to true.
--

--- Patch [1]: [PATCH v5 1/7] regulator: core: Add "enable and wait" functions ---
commit 5fd97a59a5c2607c473a3bc31a58415b701f2335
Author: Chen-Yu Tsai <wenst@chromium.org>

regulator: core: Add "enable and wait" functions

This patch introduces "enable and wait" functions to the single and bulk
regulator consumer APIs. It tracks a "last turned on" timestamp to shorten
or skip delays if the regulator is already on. The timestamp is also best
effort populated for regulators left on by hardware or firmware.

> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index 1797929dfe566..f70be7e38e599 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -2352,6 +2390,14 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
>  		}
>  		rdev->constraints_pending = false;
>  	}
> +
> +	/*
> +	 * regulator was left on but not enabled with .always_on or .boot_on
> +	 * constraints, and thus .last_on timestamp is still invalid.
> +	 */
> +	if (!rdev->last_on && _regulator_is_enabled_recursive(rdev))
> +		rdev->last_on = ktime_get_boottime();
> +

[Severity: Medium]
_regulator_is_enabled_recursive() can return negative error codes. Since it
is evaluated in a boolean context here, won't negative values evaluate to
true, causing last_on to be incorrectly updated if there is a hardware read
failure?

>  	regulator_unlock_dependent(rdev, &ww_ctx);
>  
>  	if (!do_final_setup)

[ ... ]

> @@ -5372,30 +5444,38 @@ static void regulator_bulk_enable_async(void *data, async_cookie_t cookie)
>  int regulator_bulk_enable_and_wait(int num_consumers,
>  				   struct regulator_bulk_data *consumers,
>  				   unsigned int wait_us)
>  {
>  	ASYNC_DOMAIN_EXCLUSIVE(async_domain);
>  	int i;
>  	int ret = 0;
>  
>  	for (i = 0; i < num_consumers; i++) {
> +		ACCESS_PRIVATE(consumers, wait_us) = wait_us;
>  		async_schedule_domain(regulator_bulk_enable_async,
>  				      &consumers[i], &async_domain);
>  	}

[Severity: High]
Does this loop assign wait_us only to the first element of the array instead
of using the loop counter i? For subsequent consumers where i > 0, the
wait_us field remains uninitialized.

When regulator_bulk_enable_async() executes for these subsequent consumers,
could it read uninitialized memory and pass it to fsleep(), potentially
hanging the kernel thread indefinitely or skipping required delays? Should
this be ACCESS_PRIVATE(&consumers[i], wait_us)?

>  	async_synchronize_full_domain(&async_domain);

[ ... ]

> @@ -6225,6 +6305,13 @@ regulator_register(struct device *dev,
>  			goto del_cdev_and_bdev;
>  	}
>  
> +	/*
> +	 * If no supply was given, then the last_on timestamp could not have
> +	 * been updated in regulator_resolve_supply(). Check it here.
> +	 */
> +	if (!rdev->supply_name && !rdev->last_on && _regulator_is_enabled(rdev))
> +		rdev->last_on = ktime_get_boottime();
> +

[Severity: Medium]
Similar to the case in regulator_resolve_supply(), _regulator_is_enabled()
can return negative error codes. Could this cause last_on to be updated
incorrectly if the hardware read fails during probe?

[Severity: High]
Since device_add(&rdev->dev) is called earlier in regulator_register(),
exposing the device globally and allowing concurrent regulator_enable()
calls, is it safe to call _regulator_is_enabled(rdev) and update
rdev->last_on here without holding rdev->mutex? This could lead to a data
race on last_on and unsynchronized hardware callbacks.

>  	rdev_init_debugfs(rdev);
>  
>  	/* try to resolve regulators coupling since a new one was registered */

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260825041628.988369-1-wenst@chromium.org?part=1

  reply	other threads:[~2026-08-25  4:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  4:16 [PATCH v5 0/7] arm64: mediatek: Chromebook trackpad supply fixes Chen-Yu Tsai
2026-08-25  4:16 ` [PATCH v5 1/7] regulator: core: Add "enable and wait" functions Chen-Yu Tsai
2026-08-25  4:47   ` sashiko-bot [this message]
2026-08-25  7:44   ` Chen-Yu Tsai
2026-08-25  4:16 ` [PATCH v5 2/7] Input: elan_i2c - Wait for initialization after enabling regulator supply Chen-Yu Tsai
2026-08-25  4:16 ` [PATCH v5 3/7] HID: i2c-hid-of: skip post-power-on delay if powered on sufficiently long Chen-Yu Tsai
2026-08-25  4:48   ` sashiko-bot
2026-08-25  4:16 ` [PATCH v5 4/7] i2c: of-prober: " Chen-Yu Tsai
2026-08-25  4:16 ` [PATCH v5 5/7] i2c: of-prober: Defer regulator_disable() on successful probe in simple helper Chen-Yu Tsai
2026-08-25  4:48   ` sashiko-bot
2026-08-25  4:16 ` [PATCH v5 6/7] arm64: dts: mediatek: mt8173-elm-hana: Unmark trackpad supply as always-on Chen-Yu Tsai
2026-08-25  4:50   ` sashiko-bot
2026-08-25  4:16 ` [PATCH v5 7/7] 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=20260825044730.29A151F000E9@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