From: Jonathan Cameron <jic23@kernel.org>
To: "Sabau, Radu bogdan" <Radu.Sabau@analog.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
"Hennerich, Michael" <Michael.Hennerich@analog.com>,
"David Lechner" <dlechner@baylibre.com>,
"Sa, Nuno" <Nuno.Sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Uwe Kleine-König" <ukleinek@kernel.org>,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"Linus Walleij" <linusw@kernel.org>,
"Bartosz Golaszewski" <brgl@kernel.org>,
"Philipp Zabel" <p.zabel@pengutronix.de>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-pwm@vger.kernel.org" <linux-pwm@vger.kernel.org>,
"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>
Subject: Re: [PATCH v9 3/6] iio: adc: ad4691: add triggered buffer support
Date: Thu, 7 May 2026 15:25:32 +0100 [thread overview]
Message-ID: <20260507152532.09b385eb@jic23-huawei> (raw)
In-Reply-To: <LV9PR03MB8414E0FFAD9C9423189117B2F73C2@LV9PR03MB8414.namprd03.prod.outlook.com>
On Thu, 7 May 2026 11:37:25 +0000
"Sabau, Radu bogdan" <Radu.Sabau@analog.com> wrote:
> Addressing Sashiko's review for triggered buffer patch.
>
> > -----Original Message-----
> > From: Radu Sabau via B4 Relay <devnull+radu.sabau.analog.com@kernel.org>
> > Sent: Thursday, April 30, 2026 1:17 PM
>
> ...
>
> > +static int ad4691_manual_buffer_preenable(struct iio_dev *indio_dev)
> > +{
> > + struct ad4691_state *st = iio_priv(indio_dev);
> > + unsigned int prev_i, k, i;
> > + bool first;
> > + int ret;
> > +
> > + memset(st->scan_xfers, 0, sizeof(st->scan_xfers));
> > + memset(st->scan_tx, 0, sizeof(st->scan_tx));
> > +
> > + spi_message_init(&st->scan_msg);
> > +
> > + first = true;
> > + prev_i = 0;
> > + k = 0;
> > + iio_for_each_active_channel(indio_dev, i) {
> > + st->scan_tx[k] = cpu_to_be16(AD4691_ADC_CHAN(i));
> > + st->scan_xfers[k].tx_buf = &st->scan_tx[k];
> > + /*
> > + * The pipeline means xfer[0] receives the residual from the
> > + * previous sequence, not a valid sample for channel i. Point
> > + * it at vals[i] anyway; xfer[1] (or the NOOP when only one
> > + * channel is active) will overwrite that slot with the real
> > + * result, so no separate dummy buffer is needed.
> > + */
> > + if (first) {
> > + st->scan_xfers[k].rx_buf = &st->vals[i];
> > + first = false;
> > + } else {
> > + st->scan_xfers[k].rx_buf = &st->vals[prev_i];
> > + }
>
>
> "The IIO subsystem expects data pushed to the buffer to be densely packed
> according to the active channels in the scan mask.
> If only a subset of channels are enabled, does assigning the rx_buf pointer
> directly to absolute array indices at &st->vals[i] leave holes in the buffer?
> When iio_push_to_buffers_with_ts() is called, this might cause it to read
> uninitialized memory instead of the expected samples."
>
> I would say there is no change needed. Writing to &st->vals[scan_index] and
> passing the full array to iio_push_to_buffers_with_ts() is the standard IIO kfifo
> pattern: the core demultiplexes by reading data[scan_index * storagebits/8]
> for each active channel; holes at inactive indices are silently ignored.
> The same pattern is used in ad4695, ad_sigma_delta, and others. The
> pipeline residual in the first manual-mode transfer is overwritten by the
> subsequent transfer before the scan is pushed, as the comment explains.
This looks wrong to me.
What holes? If available_scan_masks is set we will do a bunch of
demux work - but then this code would see the mask picked from that
list. If it's not then typically we won't (subject to multiple consumers
forcing it - but that still won't close up holes here).
If the active_scan_mask == the one requested, there is no demux at all
and I think that's the case here - the code pushes the data passed in
directly to the kfifo.
Perhaps given an illustration of what the layout of resulting data
is if only even numbered channels are enabled.
>
> > + st->scan_xfers[k].len = sizeof(__be16);
> > + st->scan_xfers[k].cs_change = 1;
> > + spi_message_add_tail(&st->scan_xfers[k], &st->scan_msg);
> > + prev_i = i;
> > + k++;
> > + }
> > +
>
>
> > + st->scan_xfers[2 * k + 1].len = sizeof(__be16);
> > + st->scan_xfers[2 * k + 1].cs_change = 1;
> > + spi_message_add_tail(&st->scan_xfers[2 * k + 1], &st->scan_msg);
> > +
> > + ret = spi_optimize_message(st->spi, &st->scan_msg);
> > + if (ret)
> > + return ret;
> > +
> > + ret = regmap_write(st->regmap, AD4691_STD_SEQ_CONFIG,
> > + bitmap_read(indio_dev->active_scan_mask, 0,
> > + iio_get_masklength(indio_dev)));
> > + if (ret)
> > + goto err_unoptimize;
> > +
> > + ret = regmap_write(st->regmap, AD4691_ACC_MASK_REG,
> > + ~bitmap_read(indio_dev->active_scan_mask, 0,
> > + iio_get_masklength(indio_dev)) &
> > GENMASK(15, 0));
> > + if (ret)
> > + goto err_unoptimize;
> > +
> > + ret = ad4691_enter_conversion_mode(st);
> > + if (ret)
> > + goto err_unoptimize;
> > +
> > + ret = ad4691_sampling_enable(st, true);
> > + if (ret)
> > + goto err_exit_conv;
> > +
> > + enable_irq(st->irq);
> > + return 0;
>
> "Is there a race condition introduced by enabling the PWM and unmasking the
> IRQ here?
> If a hardware interrupt fires before the IIO core attaches the trigger's poll
> function, iio_trigger_poll() drops the event. Will the IRQ handler then call
> disable_irq_nosync() without ever running the consumer thread to re-enable it?"
>
> Valid. preenable is called before the IIO core attaches the trigger
> poll function; if a DATA_READY IRQ fires in that window, iio_trigger_poll()
> is dropped, disable_irq_nosync() disables the IRQ, and enable_irq() is
> never called, leaving the IRQ stuck. Although the delay would need to be
> very great for this to happen, I moved sampling_enable(true) and
> enable_irq() to a new postenable callback which the IIO core calls only
> after the trigger poll function is attached.
Make sure to add a comment on why that is there.
Otherwise makes sense.
>
Rest look fine to me.
next prev parent reply other threads:[~2026-05-07 14:25 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 10:16 [PATCH v9 0/6] iio: adc: ad4691: add driver for AD4691 multichannel SAR ADC family Radu Sabau via B4 Relay
2026-04-30 10:16 ` [PATCH v9 1/6] dt-bindings: iio: adc: add AD4691 family Radu Sabau via B4 Relay
2026-04-30 10:16 ` [PATCH v9 2/6] iio: adc: ad4691: add initial driver for " Radu Sabau via B4 Relay
2026-05-05 13:23 ` Jonathan Cameron
2026-05-07 9:26 ` Sabau, Radu bogdan
2026-05-07 14:15 ` Jonathan Cameron
2026-05-08 4:44 ` Andy Shevchenko
2026-05-08 9:53 ` Andy Shevchenko
2026-04-30 10:16 ` [PATCH v9 3/6] iio: adc: ad4691: add triggered buffer support Radu Sabau via B4 Relay
2026-05-04 7:57 ` Andy Shevchenko
2026-05-04 12:05 ` Sabau, Radu bogdan
2026-05-05 13:26 ` Jonathan Cameron
2026-05-05 14:58 ` Andy Shevchenko
2026-05-05 16:17 ` Jonathan Cameron
2026-05-06 7:25 ` Andy Shevchenko
2026-05-06 9:01 ` Sabau, Radu bogdan
2026-05-05 14:04 ` Jonathan Cameron
2026-05-05 14:07 ` Jonathan Cameron
2026-05-07 11:37 ` Sabau, Radu bogdan
2026-05-07 14:25 ` Jonathan Cameron [this message]
2026-05-08 11:08 ` Sabau, Radu bogdan
2026-04-30 10:16 ` [PATCH v9 4/6] iio: adc: ad4691: add SPI offload support Radu Sabau via B4 Relay
2026-05-04 8:10 ` Andy Shevchenko
2026-05-05 14:12 ` Jonathan Cameron
2026-05-05 14:28 ` Jonathan Cameron
2026-05-06 9:17 ` Sabau, Radu bogdan
2026-05-07 11:49 ` Sabau, Radu bogdan
2026-05-07 15:11 ` Jonathan Cameron
2026-05-08 11:11 ` Sabau, Radu bogdan
2026-04-30 10:16 ` [PATCH v9 5/6] iio: adc: ad4691: add oversampling support Radu Sabau via B4 Relay
2026-05-04 8:14 ` Andy Shevchenko
2026-05-05 14:32 ` Jonathan Cameron
2026-05-07 11:56 ` Sabau, Radu bogdan
2026-05-07 15:26 ` Jonathan Cameron
2026-04-30 10:16 ` [PATCH v9 6/6] docs: iio: adc: ad4691: add driver documentation Radu Sabau via B4 Relay
2026-05-05 14:35 ` 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=20260507152532.09b385eb@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=Nuno.Sa@analog.com \
--cc=Radu.Sabau@analog.com \
--cc=andy@kernel.org \
--cc=brgl@kernel.org \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=lgirdwood@gmail.com \
--cc=linusw@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=ukleinek@kernel.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