Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Rupesh Majhi <zoone.rupert@gmail.com>
Cc: "Andy Shevchenko" <andy@kernel.org>,
	"Bill Wendling" <morbo@google.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Eddie James" <eajames@linux.ibm.com>,
	"Joel Stanley" <joel@jms.id.au>,
	"Justin Stitt" <justinstitt@google.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH v8 07/10] iio: pressure: dps310: read buffered samples from the hardware FIFO
Date: Sun, 27 Sep 2026 20:29:06 +0100	[thread overview]
Message-ID: <20260927202906.12a695be@jic23-hlaptop> (raw)
In-Reply-To: <20260921183132.233136-8-zoone.rupert@gmail.com>

On Mon, 21 Sep 2026 21:31:29 +0300
Rupesh Majhi <zoone.rupert@gmail.com> wrote:

> The DPS310 has a 32-entry FIFO shared by both measurements. Drain it from
> a work item and push what it held, so a buffered capture needs no
> trigger. Nothing in tree wires the interrupt pin, so the work rearms
> itself at half the time the FIFO takes to fill.
> 
> Entries carry one measurement each, so a pressure entry is compensated
> with the temperature ahead of it. Pressure read before the first
> temperature of a session is held until one arrives rather than dropped,
> so the first push can wait a temperature period.
> 
> FIFO entries are not timestamped, so postenable refuses the timestamp
> channel unless a trigger is attached.
> 
> Tested on a DPS310 on a BeagleBone Black.
> 
> Assisted-by: LLM
> Signed-off-by: Rupesh Majhi <zoone.rupert@gmail.com>
Take a look at what Sashiko had for this patch.
It raises the question on whether we can ever have a value that
is out of range in the fifo and as such fail to flush it out.

https://sashiko.dev/#/patchset/20260921183132.233136-1-zoone.rupert%40gmail.com

It also correctly raises that guard() and gotos should never be mixed in a
function.  See the comments in cleanup.h on this.


> ---
>  drivers/iio/pressure/dps310.c | 364 +++++++++++++++++++++++++++++++++-
>  1 file changed, 354 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
> index 85df58ac1809..ba59413d8e11 100644
> --- a/drivers/iio/pressure/dps310.c
> +++ b/drivers/iio/pressure/dps310.c


> +
> +static int dps310_buffer_postenable(struct iio_dev *iio)
> +{
> +	struct dps310_data *data = iio_priv(iio);
> +	int rc, prs_rate, tmp_rate;
> +
> +	/* An attached trigger drives the capture instead, FIFO stays off */
> +	if (iio_device_get_current_mode(iio) == INDIO_BUFFER_TRIGGERED)
> +		return 0;
> +
> +	/* Entries are not timestamped and the drain timer is no substitute */
> +	if (iio_scan_timestamp_enabled(iio))
> +		return -EINVAL;
> +
> +	guard(mutex)(&data->lock);

Sashiko spotted this one.  The rules are no combining this
with a goto in the same function.  In this particular case I think it
isn't a bug as such, but it is fragile code.

Here I think best option is to do the mutex_lock()/unlock() by
hand.


> +
> +	rc = dps310_get_pres_samp_freq(data, &prs_rate);
> +	if (rc)
> +		return rc;
> +
> +	rc = dps310_get_temp_samp_freq(data, &tmp_rate);
> +	if (rc)
> +		return rc;
> +
> +	data->drain_interval_ms = dps310_fifo_interval(prs_rate, tmp_rate);
> +
> +	rc = dps310_fifo_hold_alloc(data, prs_rate, tmp_rate);
> +	if (rc)
> +		return rc;
> +
> +	/* Drop whatever accumulated before enable */
> +	rc = dps310_fifo_hw_flush(data);
> +	if (rc)
> +		goto err_hold;
> +
> +	rc = dps310_fifo_set_enable(data, true);
> +	if (rc)
> +		goto err_hold;
> +
> +	schedule_delayed_work(&data->fifo_work,
> +			      msecs_to_jiffies(data->drain_interval_ms));
> +
> +	return 0;
> +
> +err_hold:
> +	kfree(data->fifo_hold);
> +
> +	return rc;
> +}


  reply	other threads:[~2026-09-27 19:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 18:31 [PATCH v8 00/10] iio: pressure: dps310: FIFO and triggered buffer support Rupesh Majhi
2026-09-21 18:31 ` [PATCH v8 01/10] iio: pressure: dps310: fix CFG_REG bit definitions Rupesh Majhi
2026-09-27 19:17   ` Jonathan Cameron
2026-09-21 18:31 ` [PATCH v8 02/10] iio: pressure: dps310: use a local device pointer in probe Rupesh Majhi
2026-09-27 19:17   ` Jonathan Cameron
2026-09-21 18:31 ` [PATCH v8 03/10] iio: pressure: dps310: use get_unaligned_be24() for the 24-bit results Rupesh Majhi
2026-09-27 19:18   ` Jonathan Cameron
2026-09-21 18:31 ` [PATCH v8 04/10] iio: pressure: dps310: take the lock once per raw read Rupesh Majhi
2026-09-27 19:19   ` Jonathan Cameron
2026-09-21 18:31 ` [PATCH v8 05/10] iio: pressure: dps310: add triggered buffer support Rupesh Majhi
2026-09-27 19:21   ` Jonathan Cameron
2026-09-21 18:31 ` [PATCH v8 06/10] iio: core: add an accessor for scan_timestamp Rupesh Majhi
2026-09-27 19:22   ` Jonathan Cameron
2026-09-21 18:31 ` [PATCH v8 07/10] iio: pressure: dps310: read buffered samples from the hardware FIFO Rupesh Majhi
2026-09-27 19:29   ` Jonathan Cameron [this message]
2026-09-21 18:31 ` [PATCH v8 08/10] iio: pressure: dps310: derive the drain interval from the watermark Rupesh Majhi
2026-09-21 18:31 ` [PATCH v8 09/10] iio: pressure: dps310: implement .hwfifo_flush_to_buffer() Rupesh Majhi
2026-09-21 18:31 ` [PATCH v8 10/10] iio: pressure: dps310: check the lock markings with context analysis Rupesh Majhi

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=20260927202906.12a695be@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=eajames@linux.ibm.com \
    --cc=joel@jms.id.au \
    --cc=justinstitt@google.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nuno.sa@analog.com \
    --cc=zoone.rupert@gmail.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