mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: Zhu Jun <zhujun2@cmss.chinamobile.com>
Cc: rf@opensource.cirrus.com, linux@roeck-us.net,
	patches@opensource.cirrus.com, linux-hwmon@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hwmon: (lochnagar) Avoid oversized shifts for zero readings
Date: Wed, 11 Nov 2026 09:32:22 +0000	[thread overview]
Message-ID: <avQ2JvdLKIp51/wH@opensource.cirrus.com> (raw)
In-Reply-To: <20261111064930.17408-1-zhujun2@cmss.chinamobile.com>

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

  reply	other threads:[~2026-11-11  9:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  6:49 Zhu Jun
2026-11-11  9:32 ` Charles Keepax [this message]
  -- 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=avQ2JvdLKIp51/wH@opensource.cirrus.com \
    --to=ckeepax@opensource.cirrus.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=patches@opensource.cirrus.com \
    --cc=rf@opensource.cirrus.com \
    --cc=zhujun2@cmss.chinamobile.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®