Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Marcelo Schmitt" <marcelo.schmitt@analog.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v1 08/13] dt-bindings: iio: adc: adi,ad4134: Document SPI connection mode
Date: Wed, 02 Sep 2026 17:46:27 +0000	[thread overview]
Message-ID: <20260902174628.5CF141F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <d9b759d29fa8ca12b6cf083e180b2556ca4533f0.1788368334.git.marcelo.schmitt@analog.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] Unconditional buffer overflow in `ad4134_trigger_handler()` and silent data loss when the timestamp channel is enabled.
- [High] The ad4134 driver ignores unsupported `adi,spi-mode` values and silently falls back to `no-cs` mode without throwing an error.
- [Medium] Adding daisy-chain modes without explicitly allowing the '#daisy-chained-devices' property.
- [Low] The `adi,spi-mode` property describes a default fallback in text but lacks the YAML `default` keyword in the schema.
--

commit 5c85e25862888f2e9a104a75c26404312b5feaf0
Author: Marcelo Schmitt <marcelo.schmitt@analog.com>

dt-bindings: iio: adc: adi,ad4134: Document SPI connection mode

Document how AD4134 chips are connected to the host SPI controller
according to different wiring configurations.

> diff --git a/Documentation/devicetree/bindings/iio/adc/adi,ad4134.yaml b/Documentation/devicetree/bindings/iio/adc/adi,ad4134.yaml
> index ea6d7e0264190..d843c02a394a3 100644
> --- a/Documentation/devicetree/bindings/iio/adc/adi,ad4134.yaml
> +++ b/Documentation/devicetree/bindings/iio/adc/adi,ad4134.yaml
> @@ -131,6 +131,28 @@ properties:
>      enum: [ free-running, gated ]
>      default: gated
>  
> +  adi,spi-mode:
> +    $ref: /schemas/types.yaml#/definitions/string
> +    enum: [ no-cs, 4-wire, one-channel-chain, two-channel-chain ]

[Severity: Medium]
Does this schema need to explicitly allow the '#daisy-chained-devices'
property, or reference /schemas/spi/spi-peripheral-props.yaml?

Standard devicetree descriptions for daisy-chained IIO devices require
'#daisy-chained-devices' to communicate chain length.

Without it, won't any devicetree using the newly added 'one-channel-chain'
mode fail dt_binding_check validation?

> +    description: |
> +      This property indicates the SPI wiring configuration.
> +
> +      When this property is omitted, it is assumed that the device is using
> +      'no-cs' wiring.

[Severity: Low]
Is it possible to add the YAML 'default: no-cs' keyword to the schema
definition?

Since the text describes a default fallback, structurally representing it
ensures tooling can infer the default configuration.

[ ... ]

I also noticed some regressions in the driver code related to these SPI modes.

In drivers/iio/adc/ad4134.c:ad4134_probe():

	ret = device_property_match_property_string(dev, "adi,spi-mode",
						    ad4134_spi_modes,
						    ARRAY_SIZE(ad4134_spi_modes));
	/* Default to "no-cs" mode if adi,spi-mode is not specified */
	if (ret == -EINVAL)
		st->spi_mode = AD4134_SPI_MODE_NO_CS;

[Severity: High]
Does this code silently ignore unsupported strings?

device_property_match_property_string() returns -EINVAL when the property
exists but contains a string not in the array (such as the newly added
"one-channel-chain" mode).

If the driver doesn't support the chain modes yet, will this incorrectly
configure the SPI host and multiplexer for no-cs minimum I/O mode?

Could this cause hardware protocol violations and garbage data reads during
system initialization when a misconfigured or untrusted DT is provided?


In drivers/iio/adc/ad4134.c:ad4134_trigger_handler():

	for (unsigned int ch = 0; ch < iio_get_masklength(indio_dev); ch++) {
		ret = spi_write_then_read(st->spi, NULL, 0, &st->scan[ch],
...
	iio_push_to_buffers_with_ts(indio_dev, &st->scan, sizeof(st->scan),
				    pf->timestamp);

[Severity: Critical]
Does this loop overflow the st->scan array?

Because ad4134_chan_set includes the soft timestamp channel,
iio_get_masklength(indio_dev) returns 5. The loop will unconditionally iterate
up to ch=4, performing an SPI read into &st->scan[4].

Since st->scan is only sized for 4 channels (u32 scan[AD4134_NUM_CHANNELS]),
won't this result in out-of-bounds memory corruption on every hardware trigger?

Furthermore, when the timestamp channel is enabled, IIO requires a 24-byte
buffer (4x4 bytes + 8-byte timestamp). Because sizeof(st->scan) is 16 bytes,
will iio_push_to_buffers_with_ts() detect the undersized buffer and silently
drop all captured data?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788368334.git.marcelo.schmitt@analog.com?part=8

  reply	other threads:[~2026-09-02 17:46 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 17:21 [PATCH v1 00/13] iio: adc: ad4134: Enable greater sample rate data capture Marcelo Schmitt
2026-09-02 17:21 ` [PATCH v1 01/13] iio: Fix typo in vendor name Marcelo Schmitt
2026-09-03  6:22   ` Andy Shevchenko
2026-09-02 17:21 ` [PATCH v1 02/13] iio: adc: ad4134: Drop import to empty name space Marcelo Schmitt
2026-09-02 17:22 ` [PATCH v1 03/13] iio: adc: ad4134: Update include list to comply with IWYU principles Marcelo Schmitt
2026-09-02 17:40   ` sashiko-bot
2026-09-03  6:26   ` Andy Shevchenko
2026-09-02 17:22 ` [PATCH v1 04/13] iio: adc: ad4134: Serialize single-read operations Marcelo Schmitt
2026-09-03  6:27   ` Andy Shevchenko
2026-09-02 17:23 ` [PATCH v1 05/13] iio: adc: ad4134: Run shorter transfers when CRC is disabled Marcelo Schmitt
2026-09-02 17:42   ` sashiko-bot
2026-09-02 17:23 ` [PATCH v1 06/13] iio: adc: ad4134: Add support for digital filter type selection Marcelo Schmitt
2026-09-03  6:31   ` Andy Shevchenko
2026-09-02 17:23 ` [PATCH v1 07/13] iio: adc: ad4134: Support buffered data read Marcelo Schmitt
2026-09-02 17:38   ` sashiko-bot
2026-09-02 17:24 ` [PATCH v1 08/13] dt-bindings: iio: adc: adi,ad4134: Document SPI connection mode Marcelo Schmitt
2026-09-02 17:46   ` sashiko-bot [this message]
2026-09-03 18:14   ` Conor Dooley
2026-09-02 17:24 ` [PATCH v1 09/13] iio: adc: ad4134: Support SPI 4-wire mode Marcelo Schmitt
2026-09-02 17:46   ` sashiko-bot
2026-09-03  6:39   ` Andy Shevchenko
2026-09-02 17:24 ` [PATCH v1 10/13] dt-bindings: iio: adc: adi,ad4134: Document PWM usage Marcelo Schmitt
2026-09-02 17:25 ` [PATCH v1 11/13] dt-bindings: iio: adc: adi,ad4134: Add high data throughput example Marcelo Schmitt
2026-09-02 17:39   ` sashiko-bot
2026-09-02 17:25 ` [PATCH v1 12/13] iio: adc: ad4134: Support high-speed data capture Marcelo Schmitt
2026-09-02 17:49   ` sashiko-bot
2026-09-03  7:00   ` Andy Shevchenko
2026-09-02 17:25 ` [PATCH v1 13/13] Docs: iio: Add AD4134 Marcelo Schmitt

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=20260902174628.5CF141F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=marcelo.schmitt@analog.com \
    --cc=robh@kernel.org \
    --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