From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Stephen Boyd <swboyd@chromium.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
linux-iio <linux-iio@vger.kernel.org>,
Gwendal Grignou <gwendal@chromium.org>
Subject: Re: [PATCH] iio:proximity:sx9324: Fix hardware gain read/write
Date: Mon, 28 Mar 2022 17:49:44 +0100 [thread overview]
Message-ID: <20220328174944.2c8d3460@jic23-huawei> (raw)
In-Reply-To: <CAHp75Ve+SiiAM6VkiwPt95w68KEDk46vXR6ZzjOR7ZgaeZ80HA@mail.gmail.com>
On Mon, 28 Mar 2022 01:16:10 +0300
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> On Sat, Mar 19, 2022 at 5:58 AM Stephen Boyd <swboyd@chromium.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
prev parent reply other threads:[~2022-03-28 16:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-18 20:48 [PATCH] iio:proximity:sx9324: Fix hardware gain read/write Stephen Boyd
2022-03-19 15:26 ` Jonathan Cameron
2022-03-21 18:36 ` Stephen Boyd
2022-03-22 20:38 ` Jonathan Cameron
2022-03-22 21:57 ` Stephen Boyd
2022-03-27 15:47 ` Jonathan Cameron
2022-03-27 22:16 ` Andy Shevchenko
2022-03-28 16:49 ` Jonathan Cameron [this message]
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=20220328174944.2c8d3460@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy.shevchenko@gmail.com \
--cc=gwendal@chromium.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=swboyd@chromium.org \
/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