From: sashiko-bot@kernel.org
To: "Guenter Roeck" <linux@roeck-us.net>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v3] hwmon: (ina2xx) Fix overflow issues
Date: Thu, 11 Jun 2026 14:07:06 +0000 [thread overview]
Message-ID: <20260611140706.7DD961F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260611135706.826074-1-linux@roeck-us.net>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Clamping to LONG_MAX/LONG_MIN before DIV_ROUND_CLOSEST guarantees signed integer overflow/underflow on 32-bit platforms.
--
commit 6fb047c808b5329542311277defe6fdce7b455f0
Author: Guenter Roeck <linux@roeck-us.net>
hwmon: (ina2xx) Fix overflow issues
This commit fixes several integer overflow issues in the ina2xx driver
by upgrading intermediate calculations to 64-bit and adjusting the
clamping limits. It also updates the return type of ina2xx_get_value
to long to better support 64-bit systems.
> diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
> --- a/drivers/hwmon/ina2xx.c
> +++ b/drivers/hwmon/ina2xx.c
[ ... ]
> @@ -283,12 +285,13 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg,
> val = DIV_ROUND_CLOSEST(val, 1000);
> break;
> case INA2XX_POWER:
> - val = regval * data->power_lsb_uW;
> + val = clamp_val((u64)regval * data->power_lsb_uW, 0, LONG_MAX);
> break;
> case INA2XX_CURRENT:
> /* signed register, result in mA */
> - val = ((s16)regval >> data->config->current_shift) *
> + val64 = (s64)((s16)regval >> data->config->current_shift) *
> data->current_lsb_uA;
> + val = clamp_val(val64, LONG_MIN, LONG_MAX);
> val = DIV_ROUND_CLOSEST(val, 1000);
[Severity: High]
Can clamping to LONG_MAX and LONG_MIN here cause a signed integer overflow
on 32-bit systems?
Since val is clamped to the absolute limits of a signed long, when it is
subsequently passed to DIV_ROUND_CLOSEST(val, 1000), the rounding macro
will add 500 to positive values or subtract 500 from negative values.
Could this operation overflow LONG_MAX and underflow LONG_MIN, causing the
value to wrap around and return the opposite sign instead of the intended
clamped maximum limit?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260611135706.826074-1-linux@roeck-us.net?part=1
prev parent reply other threads:[~2026-06-11 14:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 13:57 [PATCH v3] hwmon: (ina2xx) Fix overflow issues Guenter Roeck
2026-06-11 14:07 ` 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=20260611140706.7DD961F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
--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