Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stoyan Bogdanov" <sbogdanov@baylibre.com>
Cc: conor+dt@kernel.org, linux-hwmon@vger.kernel.org,
	robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 1/4] hwmon: (pmbus) Add and export direct conversion calculation helpers
Date: Fri, 22 May 2026 08:38:48 +0000	[thread overview]
Message-ID: <20260522083849.3C5FA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260522082349.2749970-2-sbogdanov@baylibre.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Unchecked arithmetic operations in the exported helpers can silently overflow, violating the hardware monitoring subsystem guidelines.
--

commit 4b7c4efa13e04ccc1fad0afa9ecc064091eda152
Author: Stoyan Bogdanov <sbogdanov@baylibre.com>

hwmon: (pmbus) Add and export direct conversion calculation helpers

This commit splits the math-only parts of pmbus_reg2data_direct() and
pmbus_data2reg_direct() into separate helper functions. It exports these
helpers so they can be reused by upcoming drivers.

> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index e8fdd799c71c0..2eaac337eeaba 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c

[ ... ]

> @@ -1057,6 +1063,23 @@ static u16 pmbus_data2reg_linear(struct pmbus_data *data,
>  	return (mantissa & 0x7ff) | ((exponent << 11) & 0xf800);
>  }
>  
> +u16 pmbus_data2reg_direct_calc(s64 val, s64 b, s32 m, s32 R)
> +{
> +	val = val * m + b;

[Severity: High]
This is a pre-existing issue, but does this calculation need overflow checks
to conform with the hardware monitoring subsystem guidelines?

Since sysfs handlers can parse arbitrary 64-bit values from user space without
prior bounds checking, writing a very large positive value could overflow s64
during multiplication.

If an overflow wraps the value to a negative number, it would bypass the
intended clamping logic later in this function and result in writing S16_MIN
instead of S16_MAX to the hardware limit register.

For power management controllers, this unintended minimum limit could
immediately trip hardware protection and shut down the system.

> +
> +	while (R > 0) {
> +		val *= 10;
> +		R--;
> +	}
> +	while (R < 0) {
> +		val = div_s64(val + 5LL, 10L);  /* round closest */
> +		R++;
> +	}
> +
> +	return (u16)clamp_val(val, S16_MIN, S16_MAX);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260522082349.2749970-1-sbogdanov@baylibre.com?part=1

  reply	other threads:[~2026-05-22  8:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-22  8:23 [PATCH v4 0/4] Rework TPS25990 direct conversions and add TPS1689 support Stoyan Bogdanov
2026-05-22  8:23 ` [PATCH v4 1/4] hwmon: (pmbus) Add and export direct conversion calculation helpers Stoyan Bogdanov
2026-05-22  8:38   ` sashiko-bot [this message]
2026-05-22  8:23 ` [PATCH v4 2/4] hwmon: (pmbus/tps25990): Rework TPS25990 direct conversion handling Stoyan Bogdanov
2026-05-22  9:12   ` sashiko-bot
2026-05-22  8:23 ` [PATCH v4 3/4] dt-bindings: hwmon: pmbus/tps25990: Add TPS1689 Stoyan Bogdanov
2026-05-22  9:24   ` sashiko-bot
2026-05-22  8:23 ` [PATCH v4 4/4] hwmon: (pmbus/tps25990): Add TPS1689 support Stoyan Bogdanov
2026-05-22  9:45   ` 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=20260522083849.3C5FA1F000E9@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=sbogdanov@baylibre.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