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

From: Guenter Roeck

Date: Mon Nov 09 2026 - 10:13:50 EST


On 11/9/26 03:18, Charles Keepax wrote:
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 :-)


... and remove the AI comment that it needs to be added. Unfortunately
that didn't happen, suggesting that the human submitter didn't even read
those comments, making it questionable if they were actually reviewed.
I can not apply any of the patches due to the missing signature,
making them just noise. Too bad :-(.

In the case of this patch, unless I am missing something, it isn't really
needed because the large shift causes the result to be 0 anyway.

Guenter