From: sashiko-bot@kernel.org
To: "Matti Vaittinen" <matti.vaittinen@linux.dev>
Cc: linux-hwmon@vger.kernel.org, conor+dt@kernel.org,
robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v2 3/9] hwmon: adm1275: Detect coefficient overflow
Date: Fri, 26 Jun 2026 07:35:20 +0000 [thread overview]
Message-ID: <20260626073521.337D81F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <d9e3320dbd62e094ff89598cb3aac5b5e716f9e7.1782458224.git.mazziesaccount@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch introduces spurious probe failures by restricting the intermediate `shunt * m` multiplication to a 32-bit limit instead of using a 64-bit calculation, needlessly rejecting perfectly valid shunt resistor configurations.
--
commit 02af229d429dc5c77e875edeb815b9caba7e6da2
Author: Matti Vaittinen <mazziesaccount@gmail.com>
hwmon: adm1275: Detect coefficient overflow
This commit detects potential coefficient overflow when a large shunt
resistor is used and aborts the probe if an overflow is detected.
> diff --git a/drivers/hwmon/pmbus/adm1275.c b/drivers/hwmon/pmbus/adm1275.c
> index 43baa5ded35e5..ccc3ad21e38e7 100644
> --- a/drivers/hwmon/pmbus/adm1275.c
> +++ b/drivers/hwmon/pmbus/adm1275.c
> @@ -839,15 +839,25 @@ static int adm1275_probe(struct i2c_client *client)
> info->R[PSC_VOLTAGE_OUT] = coefficients[voindex].R;
> }
> if (cindex >= 0) {
> + u32 m;
> +
> /* Scale current with sense resistor value */
> - info->m[PSC_CURRENT_OUT] =
> - coefficients[cindex].m * shunt / 1000;
> + if (unlikely(check_mul_overflow(coefficients[cindex].m, shunt, &m))) {
[Severity: High]
Does this code introduce a spurious probe failure for valid setups?
By checking for overflow on the intermediate product using a 32-bit
unsigned integer, the probe will fail for configurations where the
product exceeds U32_MAX, but the final scaled value after dividing by
1000 would safely fit into the 32-bit signed integer target field.
Could we use a 64-bit intermediate calculation instead, such as
div_s64((s64)coefficients[cindex].m * shunt, 1000), to prevent this
regression and avoid needlessly rejecting valid shunt resistor setups?
> + dev_err(&client->dev, "Current coefficient overflow\n");
> + return -EOVERFLOW;
> + }
> + info->m[PSC_CURRENT_OUT] = m / 1000;
> info->b[PSC_CURRENT_OUT] = coefficients[cindex].b;
> info->R[PSC_CURRENT_OUT] = coefficients[cindex].R;
> }
> if (pindex >= 0) {
> - info->m[PSC_POWER] =
> - coefficients[pindex].m * shunt / 1000;
> + u32 m;
> +
> + if (unlikely(check_mul_overflow(coefficients[pindex].m, shunt, &m))) {
[Severity: High]
Can this similarly cause the probe to abort prematurely?
For example, configuring an ADM1293 on the 100mV range with a 250000 uOhm
shunt resistor yields a power coefficient product of 26042 * 250000, which
is 6,510,500,000. This mathematically overflows the 32-bit check here, but
the final value of 6,510,500 easily fits in the target field.
Would it be better to calculate this using 64-bit math so the device can
successfully initialize all of its sensors?
> + dev_err(&client->dev, "Power coefficient overflow\n");
> + return -EOVERFLOW;
> + }
> + info->m[PSC_POWER] = m / 1000;
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1782458224.git.mazziesaccount@gmail.com?part=3
next prev parent reply other threads:[~2026-06-26 7:35 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-26 7:21 [PATCH v2 0/9] Support ROHM BD127x0 hot-swap controllers Matti Vaittinen
2026-06-26 7:21 ` [PATCH v2 1/9] dt-bindings: adm1275: ROHM BD12780 hot-swap controller Matti Vaittinen
2026-06-26 7:31 ` sashiko-bot
2026-06-26 15:58 ` Conor Dooley
2026-06-26 7:22 ` [PATCH v2 2/9] hwmon: adm1275: Prevent reading uninitialized stack Matti Vaittinen
2026-06-26 7:32 ` sashiko-bot
2026-06-26 7:23 ` [PATCH v2 3/9] hwmon: adm1275: Detect coefficient overflow Matti Vaittinen
2026-06-26 7:35 ` sashiko-bot [this message]
2026-06-26 7:24 ` [PATCH v2 4/9] hwmon: adm1275: Support module auto-loading Matti Vaittinen
2026-06-26 7:31 ` sashiko-bot
2026-06-26 7:24 ` [PATCH v2 5/9] doc: Add ROHM BD12780 and BD12780A Matti Vaittinen
2026-06-26 7:36 ` sashiko-bot
2026-06-26 7:24 ` [PATCH v2 6/9] hwmon: adm1275: Support ROHM BD12780 Matti Vaittinen
2026-06-26 7:32 ` sashiko-bot
2026-06-26 7:25 ` [PATCH v2 7/9] dt-bindings: adm1275: ROHM BD12790 hot-swap controller Matti Vaittinen
2026-06-26 7:35 ` sashiko-bot
2026-06-26 7:25 ` [PATCH v2 8/9] doc: adm1275: Add ROHM BD12790 Matti Vaittinen
2026-06-26 7:32 ` sashiko-bot
2026-06-26 7:26 ` [PATCH v2 9/9] hwmon: adm1275: Support " Matti Vaittinen
2026-06-26 7:33 ` sashiko-bot
2026-06-26 7:49 ` Matti Vaittinen
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=20260626073521.337D81F00AC4@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=matti.vaittinen@linux.dev \
--cc=robh@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.