From: Guillaume Stols <gstols@baylibre.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Beniamin Bia <beniamin.bia@analog.com>,
Stefan Popa <stefan.popa@analog.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-fbdev@vger.kernel.org, devicetree@vger.kernel.org,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
jstephan@baylibre.com, dlechner@baylibre.com
Subject: Re: [PATCH 8/9] iio: adc: ad7606: fix oversampling gpio array
Date: Mon, 24 Jun 2024 17:08:14 +0200 [thread overview]
Message-ID: <62dadd31-5fd1-45b4-99e8-44ffb367bad5@baylibre.com> (raw)
In-Reply-To: <20240623164542.53a9f2b1@jic23-huawei>
Resend, previous mail was erroneously sent in HTML. I apologize for the
spamming.
On 6/23/24 17:45, Jonathan Cameron wrote:
> On Tue, 18 Jun 2024 14:02:40 +0000
> Guillaume Stols <gstols@baylibre.com> wrote:
>> gpiod_set_array_value was misused here: the implementation relied on the
>> assumption that an unsigned long was required for each gpio, while the
>> function expects a bit array stored in "as much unsigned long as needed
>> for storing one bit per GPIO", i.e it is using a bit field.
>>
>> Fixes: d2a415c86c6b ("iio: adc: ad7606: Add support for AD7606B ADC")
>> Signed-off-by: Guillaume Stols <gstols@baylibre.com>
> Always drag fixes to the start of a series. Probably doesn't matter
> in this case but we want it to be obvious there are no necessary
precursors
> in this series for anyone backporting.
OK will do this change in the next version.
>
> What is the user visible outcome of this bug? Superficially the numbers
> all end up the same I think even though the code is clearly working
> mostly by luck. So might not warrant a fixes tag?
This is leading into some issues I should maybe have better documented
in the commit message.
See below
>
>> ---
>> drivers/iio/adc/ad7606.c | 4 ++--
>> drivers/iio/adc/ad7606_spi.c | 5 +++--
>> 2 files changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
>> index e3426287edf6..502344e019e0 100644
>> --- a/drivers/iio/adc/ad7606.c
>> +++ b/drivers/iio/adc/ad7606.c
>> @@ -235,9 +235,9 @@ static int ad7606_write_os_hw(struct iio_dev
*indio_dev, int val)
>> struct ad7606_state *st = iio_priv(indio_dev);
>> DECLARE_BITMAP(values, 3);
>> - values[0] = val;
>> + values[0] = val & GENMASK(2, 0);
>> - gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc,
>> + gpiod_set_array_value(st->gpio_os->ndescs, st->gpio_os->desc,
>> st->gpio_os->info, values);
ARRAY_SIZE(values) is 1 because DECLARE_BITMAP will declare a dimension
1 unsigned long array (more than enough for 3 bits !).
We want to set 3 bits in gpiod_set_array_value, thus the first parameter
should be 3, not 1.
>> /* AD7616 requires a reset to update value */
>> diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
>> index 263a778bcf25..287a0591533b 100644
>> --- a/drivers/iio/adc/ad7606_spi.c
>> +++ b/drivers/iio/adc/ad7606_spi.c
>> @@ -249,8 +249,9 @@ static int ad7616_sw_mode_config(struct iio_dev
*indio_dev)
>> static int ad7606B_sw_mode_config(struct iio_dev *indio_dev)
>> {
>> struct ad7606_state *st = iio_priv(indio_dev);
>> - unsigned long os[3] = {1};
>> + DECLARE_BITMAP(os, 3);
>> + bitmap_fill(os, 3);
Here we need 3 bits set HIGH in one unsigned long (i.e 0x07) and we get
3 times 0x01 instead.
Thus, it will not switch to software mode if OS pins are not hardwired
(which is I must admit, rather unlikely).
>> /*
>> * Software mode is enabled when all three oversampling
>> * pins are set to high. If oversampling gpios are defined
>> @@ -258,7 +259,7 @@ static int ad7606B_sw_mode_config(struct iio_dev
*indio_dev)
>> * otherwise, they must be hardwired to VDD
>> */
>> if (st->gpio_os) {
>> - gpiod_set_array_value(ARRAY_SIZE(os),
>> + gpiod_set_array_value(st->gpio_os->ndescs,
>> st->gpio_os->desc, st->gpio_os->info, os);
>> }
>> /* OS of 128 and 256 are available only in software mode */
>>
next prev parent reply other threads:[~2024-06-24 15:08 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-18 14:02 [PATCH 0/9] iio: adc: ad7606: Improvements Guillaume Stols
2024-06-18 14:02 ` [PATCH 1/9] dt-bindings: iio: adc: adi,ad7606: add missing datasheet link Guillaume Stols
2024-06-27 20:30 ` Rob Herring (Arm)
2024-06-18 14:02 ` [PATCH 2/9] dt-bindings: iio: adc: adi,ad7606: comment and sort the compatible names Guillaume Stols
2024-06-27 20:32 ` Rob Herring (Arm)
2024-06-18 14:02 ` [PATCH 3/9] dt-bindings: iio: adc: adi,ad7606: improve descriptions Guillaume Stols
2024-06-23 15:28 ` Jonathan Cameron
2024-06-18 14:02 ` [PATCH 4/9] dt-bindings: iio: adc: adi,ad7606: add supply properties Guillaume Stols
2024-06-18 15:12 ` Conor Dooley
2024-06-18 15:33 ` Guillaume Stols
2024-06-18 17:32 ` Conor Dooley
2024-06-23 15:31 ` Jonathan Cameron
2024-06-18 14:02 ` [PATCH 5/9] dt-bindings: iio: adc: adi,ad7606: add conditions Guillaume Stols
2024-06-18 15:13 ` Conor Dooley
2024-06-18 15:53 ` Rob Herring (Arm)
2024-06-23 15:33 ` Jonathan Cameron
2024-06-18 14:02 ` [PATCH 6/9] dt-bindings: iio: adc: adi,ad7606: fix example Guillaume Stols
2024-06-18 15:10 ` Conor Dooley
2024-06-23 15:35 ` Jonathan Cameron
2024-06-18 14:02 ` [PATCH 7/9] iio: adc: ad7606: switch mutexes to scoped_guard Guillaume Stols
2024-06-19 3:15 ` kernel test robot
2024-06-23 15:41 ` Jonathan Cameron
2024-06-18 14:02 ` [PATCH 8/9] iio: adc: ad7606: fix oversampling gpio array Guillaume Stols
2024-06-23 15:45 ` Jonathan Cameron
2024-06-24 15:08 ` Guillaume Stols [this message]
2024-06-18 14:02 ` [PATCH 9/9] iio: adc: ad7606: fix standby gpio state to match the documentation Guillaume Stols
2024-06-23 15:49 ` Jonathan Cameron
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=62dadd31-5fd1-45b4-99e8-44ffb367bad5@baylibre.com \
--to=gstols@baylibre.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=Michael.Hennerich@analog.com \
--cc=beniamin.bia@analog.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=jstephan@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=stefan.popa@analog.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