All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Cosmin Tanislav" <cosmin-gabriel.tanislav.xa@renesas.com>
Cc: robh@kernel.org, wsa+renesas@sang-engineering.com,
	devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 7/9] dt-bindings: iio: adc: renesas,r9a09g077-adc: document DMA support
Date: Thu, 10 Sep 2026 09:14:26 +0000	[thread overview]
Message-ID: <20260910091427.4F25F1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260910085430.3173166-8-cosmin-gabriel.tanislav.xa@renesas.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The IIO channel specifies `IIO_CPU` endianness for the DMA buffer, but the driver copies the raw hardware samples without converting them to native CPU endianness.
--

commit 7eb4eed24fc9164ecef6de1efee2ea6e90c109dc
Author: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>

iio: adc: rzt2h: implement DMA buffer support

Implement buffered capture using a cyclic DMA transfer into a kfifo
buffer to support continuous high-rate sampling.

> diff --git a/drivers/iio/adc/rzt2h_adc.c b/drivers/iio/adc/rzt2h_adc.c
> index 95bcebdc02cb3..0460dffe189e2 100644
> --- a/drivers/iio/adc/rzt2h_adc.c
> +++ b/drivers/iio/adc/rzt2h_adc.c

[ ... ]

> @@ -151,6 +186,263 @@ static int rzt2h_adc_calibrate(struct rzt2h_adc *adc)
>  	return 0;
>  }
>  
> +static void rzt2h_adc_push_period(struct iio_dev *indio_dev, u16 *period,
> +				  dma_addr_t addr)
> +{
> +	struct rzt2h_adc *adc = iio_priv(indio_dev);
> +	u16 *dst = adc->buf;
> +	u16 *src = period;
> +
> +	dma_sync_single_for_cpu(adc->dev, addr, adc->dma.period_bytes,
> +				DMA_FROM_DEVICE);
> +
> +	for (unsigned int sample = 0; sample < RZT2H_ADC_DMA_PERIOD_SAMPLES; sample++) {
> +		for (unsigned int i = 0; i < adc->dma.gather_len; i++)
> +			dst[i] = src[adc->dma.gather[i]];

[Severity: High]
Does this code copy the raw hardware samples into the IIO buffer without
converting them to native CPU endianness?

If a user-space application enables the IIO buffer and reads samples from the
ADC on a big-endian architecture, the hardware writes little-endian 16-bit
words to DMA memory. This function appears to copy those raw little-endian
bytes verbatim.

[ ... ]

> @@ -192,6 +489,12 @@ static const struct iio_chan_spec rzt2h_adc_chan_template = {
>  	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
>  			      BIT(IIO_CHAN_INFO_SCALE),
>  	.type = IIO_VOLTAGE,
> +	.scan_type = {
> +		.sign = 'u',
> +		.realbits = 12,
> +		.storagebits = 16,
> +		.endianness = IIO_CPU,
> +	},
>  };

[Severity: High]
Does setting endianness to IIO_CPU incorrectly inform the IIO core and
userspace that the buffered data is in native CPU endianness?

Because the channel is marked as IIO_CPU here, the IIO core and userspace
assume the data is natively ordered. Combined with the verbatim copy in
rzt2h_adc_push_period(), they might interpret the little-endian bytes
incorrectly on big-endian CPUs, potentially leading to data corruption where
applications read swapped bytes.

Should the little-endian data be converted to CPU endianness before being
pushed to the buffer, or should the scan type reflect the actual endianness
of the hardware?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260910085430.3173166-1-cosmin-gabriel.tanislav.xa@renesas.com?part=7

  reply	other threads:[~2026-09-10  9:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10  8:54 [PATCH v2 0/9] iio: adc: rzt2h: add DMA buffer support Cosmin Tanislav
2026-09-10  8:54 ` [PATCH v2 1/9] iio: adc: rzt2h: remove unused struct rzt2h_adc::max_channels Cosmin Tanislav
2026-09-10  8:54 ` [PATCH v2 2/9] iio: adc: rzt2h: store IRQ in private state Cosmin Tanislav
2026-09-10  8:54 ` [PATCH v2 3/9] iio: adc: rzt2h: store the physical address " Cosmin Tanislav
2026-09-10  8:54 ` [PATCH v2 4/9] iio: adc: rzt2h: claim direct mode on single reads Cosmin Tanislav
2026-09-10  8:54 ` [PATCH v2 5/9] iio: adc: rzt2h: implement DMA buffer support Cosmin Tanislav
2026-09-13 21:12   ` Jonathan Cameron
2026-09-10  8:54 ` [PATCH v2 6/9] iio: adc: rzt2h: expose sampling frequency Cosmin Tanislav
2026-09-10  9:11   ` sashiko-bot
2026-09-13 21:12   ` Jonathan Cameron
2026-09-13 21:20     ` Cosmin-Gabriel Tanislav
2026-09-10  8:54 ` [PATCH v2 7/9] dt-bindings: iio: adc: renesas,r9a09g077-adc: document DMA support Cosmin Tanislav
2026-09-10  9:14   ` sashiko-bot [this message]
2026-09-10  8:54 ` [PATCH v2 8/9] arm64: dts: renesas: r9a09g077: Wire up DMA support for ADC Cosmin Tanislav
2026-09-17  9:59   ` Geert Uytterhoeven
2026-09-10  8:54 ` [PATCH v2 9/9] arm64: dts: renesas: r9a09g087: " Cosmin Tanislav
2026-09-17  9:59   ` Geert Uytterhoeven
2026-09-13 21:12 ` [PATCH v2 0/9] iio: adc: rzt2h: add DMA buffer support 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=20260910091427.4F25F1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=cosmin-gabriel.tanislav.xa@renesas.com \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wsa+renesas@sang-engineering.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 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.