From: sashiko-bot@kernel.org
To: "Sebastián Peyrott" <speyrott@gmail.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH] hwmon: (minisforum-um780xtx) Fix clamp() build failure with GCC 11
Date: Wed, 14 Oct 2026 21:53:36 +0000 [thread overview]
Message-ID: <sashiko-outbox-171941@kernel.org> (raw)
In-Reply-To: <20261014214522.243253-1-speyrott@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] hwmon: minisforum-um780xtx: integer overflow in DIV_ROUND_CLOSEST
--
commit 37b4941cfec26b0afeccdcd44aef6f32fe1e9d55
Author: Sebastián Peyrott <speyrott@gmail.com>
hwmon: (minisforum-um780xtx) Fix clamp() build failure with GCC 11
This patch fixes a GCC 11 build failure by selecting clamping limits early
and using a single clamp_val() execution. This prevents GCC jump threading
from duplicating the limit check and firing an unreachable compile-time
assertion.
Closes: https://lore.kernel.org/r/fda0e59f-20e1-4a94-a714-288940dcdd37@paulmck-laptop
> diff --git a/drivers/hwmon/minisforum-um780xtx.c b/drivers/hwmon/minisforum-um780xtx.c
> index f5d6e18cb651f..962ebf41ffb7f 100644
> --- a/drivers/hwmon/minisforum-um780xtx.c
> +++ b/drivers/hwmon/minisforum-um780xtx.c
[ ... ]
> @@ -198,13 +198,15 @@ static ssize_t um780xtx_sys_point_temp_store(struct device *dev,
> if (points[0] >= points[1] || points[1] >= data->sys_point3)
> return -EIO;
>
> + if (!sattr->index) {
> + lo = 0;
> + hi = points[1] - 1;
> + } else {
> + lo = points[0] + 1;
> + hi = data->sys_point3 - 1;
> + }
> value = DIV_ROUND_CLOSEST(value, 1000);
> - if (!sattr->index)
> - value = clamp_val(value, 0, points[1] - 1);
> - else
> - value = clamp_val(value, points[0] + 1,
> - data->sys_point3 - 1);
> - points[sattr->index] = value;
> + points[sattr->index] = clamp_val(value, lo, hi);
[Severity: Low]
Can this arithmetic result in an integer overflow for extreme inputs?
When a user writes an extremely large value like LONG_MAX to the sysfs file
in um780xtx_sys_point_temp_store(), the unbounded value is passed directly
to DIV_ROUND_CLOSEST(value, 1000) before it is clamped.
Because DIV_ROUND_CLOSEST adds half the divisor before dividing, an extreme
positive input can overflow and wrap around to a negative number. This would
cause the value to incorrectly clamp to the minimum bound (lo) instead of
the maximum bound (hi). Conversely, an extreme negative input could underflow
and improperly clamp to hi.
Would it be safer to pre-clamp the value before calling DIV_ROUND_CLOSEST
to prevent this overflow? Many other hwmon drivers clamp the input bounds
first prior to performing the division to avoid this behavior.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261014214522.243253-1-speyrott@gmail.com?part=1
next prev parent reply other threads:[~2026-10-14 21:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 20:10 [BUG] clamp() low limit 0 greater than high limit points[1] - 1 Paul E. McKenney
2026-10-14 21:45 ` [PATCH] hwmon: (minisforum-um780xtx) Fix clamp() build failure with GCC 11 Sebastián Peyrott
2026-10-14 21:53 ` sashiko-bot [this message]
2026-10-14 23:03 ` Paul E. McKenney
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=sashiko-outbox-171941@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=speyrott@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.