Re: [PATCH] iio: temperature: mcp9600: Bound thresholds before scaling
From: Andy Shevchenko
Date: Mon Nov 09 2026 - 17:48:52 EST
On Mon, Nov 09, 2026 at 05:35:17PM +0800, Zhu Jun wrote:
>
> 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.
...
> + val = clamp_val(val, MCP9600_MIN_TEMP_HOT_JUNCTION_MICRO / 1000000,
> + MCP9600_MAX_TEMP_HOT_JUNCTION_MICRO / 1000000);
Use MICRO from units.h (but be careful about sign.
> /* Scale value to include decimal part into calculations */
> s_val = (val < 0) ? ((val * 1000000) - val2) :
> ((val * 1000000) + val2);
--
With Best Regards,
Andy Shevchenko