Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rodrigo Alencar" <rodrigo.alencar@analog.com>,
	devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 08/10] iio: frequency: ad9910: support iio backend
Date: Thu, 15 Oct 2026 17:04:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-173230@kernel.org> (raw)
In-Reply-To: <20261015-ad9910-backend-support-v1-8-3c21648c8e26@analog.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iio: ad9910: missing error rollback causing state desync and resource leaks
- [Medium] iio: frequency: ad9910: backend channel leak on preenable error
- [Medium] iio: frequency: ad9910: missing backend cleanup on postdisable error
--

commit 7c7244ed8ac1bd865ad6a2d0af50cec74add275e
Author: Rodrigo Alencar <rodrigo.alencar@analog.com>
Subject: iio: frequency: ad9910: support iio backend

This commit adds support for an optional IIO backend to the AD9910 parallel
data port. It handles backend data rate control and synchronizes hardware
states with buffer callbacks.

> diff --git a/drivers/iio/frequency/ad9910.c b/drivers/iio/frequency/ad9910.c
> index 3d517879dee39..39d65dafd5a18 100644
> --- a/drivers/iio/frequency/ad9910.c
> +++ b/drivers/iio/frequency/ad9910.c
[ ... ]
> @@ -568,6 +580,11 @@ static int ad9910_set_sysclk_freq(struct ad9910_state *st, u32 freq_hz,
>  
>  	st->data.sysclk_freq_hz = sysclk_freq_hz;
>  
> +	if (st->back)
> +		return iio_backend_set_sampling_freq(st->back,
> +						     AD9910_CHAN_IDX_PHY,
> +						     sysclk_freq_hz);
> +
>  	return 0;
>  }

[Severity: High]
If iio_backend_set_sampling_freq() fails, are the software cache and SPI
hardware states left desynchronized from the IIO backend?

It appears that st->data.sysclk_freq_hz and potentially the SPI hardware
(via earlier updates in this function) are modified before the backend call.
If the backend rejects the configuration, this returns an error without
rolling back those earlier updates, leaving the driver state inconsistent.

[ ... ]
> @@ -2278,6 +2400,72 @@ static inline void ad9910_debugfs_init(struct ad9910_state *st,
[ ... ]
> +static int ad9910_buffer_preenable(struct iio_dev *indio_dev)
> +{
> +	struct ad9910_state *st = iio_priv(indio_dev);
> +	int ret;
> +
> +	guard(mutex)(&st->lock);
> +
> +	st->scan_mask = *indio_dev->active_scan_mask;
> +	ret = iio_backend_chan_enable(st->back,
> +				      ad9910_buffer_chan_idx(indio_dev));
> +	if (ret)
> +		return ret;
> +
> +	return ad9910_reg32_update(st, AD9910_REG_CFR2,
> +				   AD9910_CFR2_PARALLEL_DATA_PORT_EN_MSK,
> +				   AD9910_CFR2_PARALLEL_DATA_PORT_EN_MSK,
> +				   true);
> +}

[Severity: High]
Does returning early here leak the backend channel if ad9910_reg32_update()
fails?

The function successfully enables the backend channel via
iio_backend_chan_enable(), but if the subsequent SPI write fails, it returns
the error code directly. Because the IIO core handles preenable() failures
by aborting the buffer enablement process without invoking postdisable(),
the backend channel seems to remain permanently enabled.

Should there be an error path here that calls iio_backend_chan_disable()
when the register update fails?

> +
> +static int ad9910_buffer_postdisable(struct iio_dev *indio_dev)
> +{
> +	struct ad9910_state *st = iio_priv(indio_dev);
> +	int ret;
> +
> +	guard(mutex)(&st->lock);
> +
> +	st->scan_mask = 0;
> +	ret = ad9910_reg32_update(st, AD9910_REG_CFR2,
> +				  AD9910_CFR2_PARALLEL_DATA_PORT_EN_MSK,
> +				  0, true);
> +	if (ret)
> +		return ret;
> +
> +	return iio_backend_chan_disable(st->back,
> +					ad9910_buffer_chan_idx(indio_dev));
> +}

[Severity: Medium]
Could this early return skip the required backend cleanup?

If ad9910_reg32_update() fails during this teardown path, it immediately
returns the error code, completely skipping iio_backend_chan_disable().
This could leak the backend channel and leave the backend state desynchronized
from the IIO buffer state.

Would it be better to always attempt iio_backend_chan_disable() on a
best-effort basis, even if the hardware write fails?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261015-ad9910-backend-support-v1-0-3c21648c8e26@analog.com?part=8

  reply	other threads:[~2026-10-15 17:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 16:49 [PATCH 00/10] iio: frequency: ad9910: add IIO backend support Rodrigo Alencar via B4 Relay
2026-10-15 16:49 ` [PATCH 01/10] iio: frequency: ad9910: powerdown fix Rodrigo Alencar via B4 Relay
2026-10-15 16:49 ` [PATCH 02/10] iio: backend: add devm_iio_backend_get_optional() Rodrigo Alencar via B4 Relay
2026-10-15 16:49 ` [PATCH 03/10] dt-bindings: iio: frequency: add adi,ad9910-axi-backend Rodrigo Alencar via B4 Relay
2026-10-15 16:49 ` [PATCH 04/10] dt-bindings: iio: frequency: ad9910: add io-backends property Rodrigo Alencar via B4 Relay
2026-10-15 16:49 ` [PATCH 05/10] iio: frequency: ad9910: move channel indexes into a shared header Rodrigo Alencar via B4 Relay
2026-10-15 16:49 ` [PATCH 06/10] iio: frequency: ad9910: add axi backend driver Rodrigo Alencar via B4 Relay
2026-10-15 16:59   ` sashiko-bot
2026-10-15 16:49 ` [PATCH 07/10] iio: frequency: ad9910: support drctl control Rodrigo Alencar via B4 Relay
2026-10-15 16:58   ` sashiko-bot
2026-10-15 16:49 ` [PATCH 08/10] iio: frequency: ad9910: support iio backend Rodrigo Alencar via B4 Relay
2026-10-15 17:04   ` sashiko-bot [this message]
2026-10-15 16:49 ` [PATCH 09/10] iio: ABI: add integration_time for output channels Rodrigo Alencar via B4 Relay
2026-10-15 16:49 ` [PATCH 10/10] docs: iio: ad9910: document DRCTL pin control Rodrigo Alencar via B4 Relay

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=sashiko-outbox-173230@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=rodrigo.alencar@analog.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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