lkml.org 
[lkml]   [2021]   [Dec]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v11 09/15] iio: afe: rescale: reduce risk of integer overflow
On Wed, Dec 22, 2021 at 8:38 PM Liam Beguin <liambeguin@gmail.com> wrote:
> On Wed, Dec 22, 2021 at 02:29:04PM +0200, Andy Shevchenko wrote:
> > On Wed, Dec 22, 2021 at 5:47 AM Liam Beguin <liambeguin@gmail.com> wrote:

...

> > > - tmp = 1 << *val2;
> >
> > At some point this should be BIT()

Forgot to add, If it's 64-bit, then BIT_ULL().

> I'm not against changing this, but (to me at least) 1 << *val2 seems
> more explicit as we're not working with bitfields. No?

You may add a comment. You may use int_pow(), but it will be suboptimal.

> > Rule of thumb (in accordance with C standard), always use unsigned
> > value as left operand of the _left_ shift.
>
> Right, that makes sense! In practice though, since we'll most likely
> never use higher bits of *val2 with IIO_VAL_FRACTIONAL_LOG2, would it be
> enough to simply typecast?
>
> tmp = 1 << (unsigned int)*val2;

No, it's about the _left_ operand.
I haven't checked if tmp is 64-bit, then even that would be still wrong.

--
With Best Regards,
Andy Shevchenko

\
 
 \ /
  Last update: 2021-12-22 19:59    [W:0.048 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site