RE: [PATCH 2/6] iio: adc: versal-sysmon: validate temperature hysteresis
From: Mahapatra, Amit Kumar
Date: Fri Nov 06 2026 - 06:42:35 EST
AMD General
Hello Andy,
> -----Original Message-----
> From: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
> Sent: Tuesday, November 3, 2026 3:39 PM
> To: Mahapatra, Amit Kumar <amit.kumar-mahapatra@xxxxxxx>
> Cc: Jonathan Cameron <jic23@xxxxxxxxxx>; Simek, Michal
> <michal.simek@xxxxxxx>; Potthuri, Sai Krishna <sai.krishna.potthuri@xxxxxxx>;
> David Lechner <dlechner@xxxxxxxxxxxx>; Nuno Sá <nuno.sa@xxxxxxxxxx>; Andy
> Shevchenko <andy@xxxxxxxxxx>; Rob Herring <robh@xxxxxxxxxx>; Krzysztof
> Kozlowski <krzk+dt@xxxxxxxxxx>; Conor Dooley <conor+dt@xxxxxxxxxx>; linux-
> iio@xxxxxxxxxxxxxxx; devicetree@xxxxxxxxxxxxxxx; linux-arm-
> kernel@xxxxxxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx;
> amitrkcian2002@xxxxxxxxx
> Subject: Re: [PATCH 2/6] iio: adc: versal-sysmon: validate temperature hysteresis
>
> 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.
I went with max() because an inverted pair (lower above upper) doesn't
really describe a hysteresis, so treating it as zero seemed the safest
reading. With abs_diff(), an inverted 80/90 pair would be read as
10 degrees, and the next threshold write would then set the lower
threshold to 70.
That said, I don't have a strong preference. If you'd rather see abs_diff()
here, I'm happy to switch to it in v2.
Regards,
Amit
>
> --
> With Best Regards,
> Andy Shevchenko
>