lkml.org 
[lkml]   [2022]   [Jan]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] drivers:iio:dac make expression evaluation 64-bit
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

\
 
 \ /
  Last update: 2022-01-05 14:40    [W:0.169 / U:0.320 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site