From: Jonathan Santos <jonath4nns@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Jonathan Santos <Jonathan.Santos@analog.com>,
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: Mon, 9 Feb 2026 18:38:31 -0300 [thread overview]
Message-ID: <aYpT1zES5la/8TTb@JSANTO12-L01.ad.analog.com> (raw)
In-Reply-To: <20260207164851.51874c46@jic23-huawei>
On 02/07, Jonathan Cameron wrote:
> 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()?
>
Yes, you are right, we have a race here. The inital problem was having
the ad7768_set_mode() before the reinit_completion() because, almost
everytime, a new conversion is done before setting the one-shot mode,
so the complete() happens before the expected trigger (that never
happened because ad7768_send_sync_pulse() was not present).
> 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?
>
Agreed, I can put reinit_completion() before sending the sync pulse to
avoid this situation. But maybe it is better just to remove the one-shot
mode as discussed in the patch 2/3. What do you think?
> 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-09 21:38 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
2026-02-09 21:38 ` Jonathan Santos [this message]
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=aYpT1zES5la/8TTb@JSANTO12-L01.ad.analog.com \
--to=jonath4nns@gmail.com \
--cc=Jonathan.Santos@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--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®