mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: temperature: mcp9600: Bound thresholds before scaling
@ 2026-11-09  9:35 Zhu Jun
  2026-11-09 10:04 ` Joshua Crofts
  0 siblings, 1 reply; 2+ messages in thread
From: Zhu Jun @ 2026-11-09  9:35 UTC (permalink / raw)
  To: jic23; +Cc: zhujun, dlechner, nuno.sa, andy, linux-iio, linux-kernel

From: zhujun <zhujun2@cmss.chinamobile.com>

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-09 10:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09  9:35 [PATCH] iio: temperature: mcp9600: Bound thresholds before scaling Zhu Jun
2026-11-09 10:04 ` Joshua Crofts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®