Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Jared Kangas <jkangas@redhat.com>
To: sashiko-reviews@lists.linux.dev
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH 4/4] hwmon: (ina2xx) Return 0 on inactive alarm/limit reads
Date: Wed, 19 Aug 2026 14:20:53 -0700	[thread overview]
Message-ID: <aoYeNed4r3yLVhJD@rh-jkangas-kernel> (raw)
In-Reply-To: <20260729162836.89BDF1F00A3A@smtp.kernel.org>

On Wed, Jul 29, 2026 at 04:28:36PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
> 
> [snip]
> 
> [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?

As with [1] and [2], this clearing is documented in
Documentation/hwmon/ina2xx.rst.

[1]: https://lore.kernel.org/all/aoYYxM63yFRgrxFD@rh-jkangas-kernel/
[2]: https://lore.kernel.org/all/aoYasBdVYNYa1OBB@rh-jkangas-kernel/

> 
> [ ... ]
> 
> [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;
> 
> [snip]
> 
> [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;
> 
> [snip]
> 
> [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);

These are addressed in e6c80061ca23 ("hwmon: (ina2xx) Fix various
overflow issues").

> [snip]
> 
> [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?

This seems accurate. It's not very related to the series but an easy
fix, so I'll put it in v2 since it was reported here.

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


  reply	other threads:[~2026-08-19 21:20 UTC|newest]

Thread overview: 14+ 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-08-19 20:42     ` Jared Kangas
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-08-19 20:57     ` Jared Kangas
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-08-19 21:05     ` Jared Kangas
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
2026-08-19 21:20     ` Jared Kangas [this message]
2026-07-31 14:34 ` [PATCH 0/4] hwmon: (ina2xx) Decouple in0 and curr1 alarms Guenter Roeck

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=aoYeNed4r3yLVhJD@rh-jkangas-kernel \
    --to=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