From: sashiko-bot@kernel.org
To: "Jared Kangas" <jkangas@redhat.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH 4/4] hwmon: (ina2xx) Return 0 on inactive alarm/limit reads
Date: Wed, 29 Jul 2026 16:28:36 +0000 [thread overview]
Message-ID: <20260729162836.89BDF1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260729-upstream-ina2xx-in0-curr1-alarms-v1-4-349f7b2f1df8@redhat.com>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Pre-existing issues:
- [High] Writing `0` to an inactive alert limit attribute unintentionally disables the currently active alert limit of a completely different type.
- [High] In `ina2xx_get_value`, calculating `INA2XX_POWER` can overflow a 32-bit signed `int` for small shunt resistor values, resulting in negative power readings.
- [High] In `ina226_alert_to_reg`, `INA2XX_SHUNT_VOLTAGE` limits can overflow a 32-bit signed `long`, causing large limits to be incorrectly clamped to 0 on 32-bit systems.
- [High] In `ina226_alert_to_reg`, `INA2XX_POWER` limits always evaluate to 0 on 32-bit systems because `UINT_MAX` is cast to a negative `long` in the clamping macro.
- [Medium] The `shunt_resistor_show` function accesses shared driver state locklessly, violating HWMON subsystem locking guidelines.
--
--- Patch [4]: [PATCH 4/4] hwmon: (ina2xx) Return 0 on inactive alarm/limit reads ---
commit 4e821bd1003ecc2b04b0b58f9702178e2bd3a2eb
Author: Jared Kangas <jkangas@redhat.com>
hwmon: (ina2xx) Return 0 on inactive alarm/limit reads
Guard alarm/limit reads with a check that returns zero if the active
alarm is for a different type to avoid unintentionally clearing alarms.
> diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
> index 8ba0dce1f9e31..5521490deba98 100644
> --- a/drivers/hwmon/ina2xx.c
> +++ b/drivers/hwmon/ina2xx.c
> @@ -479,6 +479,12 @@ static int ina226_alert_limit_read(struct ina2xx_data *data, enum ina2xx_alert_t
> u32 mask;
> int ret;
>
> + /* Avoid nonzero reads from inactive alerts caused by shared limit register */
> + if (data->active_alert != alert) {
> + *val = 0;
> + return 0;
> + }
> +
[Severity: High]
This isn't a bug introduced by this patch, but since we are fixing the
read path for inactive alerts here, what happens on the write path?
If a user or monitoring daemon reads an inactive alert attribute (which
now correctly returns 0) and subsequently writes 0 back to it, will
ina226_alert_limit_write() unconditionally wipe the active alert?
Looking at ina226_alert_limit_write():
ret = regmap_update_bits(regmap, INA226_MASK_ENABLE,
INA226_ALERT_CONFIG_MASK, 0);
...
data->active_alert = val ? alert : INA2XX_ALERT_NONE;
Does this inadvertently destroy the configuration of the currently active
alert of a different type without checking if the disable operation applies
to it?
[ ... ]
[Severity: High]
This is a pre-existing issue, but I noticed a potential overflow when
calculating power values.
In ina2xx_get_value() for INA2XX_POWER:
case INA2XX_POWER:
val = regval * data->power_lsb_uW;
break;
If a user configures a small shunt resistor (e.g., 1 mOhm), power_lsb_uW
becomes large. When the hardware measures high power, regval can also be
quite large.
Since val is a 32-bit signed integer, could this multiplication overflow
on 32-bit architectures and result in incorrect negative power readings
being reported to userspace?
[Severity: High]
This is a pre-existing issue, but could we run into an overflow on 32-bit
architectures when setting shunt voltage limits?
In ina226_alert_to_reg():
case INA2XX_SHUNT_VOLTAGE:
val = clamp_val(val, 0, SHRT_MAX * data->config->shunt_div);
val *= data->config->shunt_div;
On a 32-bit system, long is 32 bits. If a user inputs a large limit, and
it passes the first clamp, the multiplication by shunt_div could exceed
the maximum value of a signed 32-bit integer.
Does this overflow the signed long, wrapping to a negative value that
then gets incorrectly clamped to 0 by the final clamp_val()?
[Severity: High]
This is a pre-existing issue, but setting power limits on 32-bit systems
seems to always evaluate to 0.
In ina226_alert_to_reg():
case INA2XX_POWER:
val = clamp_val(val, 0, UINT_MAX - data->power_lsb_uW);
The clamp_val macro casts bounds to typeof(val) which is a signed long.
On 32-bit systems, does UINT_MAX - data->power_lsb_uW evaluate to a
large positive unsigned value that becomes negative when cast to a
signed long?
If the upper bound is negative, does this force clamp_val to rewrite all
positive user inputs to negative values, guaranteeing the function always
returns 0?
[Severity: Medium]
This is a pre-existing issue, but there appears to be a locking violation
when reading the shunt resistor.
The hwmon subsystem guidelines require drivers to use hwmon_lock() for
attributes registered outside the core info parameter.
Looking at shunt_resistor_show():
static ssize_t shunt_resistor_show(struct device *dev,
struct device_attribute *da, char *buf)
{
struct ina2xx_data *data = dev_get_drvdata(dev);
return sysfs_emit(buf, "%li\n", data->rshunt);
}
Since shunt_resistor_store() modifies data->rshunt, does this show
function need to acquire the hwmon_lock to prevent unprotected concurrent
accesses?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260729-upstream-ina2xx-in0-curr1-alarms-v1-0-349f7b2f1df8@redhat.com?part=4
prev parent reply other threads:[~2026-07-29 16:28 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
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 [this message]
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=20260729162836.89BDF1F00A3A@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