Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jared Kangas" <jkangas@redhat.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH 3/4] hwmon: (ina2xx) Track active alarm in ina2xx_data
Date: Wed, 29 Jul 2026 16:18:23 +0000	[thread overview]
Message-ID: <20260729161824.5D4C01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260729-upstream-ina2xx-in0-curr1-alarms-v1-3-349f7b2f1df8@redhat.com>

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

New issues:
- [High] Writing 0 to an inactive alert limit unintentionally clears the hardware mask, disabling the unrelated, currently active alert limit.
- [Medium] The `ina226_alert_read` function fails to use the new `active_alert` disambiguation state, causing unconfigured alarm attributes to incorrectly return 1 if another alarm triggers.

Pre-existing issues:
- [High] On 32-bit architectures, setting any positive power limit results in a limit of 0 due to an integer underflow when interacting with `clamp_val()`.
- [High] Setting large shunt voltage limits causes an integer overflow on 32-bit architectures, resulting in a limit of 0 instead of the maximum clamped limit.
--

--- Patch [3]: [PATCH 3/4] hwmon: (ina2xx) Track active alarm in ina2xx_data ---
commit 480990f993b0efa725eee2c5b0c2a864cd60bcfb
Author: Jared Kangas <jkangas@redhat.com>

hwmon: (ina2xx) Track active alarm in ina2xx_data

INA2XX current limits are converted into shunt voltage limits internally
using the shunt resistor value. Once a current limit's corresponding
voltage limit is written to the hardware, shunt voltage and current
alarms are indistinguishable from each other.

> diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
> --- a/drivers/hwmon/ina2xx.c
> +++ b/drivers/hwmon/ina2xx.c
> @@ -157,6 +157,7 @@ struct ina2xx_data {
>  	const struct ina2xx_config *config;
>  	enum ina2xx_ids chip;
>  
> +	enum ina2xx_alert_type active_alert;

[Severity: Medium]
Will this new state also be checked in ina226_alert_read()?

If an unconfigured alarm triggers, could it incorrectly return 1 since both
alarms map to the same hardware mask?

drivers/hwmon/ina2xx.c:ina226_alert_read() {
    ...
    mask = ina2xx_alert_type_to_mask(alert);
    *val = (regval & mask) && (regval & INA226_ALERT_FUNCTION_FLAG);
    ...
}

[ ... ]

> @@ -492,9 +522,13 @@ static int ina226_alert_limit_write(struct ina2xx_data *data, enum ina2xx_alert_
>  
>  	if (val) {
>  		mask = ina2xx_alert_type_to_mask(alert);
> -		return regmap_update_bits(regmap, INA226_MASK_ENABLE,
> -					  INA226_ALERT_CONFIG_MASK, mask);
> +		ret = regmap_update_bits(regmap, INA226_MASK_ENABLE,
> +					 INA226_ALERT_CONFIG_MASK, mask);
> +		if (ret < 0)
> +			return ret;
>  	}
> +
> +	data->active_alert = val ? alert : INA2XX_ALERT_NONE;

[Severity: High]
If a user writes 0 to an inactive alert limit, will it unintentionally clear
the hardware mask at the beginning of ina226_alert_limit_write() and wipe out
the currently active alert?

drivers/hwmon/ina2xx.c:ina226_alert_limit_write() {
    ...
    ret = regmap_update_bits(regmap, INA226_MASK_ENABLE,
                 INA226_ALERT_CONFIG_MASK, 0);
    ...
}

[Severity: High]
This is a pre-existing issue, but on 32-bit architectures, does this clamp
operation compute a negative boundary for INA2XX_POWER?

drivers/hwmon/ina2xx.c:ina226_alert_to_reg() {
    ...
    case INA2XX_POWER:
        val = clamp_val(val, 0, UINT_MAX - data->power_lsb_uW);
    ...
}

Because UINT_MAX is cast to signed long by clamp_val(), it could result in a
negative upper bound, forcing val to a negative number which is then clamped
to 0.

[Severity: High]
This is also a pre-existing issue, but does setting a large shunt voltage
limit cause an integer overflow on 32-bit architectures?

drivers/hwmon/ina2xx.c:ina226_alert_to_reg() {
    ...
    case INA2XX_SHUNT_VOLTAGE:
        val = clamp_val(val, 0, SHRT_MAX * data->config->shunt_div);
        val *= data->config->shunt_div;
    ...
}

If a user sets a large valid limit on a 32-bit system, the multiplication
might overflow the signed 32-bit long into a negative number, which is then
incorrectly clamped to 0.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260729-upstream-ina2xx-in0-curr1-alarms-v1-0-349f7b2f1df8@redhat.com?part=3

  reply	other threads:[~2026-07-29 16:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 15:42 [PATCH 0/4] hwmon: (ina2xx) Decouple in0 and curr1 alarms Jared Kangas
2026-07-29 15:42 ` [PATCH 1/4] hwmon: (ina2xx) Replace regmap in ina226_alert_read() with ina2xx_data Jared Kangas
2026-07-29 15:52   ` sashiko-bot
2026-07-29 15:42 ` [PATCH 2/4] hwmon: (ina2xx) Replace masks with enum in alert functions Jared Kangas
2026-07-29 16:02   ` sashiko-bot
2026-07-29 15:42 ` [PATCH 3/4] hwmon: (ina2xx) Track active alarm in ina2xx_data Jared Kangas
2026-07-29 16:18   ` sashiko-bot [this message]
2026-07-29 15:42 ` [PATCH 4/4] hwmon: (ina2xx) Return 0 on inactive alarm/limit reads Jared Kangas
2026-07-29 16:28   ` sashiko-bot

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=20260729161824.5D4C01F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=jkangas@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox