All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Javier Carrasco" <javier.carrasco.cruz@gmail.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v2 3/4] hwmon: chipcap2: enable IRQ processing when regulator is already enabled
Date: Sun, 23 Aug 2026 18:11:43 +0000	[thread overview]
Message-ID: <20260823181143.F32B11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260823-chipcap2_locks-v2-3-6a26c8e9e2fc@gmail.com>

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

Pre-existing issues:
- [High] Bypassing `regulator_enable()` but calling `regulator_disable()` leads to unbalanced operations and kernel WARNs.
- [High] Incorrect endianness conversion for I2C SMBus word write corrupts data on Big Endian architectures.
- [Medium] `regulator_is_enabled()` can return negative error codes, which are improperly evaluated as true.
- [Medium] The early return path skips clearing pending completions, potentially causing stale reads.
- [Medium] Alarm configuration (command mode) fails unconditionally with timeouts if the regulator is always-on.
- [Low] `try_wait_for_completion()` is improperly used to reset the completion structure.
--

--- Patch [3]: [PATCH v2 3/4] hwmon: chipcap2: enable IRQ processing when regulator is already enabled ---
commit d7e6228cb08396bc9407928fe3b3e28aa4aaf084
Author: Javier Carrasco <javier.carrasco.cruz@gmail.com>

hwmon: chipcap2: enable IRQ processing when regulator is already enabled

cc2_enable() returns early when the regulator is already enabled.
This can happen if a previous regulator_disable() failed or if the
regulator was configured as always-on.

> diff --git a/drivers/hwmon/chipcap2.c b/drivers/hwmon/chipcap2.c
> --- a/drivers/hwmon/chipcap2.c
> +++ b/drivers/hwmon/chipcap2.c
> @@ -119,8 +119,10 @@ static int cc2_enable(struct cc2_data *data)
>  	int ret;
>  
>  	/* exclusive regulator, check in case a disable failed */
> -	if (regulator_is_enabled(data->regulator))
> +	if (regulator_is_enabled(data->regulator)) {

[Severity: Medium]
This is a pre-existing issue, but regulator_is_enabled() can return negative
error codes. Does this condition in cc2_enable() evaluate to true for negative
error codes like -EINVAL, incorrectly bypassing the enable sequence?

Similarly, in cc2_disable(), this check incorrectly tries to disable the
regulator if its state check failed.

[Severity: High]
This is a pre-existing issue, but returning early here bypasses taking a
software reference via regulator_enable() if the regulator is physically
enabled.

If the regulator is physically always-on (e.g., fixed-regulator),
regulator_is_enabled() returns 1, and cc2_enable() skips regulator_enable().
Then cc2_disable() calls regulator_disable() without a matching enable,
triggering a kernel WARN because the consumer's enable_count is 0.

Should this code ensure regulator_enable() is always called to maintain
balance?

[Severity: Medium]
This is a pre-existing issue, but does the command mode retry logic in
cc2_command_mode_start() fundamentally assume regulator_disable() guarantees a
physical power cycle?

cc2_command_mode_start() calls cc2_disable() followed by an msleep() to power
cycle the device. If the regulator is always-on, power is never physically
removed, the 10ms startup window is permanently missed, and the START_CM
command is ignored, causing alarm configuration to fail with -ETIMEDOUT.

> +		data->process_irqs = true;
>  		return 0;

[Severity: Medium]
This is a pre-existing issue, but does this early return skip clearing the
pending completion?

If a late interrupt from a prior timeout leaves data->complete.done > 0, and
the regulator is already enabled, the early return in cc2_enable() bypasses
the reset.

Subsequently, the wait in cc2_read_measurement():

ret = wait_for_completion_timeout(&data->complete, timeout);

will succeed immediately, potentially fetching stale data prematurely before
the sensor finishes its measurement, returning -EBUSY.

> +	}
>  
>  	/* clear any pending completion */
>  	try_wait_for_completion(&data->complete);

[Severity: Low]
This is a pre-existing issue, but is try_wait_for_completion() improperly used
to reset the completion structure?

try_wait_for_completion() only decrements the done counter by 1. If multiple
interrupts occurred, done might be > 1, so the next wait could succeed
immediately.

Should this use reinit_completion() instead?

[ ... ]

[Severity: High]
This is a pre-existing issue, but does the combination of cpu_to_be16s() and
i2c_smbus_write_word_data() in cc2_write_reg() write swapped byte sequences on
Big Endian platforms?

On Big Endian systems, cpu_to_be16s() is a no-op. i2c_smbus_write_word_data()
mathematically sends the least significant 8 bits first. Thus, on Big Endian,
the original LSB is sent first, whereas the sensor expects MSB first,
which corrupts the alarm threshold configuration.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260823-chipcap2_locks-v2-0-6a26c8e9e2fc@gmail.com?part=3

  reply	other threads:[~2026-08-23 18:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-23 17:59 [PATCH v2 0/4] hwmon: chipcap2: various bug fixes Javier Carrasco
2026-08-23 17:59 ` [PATCH v2 1/4] hwmon: chipcap2: fix channels in humidity alarm notifications Javier Carrasco
2026-08-23 18:11   ` sashiko-bot
2026-08-23 18:17     ` Javier Carrasco
2026-08-28 15:27   ` Guenter Roeck
2026-08-23 17:59 ` [PATCH v2 2/4] hwmon: chipcap2: fix IRQ teardown ordering Javier Carrasco
2026-08-23 18:12   ` sashiko-bot
2026-08-23 18:22     ` Javier Carrasco
2026-08-23 21:14       ` Javier Carrasco
2026-08-23 17:59 ` [PATCH v2 3/4] hwmon: chipcap2: enable IRQ processing when regulator is already enabled Javier Carrasco
2026-08-23 18:11   ` sashiko-bot [this message]
2026-08-23 19:13     ` Javier Carrasco
2026-08-23 17:59 ` [PATCH v2 4/4] hwmon: chipcap2: serialize access to low/high_alarm indicators Javier Carrasco
2026-08-23 18:06   ` sashiko-bot
2026-08-23 18:16     ` Javier Carrasco

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=20260823181143.F32B11F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=linux-hwmon@vger.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 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.