From: sashiko-bot@kernel.org
To: "Ziming Zhu" <zmzhu0630@163.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org,
linux-hwmon@vger.kernel.org
Subject: Re: [PATCH 2/3] hwmon: pmbus: Add support for Silergy SQ24860
Date: Fri, 05 Jun 2026 02:16:02 +0000 [thread overview]
Message-ID: <20260605021603.2B3381F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260605020450.89638-3-zmzhu0630@163.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Missing validation for the `silergy,rimon-micro-ohms` device tree property allows a division by zero kernel panic and integer truncation.
- [High] Unchecked subtraction in the `PMBUS_IIN_OC_FAULT_LIMIT` calculation leads to an integer underflow that defeats hardware over-current protection.
- [Low] Using a `GENMASK` macro as the exponent for a bitwise shift operation is conceptually incorrect and brittle.
- [Low] A comment regarding `PSC_CURRENT_IN` and `PSC_POWER` scaling parameters describes software scaling logic that does not exist in the code.
--
commit 837bf8e7761b5fce46f4967982468008be6c4700
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
input voltage, output voltage, auxiliary voltage, input current, input
power, and temperature.
> diff --git a/drivers/hwmon/pmbus/sq24860.c b/drivers/hwmon/pmbus/sq24860.c
> new file mode 100644
> index 0000000000000..1c3b2bf2a026f
> --- /dev/null
> +++ b/drivers/hwmon/pmbus/sq24860.c
[ ... ]
> +static int sq24860_write_iin_cal_gain(struct i2c_client *client, u32 rimon, u32 gimon)
> +{
> + u64 temp = (u64)6400 * 1000000000 * 1000;
> + u16 word = temp / ((u64)rimon * gimon);
[Severity: High]
If the silergy,rimon-micro-ohms property is read as 0 from the device tree
during sq24860_probe(), will this division by zero cause a kernel panic
during boot?
Additionally, if a user provides a very small value (e.g., < 5394 micro-ohms),
the quotient will exceed U16_MAX. Since the result is directly assigned to
a u16, could this cause silent truncation and result in garbage calibration
values being written to the hardware?
> + int ret = i2c_smbus_write_word_data(client, SQ24860_IIN_CAL_GAIN,
> + word);
> + return ret;
> +}
[ ... ]
> +static int sq24860_write_word_data(struct i2c_client *client,
> + int page, int reg, u16 value)
> +{
> + int ret;
> +
> + switch (reg) {
[ ... ]
> + case PMBUS_IIN_OC_FAULT_LIMIT:
> + value -= SQ24860_IIN_OCF_OFF;
[Severity: High]
Does this unchecked subtraction risk an integer underflow if a user
requests a limit smaller than SQ24860_IIN_OCF_OFF (165)?
If value -= 165 underflows and wraps around to a large number, the
subsequent clamp_val() would hit its upper bound of 63. Could this
cause a safely low requested limit to configure the hardware's maximum
possible over-current limit, bypassing the safety threshold?
> + 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;
> +
> + case PMBUS_VIRT_SAMPLES:
> + value = clamp_val(value, 1, 1 << PK_MIN_AVG_AVG_CNT);
[Severity: Low]
Is it safe to use PK_MIN_AVG_AVG_CNT as a shift exponent here?
Since PK_MIN_AVG_AVG_CNT is defined as GENMASK(2, 0), it evaluates
to 7. While 1 << 7 coincidentally produces the correct limit of 128
samples, using a bitmask macro as a shift exponent is brittle. If the field
were to shift (for example, GENMASK(3, 1) evaluating to 14), would this logic
break catastrophically while still passing compilation?
> + value = ilog2(value);
> + ret = pmbus_update_byte_data(client, page, SQ24860_PK_MIN_AVG,
> + PK_MIN_AVG_AVG_CNT,
> + FIELD_PREP(PK_MIN_AVG_AVG_CNT, value));
> + break;
[ ... ]
> +static const struct pmbus_driver_info sq24860_base_info = {
> + .pages = 1,
> + .format[PSC_VOLTAGE_IN] = direct,
[ ... ]
> + .format[PSC_TEMPERATURE] = direct,
> + .m[PSC_TEMPERATURE] = 1,
> + .b[PSC_TEMPERATURE] = 0,
> + .R[PSC_TEMPERATURE] = 0,
> + /*
> + * Current and Power measurement depends on the ohm value
> + * of Rimon. m is multiplied by 1000 below to have an integer
> + * and -3 is added to R to compensate.
> + */
[Severity: Low]
Is this comment accurate for the current implementation?
The driver info struct definitions below merely set .m = 16 and .R = 0,
with no multiplication by 1000 or -3 added to R. Is this an orphaned
copy-paste comment from another PMBus driver?
> + .format[PSC_CURRENT_IN] = direct,
> + .m[PSC_CURRENT_IN] = 16,
> + .b[PSC_CURRENT_IN] = 0,
> + .R[PSC_CURRENT_IN] = 0,
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260605020450.89638-1-zmzhu0630@163.com?part=2
next prev parent reply other threads:[~2026-06-05 2:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 2:04 [PATCH 0/3] *** Add support for Silergy SQ24860 *** Ziming Zhu
2026-06-05 2:04 ` [PATCH 1/3] dt-bindings: hwmon: pmbus: Add bindings for Silergy SQ24860 Ziming Zhu
2026-06-05 2:11 ` sashiko-bot
2026-06-05 2:04 ` [PATCH 2/3] hwmon: pmbus: Add support " Ziming Zhu
2026-06-05 2:16 ` sashiko-bot [this message]
2026-06-05 2:04 ` [PATCH 3/3] hwmon: Add documentation for SQ24860 Ziming Zhu
2026-06-05 2:12 ` sashiko-bot
2026-06-05 4:36 ` Randy Dunlap
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=20260605021603.2B3381F00893@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