public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	Michael Hennerich <Michael.Hennerich@analog.com>,
	Jonathan Cameron <jic23@kernel.org>,
	Mihail Chindris <mihail.chindris@analog.com>,
	"open list:IIO SUBSYSTEM AND DRIVERS" <linux-iio@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	kernel@collabora.com, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] drivers:iio:dac make expression evaluation 64-bit
Date: Wed, 5 Jan 2022 16:39:02 +0300	[thread overview]
Message-ID: <20220105133902.GD7674@kadam> (raw)
In-Reply-To: <YcIpAKV7Cmi0o7PU@debian-BULLSEYE-live-builder-AMD64>

On Wed, Dec 22, 2021 at 12:20:32AM +0500, Muhammad Usama Anjum wrote:
> Two 32-bit values are being evaluated using 32-bit arithmetic and then
> passed to s64 type. It is wrong. Expression should be evaluated using
> 64-bit arithmetic and then passed.
> 
> Fixes: 8f2b54824b ("drivers:iio:dac: Add AD3552R driver support")
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
>  drivers/iio/dac/ad3552r.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/dac/ad3552r.c b/drivers/iio/dac/ad3552r.c
> index 97f13c0b9631..b03d3c7cd4c4 100644
> --- a/drivers/iio/dac/ad3552r.c
> +++ b/drivers/iio/dac/ad3552r.c
> @@ -770,7 +770,7 @@ static void ad3552r_calc_gain_and_offset(struct ad3552r_desc *dac, s32 ch)
>  	dac->ch_data[ch].scale_dec = DIV_ROUND_CLOSEST((s64)rem * 1000000,
>  							65536);
>  
> -	dac->ch_data[ch].offset_int = div_s64_rem(v_min * 65536, span, &rem);
> +	dac->ch_data[ch].offset_int = div_s64_rem(v_min * 65536L, span, &rem);

"v_min" is relatively close to zero on a number line so this can't
overflow.  There is no way that this change affects anything at runtime
(except making the code a tiny tiny bit slower).

And it should be 65536LL for 32 bit systems?

But I just don't see the point of this change.  Presumably it is to make
a static analyzer happy?

regards,
dan carpenter


  parent reply	other threads:[~2022-01-05 13:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-21 19:20 [PATCH] drivers:iio:dac make expression evaluation 64-bit Muhammad Usama Anjum
2021-12-22 18:49 ` Andy Shevchenko
2021-12-23 16:34   ` Muhammad Usama Anjum
2021-12-23 16:38     ` Lars-Peter Clausen
2022-01-04 10:28       ` Chindris, Mihail
2022-01-05 13:39 ` Dan Carpenter [this message]
2022-01-05 15:36   ` Sa, Nuno

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=20220105133902.GD7674@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=jic23@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kernel@collabora.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mihail.chindris@analog.com \
    --cc=usama.anjum@collabora.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