Re: [PATCH v2] iio: temperature: mcp9600: Bound thresholds before scaling
From: Andy Shevchenko
Date: Wed Nov 11 2026 - 09:43:58 EST
On Wed, Nov 11, 2026 at 11:05:38AM +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 / (int)MICRO,
Btw, why do we need to use _val() variant of clamp*()?
> + MCP9600_MAX_TEMP_HOT_JUNCTION_MICRO / (int)MICRO);
--
With Best Regards,
Andy Shevchenko