Re: [PATCH 2/6] iio: adc: versal-sysmon: validate temperature hysteresis

From: Andy Shevchenko

Date: Tue Nov 03 2026 - 05:16:27 EST


On Mon, Nov 02, 2026 at 05:51:08PM +0530, Amit Kumar Mahapatra wrote:
> The hysteresis written through sysfs is only checked for being negative.
> A large value makes upper_mc - hysteresis in sysmon_update_temp_lower()
> overflow before it is clamped. Reject values above the full Q8.7 span of
> 511992 millicelsius, and name the Q8.7 temperature limits so that the
> span and the existing range checks share one definition.
>
> The cached hysteresis is seeded at probe from the threshold registers
> without checking that the lower threshold is not above the upper one.
> Treat that case as zero hysteresis, as negative values are rejected on
> the write path.

...

> sysmon_q8p7_to_millicelsius(upper_reg, &upper_mc);
> sysmon_q8p7_to_millicelsius(lower_reg, &lower_mc);
> - *hysteresis = upper_mc - lower_mc;
> + *hysteresis = max(upper_mc - lower_mc, 0);

But you can use abs_diff() and let it make the problem of the supplier.

--
With Best Regards,
Andy Shevchenko