Re: [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings
From: Charles Keepax
Date: Mon Nov 09 2026 - 06:19:06 EST
On Mon, Nov 09, 2026 at 05:33:32PM +0800, Zhu Jun wrote:
> From: zhujun <zhujun2@xxxxxxxxxxxxxxxxxxxx>
>
> 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")
> ---
> Validation: x86-64 and i386 driver objects built with W=1.
> Source-extracted boundary tests passed on 32-bit and 64-bit;
> the corresponding test fails on the base revision. I/O is mocked.
> No physical sensor hardware or booted-kernel test was available.
> OpenAI Codex assisted analysis, code, tests and changelog drafting.
> The human submitter must review and add their Signed-off-by.
Yeah afraid the human submitter will need to add their
Signed-off-by :-)
Otherwise the patch looks good I think.
Thanks,
Charles