[PATCH] iio: temperature: mcp9600: Bound thresholds before scaling
From: Zhu Jun
Date: Mon Nov 09 2026 - 05:11:06 EST
From: zhujun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
mcp9600_write_thresh() multiplies the integer part by 1000000 before
clamping to the supported temperature range. The multiplication can
overflow int, so a request such as 3000 degrees can select the lower
threshold instead of the upper threshold.
Clamp the integer part to the hot-junction range before scaling. Keep
the existing final clamp for fractional values and the narrower cold-
junction range.
Fixes: dea750f8015b ("iio: temperature: mcp9600: add threshold events support")
---
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/iio/temperature/mcp9600.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/iio/temperature/mcp9600.c b/drivers/iio/temperature/mcp9600.c
index b0ff0c7b4891..51ae622d41f7 100644
--- a/drivers/iio/temperature/mcp9600.c
+++ b/drivers/iio/temperature/mcp9600.c
@@ -326,6 +326,8 @@ static int mcp9600_write_thresh(struct iio_dev *indio_dev,
i = mcp9600_get_alert_index(chan->channel2, dir);
switch (info) {
case IIO_EV_INFO_VALUE:
+ val = clamp_val(val, MCP9600_MIN_TEMP_HOT_JUNCTION_MICRO / 1000000,
+ MCP9600_MAX_TEMP_HOT_JUNCTION_MICRO / 1000000);
/* Scale value to include decimal part into calculations */
s_val = (val < 0) ? ((val * 1000000) - val2) :
((val * 1000000) + val2);
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0