All of lore.kernel.org
 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 2/4] hwmon: (ina2xx) Replace masks with enum in alert functions
Date: Wed, 19 Aug 2026 13:57:40 -0700	[thread overview]
Message-ID: <aoYYxM63yFRgrxFD@rh-jkangas-kernel> (raw)
In-Reply-To: <20260729160250.7FCE21F00A3A@smtp.kernel.org>

On Wed, Jul 29, 2026 at 04:02:50PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
> 
> [snip]
> 
> [Severity: Medium]
> Does this actually distinguish current from shunt voltage alerts as stated
> in the commit message?

No, this patch is intended to do some replumbing to make the fix
cleaner. I could see how the patch phrasing could come off the wrong way
though. I'll reword this in v2.

> 
> By converting the enum back to the shared hardware mask here and in
> ina226_alert_read(), and not tracking which alert was actually configured,
> reading current limits or alarms via sysfs can return the value or status of
> a configured shunt voltage limit (or vice versa), yielding incorrectly scaled
> hardware measurements.
> 
> [snip]
> 
> [Severity: High]
> This is a pre-existing issue, but does ina226_alert_limit_write() reject
> valid configurations for reverse current flow?
> 
> The function explicitly returns -EINVAL for negative limits:
> 
>     if (val < 0)
>         return -EINVAL;
> 
> This prevents configuring hardware alerts for reverse current or negative
> shunt voltage, such as during battery discharge.
> 

Shunt/bus voltages are clamped to non-negative values in the driver, so
this seems like more of a design choice than a high-severity issue.

> Additionally, if the limit is exactly zero, the alert is not enabled here,
> which makes it impossible to trigger an alert at exactly zero.

Disabling on zero is an explicit driver choice, per
Documentation/hwmon/ina2xx.rst:

    Writing 0 to any `*crit` setting clears all `*crit` settings and
    alarms.

> 
> [snip]
> 
> [Severity: High]
> This is a pre-existing issue, but can the calculations in ina2xx_get_value()
> and ina226_alert_to_reg() overflow?
> 
> For large limit values, such as a 200V bus voltage limit, the shift operation
> in ina226_alert_to_reg() on 32-bit architectures:
> 
>     val = (val * 1000) << data->config->bus_voltage_shift;
> 
> yields 3.2 billion, which overflows a signed 32-bit long variable. This
> results in a negative value that gets clamped to 0.
> 
> Similarly, in ina2xx_get_value() called above:
> 
>     val = regval * data->power_lsb_uW;
> 
> the power calculation can overflow a 32-bit signed int for large regval and
> high power_lsb_uW, returning negative power readings.

This is addressed in e6c80061ca23 ("hwmon: (ina2xx) Fix various overflow
issues").

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


  reply	other threads:[~2026-08-19 20:57 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 [this message]
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
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=aoYYxM63yFRgrxFD@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 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.