From: sashiko-bot@kernel.org
To: "Jared Kangas" <jkangas@redhat.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v2 2/4] hwmon: (ina2xx) Parameterize ina2xx_data in ina226_alert_read()
Date: Thu, 20 Aug 2026 13:21:12 +0000 [thread overview]
Message-ID: <20260820132112.AA69C1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260820-upstream-ina2xx-in0-curr1-alarms-v2-2-fdce35abc41e@redhat.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Arithmetic overflows and incorrect clamping logic cause alert limits to be wrongly configured to 0 instead of maximum for shunt voltage and power alerts on 32-bit systems.
--
--- Patch [2]: [PATCH v2 2/4] hwmon: (ina2xx) Parameterize ina2xx_data in ina226_alert_read() ---
commit 034555c6bd153d8c094cfb7d04cc7d98d34d3774
Author: Jared Kangas <jkangas@redhat.com>
hwmon: (ina2xx) Parameterize ina2xx_data in ina226_alert_read()
This commit updates ina226_alert_read() to take a struct ina2xx_data pointer
instead of a struct regmap pointer. This aligns its parameters with
ina226_alert_limit_read() and ina226_alert_limit_write().
> diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
> index f6c63ce1ef193..c56e42432673f 100644
> --- a/drivers/hwmon/ina2xx.c
> +++ b/drivers/hwmon/ina2xx.c
> @@ -476,12 +476,12 @@ static int ina2xx_chip_read(struct device *dev, u32 attr, long *val)
> return 0;
> }
>
> -static int ina226_alert_read(struct regmap *regmap, u32 mask, long *val)
> +static int ina226_alert_read(struct ina2xx_data *data, u32 mask, long *val)
> {
> unsigned int regval;
> int ret;
[ ... ]
[Severity: High]
This is a pre-existing issue, and was not introduced by the patch under review,
but does ina226_alert_to_reg() have arithmetic overflows and incorrect clamping
logic on 32-bit systems?
When a user or configuration script sets a valid power limit or a large shunt
voltage limit on a 32-bit system, it appears the values might collapse to zero:
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;
val <<= data->config->shunt_voltage_shift;
return clamp_val(val, 0, SHRT_MAX);
...
case INA2XX_POWER:
val = clamp_val(val, 0, UINT_MAX - data->power_lsb_uW);
val = DIV_ROUND_CLOSEST(val, data->power_lsb_uW);
return clamp_val(val, 0, USHRT_MAX);
...
}
For INA2XX_POWER, could UINT_MAX - data->power_lsb_uW implicitly cast to a
negative long upper bound in the clamp_val macro, forcing all limits to
negative?
And for INA2XX_SHUNT_VOLTAGE, is the clamp mistakenly using multiplication
(SHRT_MAX * data->config->shunt_div) instead of division, allowing large values
that later overflow a signed 32-bit long multiplication?
In both cases, it looks like the final step clamps the negative intermediate
value to 0, which could cause immediate false hardware alerts if the alert pin
is wired to hardware reset logic.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260820-upstream-ina2xx-in0-curr1-alarms-v2-0-fdce35abc41e@redhat.com?part=2
next prev parent reply other threads:[~2026-08-20 13:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 13:09 [PATCH v2 0/4] hwmon: (ina2xx) Decouple in0 and curr1 alarms Jared Kangas
2026-08-20 13:09 ` [PATCH v2 1/4] hwmon: (ina2xx) Acquire hwmon_lock in shunt_resistor_show() Jared Kangas
2026-08-20 13:17 ` sashiko-bot
2026-08-20 13:09 ` [PATCH v2 2/4] hwmon: (ina2xx) Parameterize ina2xx_data in ina226_alert_read() Jared Kangas
2026-08-20 13:21 ` sashiko-bot [this message]
2026-08-20 13:09 ` [PATCH v2 3/4] hwmon: (ina2xx) Replace masks with enum in alert functions Jared Kangas
2026-08-20 13:17 ` sashiko-bot
2026-08-20 13:09 ` [PATCH v2 4/4] hwmon: (ina2xx) Decouple in0 and curr1 alarms Jared Kangas
2026-08-20 13:23 ` 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=20260820132112.AA69C1F00A3A@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 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.