* [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings
@ 2026-11-11 6:49 Zhu Jun
2026-11-11 9:32 ` Charles Keepax
0 siblings, 1 reply; 5+ messages in thread
From: Zhu Jun @ 2026-11-11 6:49 UTC (permalink / raw)
To: ckeepax; +Cc: rf, linux, patches, linux-hwmon, linux-kernel, Zhu Jun
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@cmss.chinamobile.com>
---
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
--
2.51.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings
2026-11-11 6:49 [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings Zhu Jun
@ 2026-11-11 9:32 ` Charles Keepax
0 siblings, 0 replies; 5+ messages in thread
From: Charles Keepax @ 2026-11-11 9:32 UTC (permalink / raw)
To: Zhu Jun; +Cc: rf, linux, patches, linux-hwmon, linux-kernel
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@cmss.chinamobile.com>
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings
2026-11-09 11:18 ` Charles Keepax
@ 2026-11-09 15:11 ` Guenter Roeck
0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2026-11-09 15:11 UTC (permalink / raw)
To: Charles Keepax, Zhu Jun; +Cc: rf, patches, linux-hwmon, linux-kernel
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@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 :-)
>
... 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings
2026-11-09 9:33 Zhu Jun
@ 2026-11-09 11:18 ` Charles Keepax
2026-11-09 15:11 ` Guenter Roeck
0 siblings, 1 reply; 5+ 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] 5+ messages in thread
* [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; 5+ 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] 5+ messages in thread
end of thread, other threads:[~2026-11-11 9:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 6:49 [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings Zhu Jun
2026-11-11 9:32 ` Charles Keepax
-- strict thread matches above, loose matches on Subject: below --
2026-11-09 9:33 Zhu Jun
2026-11-09 11:18 ` Charles Keepax
2026-11-09 15:11 ` Guenter Roeck
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®