DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nuno Sá" <nuno.sa@analog.com>
Cc: vkoul@kernel.org, Frank.Li@kernel.org, dmaengine@vger.kernel.org
Subject: Re: [PATCH v2 6/9] iio: buffer-dmaengine: Use dma_slave_caps bus width accessors
Date: Mon, 10 Aug 2026 15:32:39 +0000	[thread overview]
Message-ID: <20260810153240.5C5861F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260810-dmaengine-support-wider-dma-masks-v2-6-1f7b798d035f@analog.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] DMA buffer alignment calculation uses `round_down()` with non-power-of-2 alignments, causing broken truncation
--

--- Patch [6]: [PATCH v2 6/9] iio: buffer-dmaengine: Use dma_slave_caps bus width accessors ---
commit 5f03b0a586d9a871f77efec877e70d9047e60575
Author: Nuno Sá <nuno.sa@analog.com>

iio: buffer-dmaengine: Use dma_slave_caps bus width accessors

This commit updates the IIO DMA buffer to use the new dma_slave_caps
bus width helpers instead of decoding raw legacy width masks. This ensures
compatibility with DMA controllers using the new bitmap representation.

> diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> index 98acce9098547..855e3662cd3dc 100644
> --- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> +++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c
> @@ -229,14 +229,13 @@ static struct iio_buffer *iio_dmaengine_buffer_alloc(struct dma_chan *chan)
>  		return ERR_PTR(-ENOMEM);
>  
>  	/* Needs to be aligned to the maximum of the minimums */
> -	if (caps.src_addr_widths)
> -		src_width = __ffs(caps.src_addr_widths);
> -	else
> -		src_width = 1;
> -	if (caps.dst_addr_widths)
> -		dest_width = __ffs(caps.dst_addr_widths);
> -	else
> -		dest_width = 1;
> +	src_width = dma_slave_caps_get_src_width_min(&caps);
> +	if (src_width == DMA_SLAVE_BUSWIDTH_UNDEFINED)
> +		src_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
> +	dest_width = dma_slave_caps_get_dst_width_min(&caps);
> +	if (dest_width == DMA_SLAVE_BUSWIDTH_UNDEFINED)
> +		dest_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
> +
>  	width = max(src_width, dest_width);

[Severity: High]
This is a pre-existing issue, but does this alignment calculation
cause broken truncation when used with 3-byte bus widths?

If a DMA controller advertises a 3-byte minimum bus width
(e.g., using 24-bit transfers), width and subsequently
dmaengine_buffer->align will be set to 3.

In iio_dmaengine_buffer_submit_block(), this alignment is used:

    max_size = round_down(max_size, dmaengine_buffer->align);

The round_down(x, y) macro requires y to be a power of 2 because it
evaluates to (x & ~(y - 1)). When align is 3, round_down(max_size, 3) 
yields (max_size & ~2) instead of properly rounding to a multiple of 3.

For example, round_down(30, 3) evaluates to 28 instead of 27. 

This incorrectly aligned length is then assigned to block->bytes_used 
and passed to the DMA controller, which could result in unaligned 
transfer configurations and DMA controller faults.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260810-dmaengine-support-wider-dma-masks-v2-0-1f7b798d035f@analog.com?part=6

  reply	other threads:[~2026-08-10 15:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10 15:06 [PATCH v2 0/9] dmaengine: Support bus widths of 32 bytes and above Nuno Sá
2026-08-10 15:06 ` [PATCH v2 1/9] " Nuno Sá
2026-08-10 15:17   ` sashiko-bot
2026-08-10 17:15   ` Andy Shevchenko
2026-08-10 15:06 ` [PATCH v2 2/9] dmaengine: dma-axi-dmac: Use bus width capability helpers Nuno Sá
2026-08-10 15:06 ` [PATCH v2 3/9] dmaengine: dw-axi-dmac: " Nuno Sá
2026-08-10 15:18   ` sashiko-bot
2026-08-10 15:06 ` [PATCH v2 4/9] dmaengine: qcom: gpi: " Nuno Sá
2026-08-10 15:15   ` sashiko-bot
2026-08-10 15:06 ` [PATCH v2 5/9] dmaengine: stm32-dma3: " Nuno Sá
2026-08-10 15:06 ` [PATCH v2 6/9] iio: buffer-dmaengine: Use dma_slave_caps bus width accessors Nuno Sá
2026-08-10 15:32   ` sashiko-bot [this message]
2026-08-10 15:06 ` [PATCH v2 7/9] ALSA: pcm_dmaengine: Use dma_slave_caps bus width helpers Nuno Sá
2026-08-10 15:06 ` [PATCH v2 8/9] spi: dw: " Nuno Sá
2026-08-10 15:28   ` sashiko-bot
2026-08-10 15:06 ` [PATCH v2 9/9] dmaengine: Drop legacy bus width fields from dma_slave_caps Nuno Sá
2026-08-10 16:56   ` Frank Li

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=20260810153240.5C5861F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    /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