From: sashiko-bot@kernel.org
To: "Alexis Czezar Torreno" <alexisczezar.torreno@analog.com>
Cc: linux-hwmon@vger.kernel.org, conor+dt@kernel.org,
devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v3 2/4] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support
Date: Mon, 20 Jul 2026 03:25:50 +0000 [thread overview]
Message-ID: <20260720032550.A4F891F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720-dev-max20830c-v3-2-9d06d27d6da3@analog.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The voltage divider scaling calculation suffers from a 32-bit addition overflow and an unsafe 64-bit to 32-bit signed integer truncation before clamping.
--
--- Patch [2]: [PATCH v3 2/4] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support ---
commit ac88893286286c633f117369db91c2cffd163afd
Author: Alexis Czezar Torreno <alexisczezar.torreno@analog.com>
hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support
This commit implements support for external voltage divider scaling using
the adi,vout-rfb1-ohms and adi,vout-rfb2-ohms device tree properties. The
driver reads these values and applies the scaling formula to the raw VOUT
reading.
> diff --git a/drivers/hwmon/pmbus/max20830.c b/drivers/hwmon/pmbus/max20830.c
> index cb2c23672166d..7a5e67bd33c0a 100644
> --- a/drivers/hwmon/pmbus/max20830.c
> +++ b/drivers/hwmon/pmbus/max20830.c
[ ... ]
> +static int max20830_read_word_data(struct i2c_client *client, int page,
> + int phase, int reg)
> +{
> + const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
> + const struct max20830_data *data = container_of(info, struct max20830_data, info);
> + int ret;
> +
> + switch (reg) {
> + case PMBUS_READ_VOUT:
> + ret = pmbus_read_word_data(client, page, phase, reg);
> + if (ret < 0)
> + return ret;
> +
> + /* Apply voltage divider scaling if resistors are non-zero */
> + if (data->vout_rfb1 && data->vout_rfb2) {
> + ret = DIV_ROUND_CLOSEST_ULL((u64)ret * (data->vout_rfb1 +
> + data->vout_rfb2), data->vout_rfb2);
> + ret = clamp_val(ret, 0, 0xFFFF);
[Severity: Medium]
Can this calculation suffer from a 32-bit addition overflow and an unsafe
64-bit to 32-bit signed integer truncation?
If data->vout_rfb1 and data->vout_rfb2 sum to more than 2^32 - 1, the 32-bit
addition will wrap around before the 64-bit multiplication.
Additionally, since ret is a signed 32-bit integer, if the 64-bit result
returned from DIV_ROUND_CLOSEST_ULL exceeds 2^31 - 1, the assignment to ret
will overflow into a negative integer. The clamp_val() macro will then
evaluate this negative number and incorrectly clamp it to 0 instead of
0xFFFF.
> + }
> + return ret;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260720-dev-max20830c-v3-0-9d06d27d6da3@analog.com?part=2
next prev parent reply other threads:[~2026-07-20 3:25 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 3:14 [PATCH v3 0/4] Add support for MAX20830C and MAX20840C step-down DC-DC switching regulator Alexis Czezar Torreno
2026-07-20 3:14 ` [PATCH v3 1/4] dt-bindings: hwmon: (pmbus/max20830): add VOUT feedback resistor properties and complete examples Alexis Czezar Torreno
2026-07-20 3:22 ` sashiko-bot
2026-07-20 3:28 ` Torreno, Alexis Czezar
2026-07-20 3:41 ` Torreno, Alexis Czezar
2026-07-20 4:38 ` Rob Herring (Arm)
2026-07-20 3:14 ` [PATCH v3 2/4] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support Alexis Czezar Torreno
2026-07-20 3:25 ` sashiko-bot [this message]
2026-07-21 0:44 ` Torreno, Alexis Czezar
2026-07-21 1:05 ` Guenter Roeck
2026-07-21 1:13 ` Torreno, Alexis Czezar
2026-07-20 3:14 ` [PATCH v3 3/4] dt-bindings: hwmon: (pmbus/max20830): add max20830c and max20840c support Alexis Czezar Torreno
2026-07-20 3:21 ` sashiko-bot
2026-07-21 0:44 ` Torreno, Alexis Czezar
2026-07-20 4:38 ` Rob Herring (Arm)
2026-07-20 3:14 ` [PATCH v3 4/4] hwmon: (pmbus/max20830): add support for max20830c and max20840c Alexis Czezar Torreno
2026-07-20 3:29 ` sashiko-bot
2026-07-21 0:44 ` Torreno, Alexis Czezar
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=20260720032550.A4F891F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexisczezar.torreno@analog.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox