[PATCH] hwmon: (w83793) Prevent underflow when removing voltage offsets

From: Zhu Jun

Date: Mon Nov 09 2026 - 04:50:32 EST


From: zhujun <zhujun2@xxxxxxxxxxxxxxxxxxxx>

The 5VDD and 5VSB limit conversion subtracts the voltage offset from an
unsigned value. A requested limit below the offset wraps and is clamped
to 255. For example, writing zero to in7_min selects the highest limit
instead of the lowest.

Limit the subtraction to the converted input so that values below the
offset select register zero.

Fixes: ddca933bd554 ("hwmon/w83793: Remove the description of AMDSI and update the voltage formula")
---
Validation: x86-64 and i386 driver objects built with W=1.
Source-extracted boundary tests passed on 32-bit and 64-bit;
the corresponding test fails on the base revision. I/O is mocked.
No physical sensor hardware or booted-kernel test was available.
OpenAI Codex assisted analysis, code, tests and changelog drafting.
The human submitter must review and add their Signed-off-by.

drivers/hwmon/w83793.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index e1f2708b5db6..b1d390904fe4 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -991,7 +991,7 @@ store_in(struct device *dev, struct device_attribute *attr,
if (index > 2) {
/* fix the limit values of 5VDD and 5VSB to ALARM mechanism */
if (nr == 1 || nr == 2)
- val -= scale_in_add[index] / scale_in[index];
+ val -= min_t(unsigned long, val, scale_in_add[index] / scale_in[index]);
val = clamp_val(val, 0, 255);
} else {
val = clamp_val(val, 0, 0x3FF);

base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0