From: "Sebastián Peyrott" <speyrott@gmail.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: "Paul E. McKenney" <paulmck@kernel.org>,
Mark Brown <broonie@kernel.org>,
linux-hwmon@vger.kernel.org, linux-next@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] hwmon: (minisforum-um780xtx) Fix clamp() build failure with GCC 11
Date: Wed, 14 Oct 2026 18:45:22 -0300 [thread overview]
Message-ID: <20261014214522.243253-1-speyrott@gmail.com> (raw)
In-Reply-To: <fda0e59f-20e1-4a94-a714-288940dcdd37@paulmck-laptop>
GCC 11 fails to build the driver:
error: call to '__compiletime_assert_727' declared with attribute error:
clamp() low limit 0 greater than high limit points[1] - 1
The store function returns -EIO unless points[0] < points[1], so
points[1] - 1 cannot be negative when the clamp is reached. GCC 11 jump
threading, however, duplicates the clamp() limit check and does not prune
the copy in which points[1] is zero, so the compile-time check in clamp()
fires on an unreachable path. GCC 8 to 10 and 12 to 16 accept the code.
Select both limits first and use a single clamp_val(). This does not
change behavior.
Fixes: 9d980da93bbc ("hwmon: Add Minisforum UM780 XTX EC monitoring and fan control")
Reported-by: Paul E. McKenney <paulmck@kernel.org>
Closes: https://lore.kernel.org/r/fda0e59f-20e1-4a94-a714-288940dcdd37@paulmck-laptop
Assisted-by: LLM
Signed-off-by: Sebastián Peyrott <speyrott@gmail.com>
---
Reproduced on next-20261014 (x86_64) with GCC 11.5.0, both with
allmodconfig and with defconfig plus this driver; GCC 8.5, 9.5, 10.5,
12.4, 13.4, 14.4, 15.3 and 16.1 build the unmodified driver. With this
change, the driver builds without warnings with W=1 using GCC 11, 13, 14,
15 and 16 (x86_64 allmodconfig) and GCC 16 (i386 allmodconfig). A small
standalone reproducer of the clamp() pattern fails only with GCC 11, and
the patched form builds with GCC 8 through 16.
Tested on the UM780 XTX: the installed driver and this version produce
identical rounding and clamping results for both system fan thresholds,
with every value verified against the EC registers and the original
thresholds restored afterwards. Module load and unload are also clean.
An LLM-based coding assistant helped reproduce and analyse the failure
and prepare this patch. I reviewed the change and the test results.
drivers/hwmon/minisforum-um780xtx.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/hwmon/minisforum-um780xtx.c b/drivers/hwmon/minisforum-um780xtx.c
index f5d6e18cb651..962ebf41ffb7 100644
--- a/drivers/hwmon/minisforum-um780xtx.c
+++ b/drivers/hwmon/minisforum-um780xtx.c
@@ -180,7 +180,7 @@ static ssize_t um780xtx_sys_point_temp_store(struct device *dev,
struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
u8 points[2];
u8 readback;
- long value;
+ long value, lo, hi;
int ret;
ret = kstrtol(buf, 10, &value);
@@ -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);
ret = ec_write(um780xtx_sys_point_offsets[sattr->index],
points[sattr->index]);
base-commit: 4781ca52761e666cf18b591e6bb0478396c90320
--
2.54.0
next prev parent reply other threads:[~2026-10-14 21:45 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 ` Sebastián Peyrott [this message]
2026-10-14 21:53 ` [PATCH] hwmon: (minisforum-um780xtx) Fix clamp() build failure with GCC 11 sashiko-bot
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=20261014214522.243253-1-speyrott@gmail.com \
--to=speyrott@gmail.com \
--cc=broonie@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=paulmck@kernel.org \
/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