Re: [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings
From: Charles Keepax
Date: Wed Nov 11 2026 - 04:38:35 EST
On Wed, Nov 11, 2026 at 02:49:30PM +0800, Zhu Jun wrote:
> A zero IEEE754 reading gives exp = -150 in float_to_long(). Both shifts
> in the rounding expression then exceed the width of u64. UBSAN reports a
> shift exponent of 149, and the conversion can return a nonzero reading.
>
> Return zero when the required right shift is at least 64 bits. With the
> supported precisions, the scaled mantissa is too small to round up in
> this case.
>
> Fixes: 4cdb56214746 ("hwmon: lochnagar: Add Lochnagar 2 hardware monitoring driver")
> Signed-off-by: Zhu Jun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
Thanks for adding the sign off.
> + else if (exp <= -64)
> + result = 0;
> else if (exp < 0)
> result = (man + (1ull << (-exp - 1))) >> -exp;
But as I missed and Guenter Roeck kindly pointed out there is no
value in this. The shift in the following case will just result
in a value of zero anyway.
Thanks,
Charles