Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chen-Yu Tsai" <wenst@chromium.org>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v2 2/7] HID: i2c-hid-of: skip post-power-on delay if already powered on
Date: Fri, 03 Jul 2026 12:07:17 +0000	[thread overview]
Message-ID: <20260703120718.DA5101F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260703115601.1323491-3-wenst@chromium.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Bitwise AND assignment (`&=`) between a `bool` and the `int` return value of `regulator_is_enabled()` causes pseudo-random evaluation based on the least significant bit (LSB) of the integer, potentially skipping mandatory delays.
- [High] Skipping the post-power-on delay based solely on the current state of `regulator_is_enabled()` introduces a race condition for devices sharing a power rail.
--

commit 14324865d2e3b5ccaf90d6ff025e907befb17313
Author: Chen-Yu Tsai <wenst@chromium.org>

HID: i2c-hid-of: skip post-power-on delay if already powered on

This patch checks if the regulator supplies for an i2c-hid device are
already enabled during probe. If all supplies are already on, it skips
the post-power-on delay to save boot time.

> diff --git a/drivers/hid/i2c-hid/i2c-hid-of.c b/drivers/hid/i2c-hid/i2c-hid-of.c
> --- a/drivers/hid/i2c-hid/i2c-hid-of.c
> +++ b/drivers/hid/i2c-hid/i2c-hid-of.c
> @@ -46,8 +47,12 @@ static int i2c_hid_of_power_up(struct i2chid_ops *ops)
>  {
>  	struct i2c_hid_of *ihid_of = container_of(ops, struct i2c_hid_of, ops);
>  	struct device *dev = &ihid_of->client->dev;
> +	bool supply_was_enabled = true;
>  	int ret;
>  
> +	for (unsigned int i = 0; i < ARRAY_SIZE(ihid_of->supplies); i++)
> +		supply_was_enabled &= regulator_is_enabled(ihid_of->supplies[i].consumer);

[Severity: High]
Could this bitwise operation cause a regression by inadvertently evaluating
the least significant bit of the return value?

The function regulator_is_enabled() returns an int (positive state, 0, or 
a negative error). In C, performing a bitwise AND (&=) between a bool 
(promoted to integer 1) and an int isolates the least significant bit.

For example, if regulator_is_enabled() returns a negative error code like 
-ENODEV (-19), the least significant bit is 1, causing supply_was_enabled 
to evaluate to true despite the error. If it returns an even positive 
state like 2, the least significant bit is 0, making it false.

[ ... ]

>  	if (ret) {
>  		dev_warn(dev, "Failed to enable supplies: %d\n", ret);
>  		return ret;
>  	}
>  
> -	if (ihid_of->post_power_delay_ms)
> +	dev_dbg(dev, "supply was %s.\n", str_on_off(supply_was_enabled));
> +	if (!supply_was_enabled && ihid_of->post_power_delay_ms)
>  		msleep(ihid_of->post_power_delay_ms);

[Severity: High]
Is it safe to skip this delay based solely on whether the regulator is
currently enabled?

If two devices (e.g. a touchscreen and a trackpad) share the same 
non-always-on regulator and probe asynchronously:

Device 1 starts probing, calls regulator_bulk_enable(), and begins
waiting its post-power delay.

Device 2 concurrently probes in i2c_hid_of_power_up(), sees 
regulator_is_enabled() is true, and skips its post_power_delay_ms here.

Device 2 would then immediately issue I2C transactions to a newly powered
device that might not have finished initializing, potentially resulting
in NACKs and a probe regression. 

Does the regulator framework provide a way to ensure the rail has been on
for the required duration, rather than just currently enabled?

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

  reply	other threads:[~2026-07-03 12:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03 11:55 [PATCH v2 0/7] arm64: mediatek: Chromebook trackpad supply fixes Chen-Yu Tsai
2026-07-03 11:55 ` [PATCH v2 1/7] Input: elan_i2c - Wait for initialization after enabling regulator supply Chen-Yu Tsai
2026-07-03 12:06   ` sashiko-bot
2026-07-04 23:44   ` Dmitry Torokhov
2026-07-03 11:55 ` [PATCH v2 2/7] HID: i2c-hid-of: skip post-power-on delay if already powered on Chen-Yu Tsai
2026-07-03 12:07   ` sashiko-bot [this message]
2026-07-03 11:55 ` [PATCH v2 3/7] i2c: of-prober: " Chen-Yu Tsai
2026-07-03 12:05   ` sashiko-bot
2026-07-03 11:55 ` [PATCH v2 4/7] i2c: of-prober: Defer regulator_disable() on successful probe in simple helper Chen-Yu Tsai
2026-07-03 12:08   ` sashiko-bot
2026-07-03 11:55 ` [PATCH v2 5/7] platform/chrome: of_hw_prober: Add delay for hana trackpads Chen-Yu Tsai
2026-07-03 12:10   ` sashiko-bot
2026-07-03 11:55 ` [PATCH v2 6/7] arm64: dts: mediatek: mt8173-elm-hana: Unmark trackpad supply as always-on Chen-Yu Tsai
2026-07-03 11:56 ` [PATCH v2 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=20260703120718.DA5101F00A3A@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