Re: [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings

From: Guenter Roeck

Date: Wed Nov 11 2026 - 17:42:40 EST


On 11/11/26 01:32, Charles Keepax wrote:
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.

I am not going to apply any patches from this individual. First,
they don't listen - see above. Second, they don't find it necessary
to have enough courtesy to follow patch submission rules such as
versioning patches and providing change logs.

Given that the patches at best fix minor issues, and at worst
may be misleading and/or unnecessary, this is not worth my time.

Guenter