* [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings
@ 2026-11-09 9:33 Zhu Jun
2026-11-09 11:18 ` Charles Keepax
0 siblings, 1 reply; 2+ messages in thread
From: Zhu Jun @ 2026-11-09 9:33 UTC (permalink / raw)
To: ckeepax; +Cc: zhujun, rf, linux, patches, linux-hwmon, linux-kernel
From: zhujun <zhujun2@cmss.chinamobile.com>
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.
drivers/hwmon/lochnagar-hwmon.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/hwmon/lochnagar-hwmon.c b/drivers/hwmon/lochnagar-hwmon.c
index 24a255d4c46b..328589e19917 100644
--- a/drivers/hwmon/lochnagar-hwmon.c
+++ b/drivers/hwmon/lochnagar-hwmon.c
@@ -74,6 +74,8 @@ static long float_to_long(u32 data, u32 precision)
if (fls64(man) + exp > (int)sizeof(long) * 8 - 1)
result = LONG_MAX;
+ else if (exp <= -64)
+ result = 0;
else if (exp < 0)
result = (man + (1ull << (-exp - 1))) >> -exp;
else
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.51.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings
2026-11-09 9:33 [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings Zhu Jun
@ 2026-11-09 11:18 ` Charles Keepax
0 siblings, 0 replies; 2+ messages in thread
From: Charles Keepax @ 2026-11-09 11:18 UTC (permalink / raw)
To: Zhu Jun; +Cc: rf, linux, patches, linux-hwmon, linux-kernel
On Mon, Nov 09, 2026 at 05:33:32PM +0800, Zhu Jun wrote:
> From: zhujun <zhujun2@cmss.chinamobile.com>
>
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-09 11:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 9:33 [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings Zhu Jun
2026-11-09 11:18 ` Charles Keepax
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®