[PATCH] hwmon: (minisforum-um780xtx) Fix clamp() build failure with GCC 11

From: Sebastián Peyrott

Date: Wed Oct 14 2026 - 17:45:50 EST


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@xxxxxxxxxx>
Closes: https://lore.kernel.org/r/fda0e59f-20e1-4a94-a714-288940dcdd37@paulmck-laptop
Assisted-by: LLM
Signed-off-by: Sebastián Peyrott <speyrott@xxxxxxxxx>
---
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