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

Mahapatra, Amit Kumar amit.kumar-mahapatra at amd.com
Fri Nov 6 03:35:00 PST 2026


AMD General

Hello Andy,

> -----Original Message-----
> From: Andy Shevchenko <andriy.shevchenko at intel.com>
> Sent: Tuesday, November 3, 2026 3:39 PM
> To: Mahapatra, Amit Kumar <amit.kumar-mahapatra at amd.com>
> Cc: Jonathan Cameron <jic23 at kernel.org>; Simek, Michal
> <michal.simek at amd.com>; Potthuri, Sai Krishna <sai.krishna.potthuri at amd.com>;
> David Lechner <dlechner at baylibre.com>; Nuno Sá <nuno.sa at analog.com>; Andy
> Shevchenko <andy at kernel.org>; Rob Herring <robh at kernel.org>; Krzysztof
> Kozlowski <krzk+dt at kernel.org>; Conor Dooley <conor+dt at kernel.org>; linux-
> iio at vger.kernel.org; devicetree at vger.kernel.org; linux-arm-
> kernel at lists.infradead.org; linux-kernel at vger.kernel.org;
> amitrkcian2002 at gmail.com
> 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
>




More information about the linux-arm-kernel mailing list