From: sashiko-bot@kernel.org
To: "Rodrigo Alencar" <rodrigo.alencar@analog.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v9 13/17] iio: frequency: ad9910: add RAM mode support
Date: Wed, 22 Jul 2026 16:44:56 +0000 [thread overview]
Message-ID: <20260722164456.B12EF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260722-ad9910-iio-driver-v9-13-459d1df5ac56@analog.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Failure to rollback hardware shadow registers and software cache on error paths leaves DDS state permanently corrupted when toggling RAM mode.
- [Medium] The `st->ram_fwu_cancel` flag can be permanently leaked if an upload is cancelled concurrently while `ad9910_ram_fwu_prepare()` returns an early error.
- [Medium] The driver prematurely updates its software register cache before the hardware write succeeds during RAM firmware upload cleanup.
--
--- Patch [13]: [PATCH v9 13/17] iio: frequency: ad9910: add RAM mode support ---
commit 3693cd96a1750a5d9f949991dc4f3494e3cfae47
Author: Rodrigo Alencar <rodrigo.alencar@analog.com>
iio: frequency: ad9910: add RAM mode support
This patch adds RAM control channel support to the AD9910 DDS driver. It
includes RAM data loading via the firmware upload interface, per-profile
configuration, and sampling frequency control. When RAM is enabled, the DDS
profile parameters are sourced from a shadow register cache.
> diff --git a/drivers/iio/frequency/ad9910.c b/drivers/iio/frequency/ad9910.c
> index 6c794e1b4b1c8..844cc0cc8f3eb 100644
> --- a/drivers/iio/frequency/ad9910.c
> +++ b/drivers/iio/frequency/ad9910.c
[ ... ]
> @@ -1156,6 +1257,41 @@ static int ad9910_write_raw(struct iio_dev *indio_dev,
> AD9910_CFR2_DRG_DEST_MSK |
> AD9910_CFR2_DRG_ENABLE_MSK,
> tmp32, true);
> + case AD9910_CHANNEL_RAM:
> + if (AD9910_RAM_ENABLED(st) == !!val)
> + return 0;
> +
> + /* swap profile configs */
> + for (i = 0; i < AD9910_NUM_PROFILES; i++) {
> + tmp64 = st->reg[AD9910_REG_PROFILE(i)].val64;
> + ret = ad9910_reg64_write(st,
> + AD9910_REG_PROFILE(i),
> + st->reg_profile[i],
> + false);
> + if (ret)
> + break;
> + st->reg_profile[i] = tmp64;
> + }
> +
> + if (ret) {
> + /*
> + * After the write failure, profiles 0..i-1 were
> + * already swapped in SW, but Hw registers are
> + * still pending an IO update, so swap them back
> + * in SW to keep the state consistent.
> + */
> + while (i--) {
> + tmp64 = st->reg[AD9910_REG_PROFILE(i)].val64;
> + st->reg[AD9910_REG_PROFILE(i)].val64 = st->reg_profile[i];
> + st->reg_profile[i] = tmp64;
> + }
> + return ret;
> + }
[Severity: High]
Does this error path leave the hardware shadow registers out of sync with the
software cache?
If ad9910_reg64_write() fails for a profile during ad9910_write_raw(), the
hardware shadow registers for previous profiles have already been modified,
but this fallback loop only reverts the software cache.
If an IO_UPDATE pulse is subsequently triggered by a different operation,
could it unintentionally apply the partially swapped configurations to the
hardware?
Also, if the profile swaps succeed but the CFR1 register update below fails,
neither the software nor hardware state seems to be rolled back.
> +
> + tmp32 = FIELD_PREP(AD9910_CFR1_RAM_ENABLE_MSK, !!val);
> + return ad9910_reg32_update(st, AD9910_REG_CFR1,
> + AD9910_CFR1_RAM_ENABLE_MSK,
> + tmp32, true);
[ ... ]
> @@ -1436,6 +1607,142 @@ static int ad9910_read_label(struct iio_dev *indio_dev,
> return sysfs_emit(label, "%s\n", ad9910_channel_str[chan->address]);
> }
>
> +static enum fw_upload_err ad9910_ram_fwu_prepare(struct fw_upload *fw_upload,
> + const u8 *data, u32 size)
> +{
> + struct ad9910_state *st = fw_upload->dd_handle;
> + const struct ad9910_ram_fw *fw_data = (const struct ad9910_ram_fw *)data;
> + size_t wcount, bcount;
> +
> + if (size < sizeof(struct ad9910_ram_fw))
> + return FW_UPLOAD_ERR_INVALID_SIZE;
> +
> + if (get_unaligned_be32(&fw_data->magic) != AD9910_RAM_FW_MAGIC)
> + return FW_UPLOAD_ERR_FW_INVALID;
> +
> + if (get_unaligned_be16(&fw_data->version) != AD9910_RAM_FW_V1)
> + return FW_UPLOAD_ERR_FW_INVALID;
> +
> + wcount = get_unaligned_be16(&fw_data->wcount);
> + bcount = size - sizeof(struct ad9910_ram_fw);
> + if (wcount > AD9910_RAM_SIZE_MAX_WORDS ||
> + bcount != (wcount * AD9910_RAM_WORD_SIZE))
> + return FW_UPLOAD_ERR_INVALID_SIZE;
> +
> + bcount += sizeof(fw_data->cfr1) + sizeof(fw_data->profiles);
> + if (crc32(0, &fw_data->cfr1, bcount) != get_unaligned_be32(&fw_data->crc))
> + return FW_UPLOAD_ERR_FW_INVALID;
[Severity: Medium]
If a sysfs cancel operation occurs concurrently with firmware upload and sets
st->ram_fwu_cancel to true, could one of these early validation checks
returning an error permanently leak the cancel flag?
The fw_upload framework does not call cleanup() if prepare() fails. If the
flag is not cleared on these early error paths in ad9910_ram_fwu_prepare(),
could it cause subsequent valid firmware uploads to be spuriously rejected?
> +
> + guard(mutex)(&st->lock);
> + if (st->ram_fwu_cancel) {
> + /* cleanup() is not called when prepare fails */
> + st->ram_fwu_cancel = false;
> + return FW_UPLOAD_ERR_CANCELED;
> + }
> +
> + return FW_UPLOAD_ERR_NONE;
> +}
> +
> +static enum fw_upload_err ad9910_ram_fwu_write(struct fw_upload *fw_upload,
> + const u8 *data, u32 offset,
> + u32 size, u32 *written)
> +{
[ ... ]
> + /* restore active single tone profile regardless */
> + st->reg[AD9910_REG_PROFILE(st->profile)].val64 = backup;
> + ret2 = ad9910_reg64_write(st, AD9910_REG_PROFILE(st->profile), backup, true);
> + if (ret || ret2)
> + return FW_UPLOAD_ERR_RW_ERROR;
[Severity: Medium]
Does this unconditionally desynchronize the software cache if the hardware
write fails during ad9910_ram_fwu_write()?
By pre-assigning the software cache st->reg before checking if
ad9910_reg64_write() succeeds, a failed SPI transfer could leave the
hardware with the RAM upload configuration, while the software cache will
falsely indicate it has been restored to the backup state.
> +
> + *written = size;
> +
> + return FW_UPLOAD_ERR_NONE;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260722-ad9910-iio-driver-v9-0-459d1df5ac56@analog.com?part=13
next prev parent reply other threads:[~2026-07-22 16:44 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 15:50 [PATCH v9 00/17] AD9910 Direct Digital Synthesizer Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 15:50 ` [PATCH v9 01/17] iio: ABI: add attributes for altcurrent channels Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 15:50 ` [PATCH v9 02/17] iio: ABI: raw, scale and offset for frequency/phase channels Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 15:50 ` [PATCH v9 03/17] iio: ABI: add parent entry for iio channels Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 15:50 ` [PATCH v9 04/17] iio: add IIO_FREQUENCY channel type Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 15:50 ` [PATCH v9 05/17] iio: core: support 64-bit register through debugfs Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 15:50 ` [PATCH v9 06/17] iio: core: create local __iio_chan_prefix_emit() for reuse Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 15:50 ` [PATCH v9 07/17] iio: test: add kunit tests for channel prefix naming generation Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 16:13 ` sashiko-bot
2026-07-22 15:50 ` [PATCH v9 08/17] iio: core: add hierarchical channel relationships Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 15:50 ` [PATCH v9 09/17] dt-bindings: iio: frequency: add ad9910 Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 15:50 ` [PATCH v9 10/17] iio: frequency: ad9910: initial driver implementation Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 16:24 ` sashiko-bot
2026-07-22 15:50 ` [PATCH v9 11/17] iio: frequency: ad9910: add basic parallel port support Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 15:50 ` [PATCH v9 12/17] iio: frequency: ad9910: add digital ramp generator support Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 15:50 ` [PATCH v9 13/17] iio: frequency: ad9910: add RAM mode support Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 16:44 ` sashiko-bot [this message]
2026-07-22 15:50 ` [PATCH v9 14/17] iio: frequency: ad9910: add output shift keying support Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 15:50 ` [PATCH v9 15/17] iio: frequency: ad9910: show channel priority in debugfs Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 16:52 ` sashiko-bot
2026-07-22 15:50 ` [PATCH v9 16/17] iio: ABI: add docs for ad9910 sysfs and debugfs entries Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
2026-07-22 16:50 ` sashiko-bot
2026-07-22 15:50 ` [PATCH v9 17/17] docs: iio: add documentation for ad9910 driver Rodrigo Alencar via B4 Relay
2026-07-22 15:50 ` Rodrigo Alencar
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=20260722164456.B12EF1F000E9@smtp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.