From: Jonathan Cameron <jic23@kernel.org>
To: Jonathan Santos <Jonathan.Santos@analog.com>
Cc: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<Michael.Hennerich@analog.com>, <lars@metafoo.de>,
<dlechner@baylibre.com>, <nuno.sa@analog.com>, <andy@kernel.org>
Subject: Re: [PATCH 1/3] iio: adc: ad7768-1: fix one-shot mode data acquisition
Date: Sat, 7 Feb 2026 16:48:51 +0000 [thread overview]
Message-ID: <20260207164851.51874c46@jic23-huawei> (raw)
In-Reply-To: <c4af45393ec299d0fbf853fa8ec224f475e5901e.1769889074.git.Jonathan.Santos@analog.com>
On Sat, 31 Jan 2026 22:35:20 -0300
Jonathan Santos <Jonathan.Santos@analog.com> wrote:
> According to the datasheet, one-shot mode requires a SYNC_IN pulse to
> trigger a new sample conversion. In the current implementation, No sync
> pulse was sent after switching to one-shot mode and reinit_completion()
> was called before mode switching, creating a race condition where spurious
> interrupts during mode change could trigger completion prematurely.
>
> Fix by sending a sync pulse after configuring one-shot mode and moving
> reinit_completion() after the pulse to ensure it only waits for the
> actual conversion completion.
That smells like a race...
What stops us taking a long break between ending that sync pulse and
the reinit_completition() such that we have initialized if before the
complete()?
You always have to do it before what ever ultimately makes the complete()
happen. Have you seen an sign of the spurious interrupts or is that
more a conjecture of what might happen?
Jonathan
>
> Fixes: a5f8c7da3dbe ("iio: adc: Add AD7768-1 ADC basic support")
> Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
> ---
> drivers/iio/adc/ad7768-1.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
> index fcd8aea7152e..8d39b71703ae 100644
> --- a/drivers/iio/adc/ad7768-1.c
> +++ b/drivers/iio/adc/ad7768-1.c
> @@ -463,12 +463,17 @@ static int ad7768_scan_direct(struct iio_dev *indio_dev)
> struct ad7768_state *st = iio_priv(indio_dev);
> int readval, ret;
>
> - reinit_completion(&st->completion);
> -
> ret = ad7768_set_mode(st, AD7768_ONE_SHOT);
> if (ret < 0)
> return ret;
>
> + /* One-shot mode requires a SYNC pulse to generate a new sample */
> + ret = ad7768_send_sync_pulse(st);
> + if (ret)
> + return ret;
> +
> + reinit_completion(&st->completion);
> +
> ret = wait_for_completion_timeout(&st->completion,
> msecs_to_jiffies(1000));
> if (!ret)
next prev parent reply other threads:[~2026-02-07 16:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-01 1:35 [PATCH 0/3] iio: adc: ad7768-1: add support for SPI offload Jonathan Santos
2026-02-01 1:35 ` [PATCH 1/3] iio: adc: ad7768-1: fix one-shot mode data acquisition Jonathan Santos
2026-02-07 16:48 ` Jonathan Cameron [this message]
2026-02-09 21:38 ` Jonathan Santos
2026-02-14 14:47 ` Jonathan Cameron
2026-02-01 1:35 ` [PATCH 2/3] iio: adc: ad7768-1: prevent one-shot mode with wideband filter Jonathan Santos
2026-02-04 16:11 ` Nuno Sá
2026-02-02 22:41 ` Jonathan Santos
2026-02-01 1:35 ` [PATCH 3/3] iio: adc: ad7768-1: add support for SPI offload Jonathan Santos
2026-02-04 14:09 ` Andy Shevchenko
2026-02-04 15:38 ` David Lechner
2026-02-05 5:42 ` kernel test robot
2026-02-05 6:03 ` Dan Carpenter
2026-02-05 6:44 ` kernel test robot
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=20260207164851.51874c46@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Santos@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@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
all inboxes | Powered by JetHome®