[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20220328174944.2c8d3460@jic23-huawei>
Date: Mon, 28 Mar 2022 17:49:44 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: Andy Shevchenko <andy.shevchenko@...il.com>
Cc: Stephen Boyd <swboyd@...omium.org>,
Lars-Peter Clausen <lars@...afoo.de>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
linux-iio <linux-iio@...r.kernel.org>,
Gwendal Grignou <gwendal@...omium.org>
Subject: Re: [PATCH] iio:proximity:sx9324: Fix hardware gain read/write
On Mon, 28 Mar 2022 01:16:10 +0300
Andy Shevchenko <andy.shevchenko@...il.com> wrote:
> On Sat, Mar 19, 2022 at 5:58 AM Stephen Boyd <swboyd@...omium.org> wrote:
> >
> > There are four possible gain values according to sx9324_gain_vals[]: 1,
> > 2, 4, and 8. When writing and reading the register the values are off by
> > one. The bits should be set according to this equation:
> >
> > ilog2(<gain>) + 1
> >
> > so that a gain of 8 is 0x3 in the register field and a gain of 4 is 0x2
> > in the register field, etc. Fix up the functions.
>
> ...
>
> > + *val = 1 << regval;
>
> I see it's similar in the original code, but this is still problematic
> from C standard point of view, i.e. if regval = 31, the C standard
> calls it UB (Undefined Behaviour).
>
I don't see that as a problem as regval is coming from a FIELD_GET() with a 3 bit mask
so we can't hit the UB case (can only be up to 7 - well 6 because of the --)
Jonathan
Powered by blists - more mailing lists