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 v2 3/5] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support
Date: Mon, 06 Jul 2026 02:21:55 +0000 [thread overview]
Message-ID: <20260706022155.C5B251F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260706-dev-max20830c-v2-3-37761e89bb5f@analog.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Scaled `PMBUS_READ_VOUT` value can exceed the 16-bit capacity of the PMBus `LINEAR16` format, causing silent truncation and incorrect voltage reporting.
- [High] Missing software scaling for VOUT limit attributes and missing `.write_word_data` callback causes hardware limits to be programmed completely out of bounds.
--
commit 19e6041d100f0e80c9e49784d17900b141e3ea61
Author: Alexis Czezar Torreno <alexisczezar.torreno@analog.com>
hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support
Implement support for external voltage divider scaling using the
adi,vout-rfb1-ohms and adi,vout-rfb2-ohms device tree properties.
When the desired output voltage exceeds VREF, a resistor divider
(RFB1 and RFB2) is used to scale down the feedback voltage. The
driver reads these resistor values from device tree and applies
the scaling formula: VOUT_actual = VOUT_measured × (1 + RFB1/RFB2)
> diff --git a/drivers/hwmon/pmbus/max20830.c b/drivers/hwmon/pmbus/max20830.c
> index cb2c23672166d..5aad4448054fc 100644
> --- a/drivers/hwmon/pmbus/max20830.c
> +++ b/drivers/hwmon/pmbus/max20830.c
[ ... ]
> @@ -14,6 +15,45 @@
>
> #define MAX20830_IC_DEVICE_ID_LENGTH 9
>
> +struct max20830_data {
> + struct pmbus_driver_info info;
> + u32 vout_rfb1;
> + u32 vout_rfb2;
> +};
> +
> +/*
> + * Driver currently only supports READ_VOUT for monitoring that needs scaling to
> + * convert from feedback voltage to actual output voltage.
> + *
> + * vout_actual = vout_fb × (1 + RFB1/RFB2)
> + *
> + * VOUT_COMMAND and VOUT_MAX are currently not in use, but work with feedback
> + * voltage. If regulator support is added, VOUT_COMMAND values would need
> + * to be adjusted accordingly.
> + */
> +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);
> + return ret;
[Severity: High]
Does this returned value need bounds checking?
If a large resistor divider is used, the scaled PMBus word calculated here
can exceed 0xFFFF. The generic PMBus core function pmbus_reg2data_linear()
will cast this returned value to a u16, silently wrapping the value modulo
65536 and resulting in wildly incorrect telemetry (e.g., reporting 2V instead
of 12V).
Should this be clamped using clamp_val(ret, 0, 0xffff)?
> + default:
> + return -ENODATA;
> + }
> +}
[Severity: High]
Will returning -ENODATA bypass software scaling for VOUT limit attributes?
The driver sets PMBUS_HAVE_VOUT below, which exposes hardware VOUT limits
(like inX_max or inX_lcrit). Because only PMBUS_READ_VOUT is intercepted
here, the core will read those limits unscaled from the hardware.
> +
> static struct pmbus_driver_info max20830_info = {
> .pages = 1,
> .format[PSC_VOLTAGE_IN] = linear,
> @@ -24,13 +64,25 @@ static struct pmbus_driver_info max20830_info = {
> PMBUS_HAVE_TEMP |
> PMBUS_HAVE_STATUS_VOUT | PMBUS_HAVE_STATUS_IOUT |
> PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP,
> + .read_word_data = max20830_read_word_data,
[Severity: High]
Does this struct also need a .write_word_data callback?
Since PMBUS_HAVE_VOUT is enabled, user writes to limit attributes will fall
through to the PMBus core, which writes the scaled PMBus word directly into
the hardware's limit register. Because the hardware expects limits in the
unscaled feedback voltage range, the written value will be completely out
of bounds.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260706-dev-max20830c-v2-0-37761e89bb5f@analog.com?part=3
next prev parent reply other threads:[~2026-07-06 2:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 2:08 [PATCH v2 0/5] Add support for MAX20830C and MAX20840C step-down DC-DC switching regulator Alexis Czezar Torreno
2026-07-06 2:08 ` [PATCH v2 1/5] dt-bindings: hwmon: (pmbus/max20830): add enable-gpios property and complete examples Alexis Czezar Torreno
2026-07-06 2:16 ` sashiko-bot
2026-07-06 6:39 ` Krzysztof Kozlowski
2026-07-06 7:13 ` Torreno, Alexis Czezar
2026-07-06 16:33 ` Guenter Roeck
2026-07-06 14:01 ` Guenter Roeck
2026-07-06 2:08 ` [PATCH v2 2/5] dt-bindings: hwmon: (pmbus/max20830): add VOUT feedback resistor properties Alexis Czezar Torreno
2026-07-06 2:14 ` sashiko-bot
2026-07-06 2:08 ` [PATCH v2 3/5] hwmon: (pmbus/max20830): add VOUT feedback resistor scaling support Alexis Czezar Torreno
2026-07-06 2:21 ` sashiko-bot [this message]
2026-07-06 2:08 ` [PATCH v2 4/5] dt-bindings: hwmon: (pmbus/max20830): add max20830c and max20840c support Alexis Czezar Torreno
2026-07-06 2:16 ` sashiko-bot
2026-07-06 6:40 ` Krzysztof Kozlowski
2026-07-06 2:08 ` [PATCH v2 5/5] hwmon: (pmbus/max20830): add support for max20830c and max20840c Alexis Czezar Torreno
2026-07-06 2:20 ` sashiko-bot
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=20260706022155.C5B251F000E9@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