From: sashiko-bot@kernel.org
To: "Ziming Zhu" <zmzhu0630@163.com>
Cc: robh@kernel.org, linux-hwmon@vger.kernel.org,
conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 2/3] hwmon: pmbus: Add support for Silergy SQ24860
Date: Thu, 11 Jun 2026 07:54:32 +0000 [thread overview]
Message-ID: <20260611075433.325CB1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260611074335.4415-3-zmzhu0630@163.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing signedness check on PMBus limits causes negative inputs to silently set maximum hardware limits.
- [Medium] Returns -EINVAL instead of clamping for out-of-bounds lower limits in PMBUS_IIN_OC_FAULT_LIMIT.
--
commit 1edf6322da1b629fce9b16a96496a18863aacef8
Author: Ziming Zhu <ziming.zhu@silergycorp.com>
hwmon: pmbus: Add support for Silergy SQ24860
Add PMBus hwmon support for the Silergy SQ24860 eFuse. The driver reports
voltage, current, power, and temperature, along with history attributes
and over-current fault limits.
> diff --git a/drivers/hwmon/pmbus/sq24860.c b/drivers/hwmon/pmbus/sq24860.c
> new file mode 100644
> index 0000000000000..f16f650ff7ba2
> --- /dev/null
> +++ b/drivers/hwmon/pmbus/sq24860.c
[ ... ]
> +static int sq24860_write_word_data(struct i2c_client *client,
> + int page, int reg, u16 value)
> +{
> + int ret;
> +
> + switch (reg) {
> + case PMBUS_VIN_UV_WARN_LIMIT:
> + case PMBUS_VIN_UV_FAULT_LIMIT:
> + case PMBUS_VIN_OV_WARN_LIMIT:
> + case PMBUS_VIN_OV_FAULT_LIMIT:
> + case PMBUS_VOUT_UV_WARN_LIMIT:
> + case PMBUS_IIN_OC_WARN_LIMIT:
> + case PMBUS_OT_WARN_LIMIT:
> + case PMBUS_OT_FAULT_LIMIT:
> + case PMBUS_PIN_OP_WARN_LIMIT:
> + value >>= SQ24860_8B_SHIFT;
> + value = clamp_val(value, 0, 0xff);
[Severity: High]
Does this handle negative user inputs correctly?
The PMBus core converts limit values into 16-bit 2's complement integers
(s16), but passes them as u16 to sq24860_write_word_data(). Because this
driver treats value as an unsigned u16, a negative user limit written via
sysfs will become a large positive value (e.g., 0xFFFF).
When this large value is logically right-shifted and clamped here, it
results in setting the maximum possible hardware limit (0xff) instead of
clamping to the minimum limit (0).
> + ret = pmbus_write_word_data(client, page, reg, value);
> + break;
> +
> + case PMBUS_IIN_OC_FAULT_LIMIT:
> + if (value < SQ24860_IIN_OCF_OFF)
> + return -EINVAL;
[Severity: High]
Could a negative user limit bypass this bounds check?
Since value is unsigned, a negative limit (e.g., 0xFFFF) will evaluate
as greater than SQ24860_IIN_OCF_OFF (165). This bypasses the check below
and overflows the 32-bit unsigned calculation, effectively disabling
over-current protection by incorrectly setting the hardware limit to its
maximum.
[Severity: Medium]
Should this clamp the value instead of returning an error?
The hwmon sysfs ABI convention requires drivers to silently clamp
out-of-range user limits to the nearest supported hardware value rather
than returning an error.
If the requested limit translates to a value below SQ24860_IIN_OCF_OFF,
returning -EINVAL violates this convention. Would it be better to clamp
the limit to SQ24860_IIN_OCF_OFF so the underlying register is set to 0?
> + value -= SQ24860_IIN_OCF_OFF;
> + value = DIV_ROUND_CLOSEST(((unsigned int)value) * SQ24860_IIN_OCF_DIV,
> + SQ24860_IIN_OCF_NUM);
> + value = clamp_val(value, 0, 0x3f);
> + ret = pmbus_write_byte_data(client, page, SQ24860_VIREF, value);
> + break;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260611074335.4415-1-zmzhu0630@163.com?part=2
next prev parent reply other threads:[~2026-06-11 7:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 7:43 [PATCH v3 0/3] Add Silergy SQ24860 support Ziming Zhu
2026-06-11 7:43 ` [PATCH v3 1/3] dt-bindings: hwmon: pmbus: Add bindings for Silergy SQ24860 Ziming Zhu
2026-06-11 7:55 ` sashiko-bot
2026-06-11 7:43 ` [PATCH v3 2/3] hwmon: pmbus: Add support " Ziming Zhu
2026-06-11 7:54 ` sashiko-bot [this message]
2026-06-11 7:43 ` [PATCH v3 3/3] hwmon: Add documentation for SQ24860 Ziming Zhu
2026-06-11 7:50 ` 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=20260611075433.325CB1F00893@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=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zmzhu0630@163.com \
/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