mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Amelie Delaunay <amelie.delaunay@foss.st.com>
Cc: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	dmaengine@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] dmaengine: stm32-dma3: replace hardcoded LLI size with aligned descriptor size
Date: Fri, 20 Nov 2026 12:05:57 -0600	[thread overview]
Message-ID: <awCMBWXquRi3_WFZ@SMW015318> (raw)
In-Reply-To: <20261120-dma3-fixes-v1-4-f29c1f437399@foss.st.com>

On Fri, Nov 20, 2026 at 10:18:04AM +0100, Amelie Delaunay wrote:
> The DMA3 driver currently hardcodes a 32-byte descriptor size when
> computing the maximum linked-list size and validating the number of
> descriptors to allocate.
>
> Compute the descriptor size from the aligned size of
> struct stm32_dma3_hwdesc, introduce a dedicated STM32_DMA3_MAX_DESC_COUNT
> macro, and use it both for the segment size limit (STM32_DMA3_MAX_SEG_SIZE)
> and for the descriptor count check (in stm32_dma3_chan_desc_alloc()).
>
> This also corrects the maximum descriptor count: CLLR_LA holds the offset
> to the next descriptor, so for a descriptor size of N bytes the last
> valid descriptor is at offset (count - 1) * N, and the maximum number of
> descriptors is (CLLR_LA / N) + 1.
>
> Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>  drivers/dma/stm32/stm32-dma3.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/dma/stm32/stm32-dma3.c b/drivers/dma/stm32/stm32-dma3.c
> index 7c509a69f5e5..e5724c4b2c84 100644
> --- a/drivers/dma/stm32/stm32-dma3.c
> +++ b/drivers/dma/stm32/stm32-dma3.c
> @@ -251,12 +251,14 @@ struct stm32_dma3_hwdesc {
>  } __packed __aligned(32);
>
>  /*
> - * CLLR_LA / sizeof(struct stm32_dma3_hwdesc) represents the number of hdwdesc that can be addressed
> - * by the pointer to the next linked-list data structure. The __aligned forces the 32-byte
> - * alignment. So use hardcoded 32. Multiplied by the max block size of each item, it represents
> - * the sg size limitation.
> + * (CLLR_LA / STM32_DMA3_DESC_SIZE) + 1 represents the number of hwdesc that can be addressed
> + * by the pointer to the next linked-list data structure.
> + * Multiplied by the max block size of each item, it represents the sg size limitation.
>   */
> -#define STM32_DMA3_MAX_SEG_SIZE		((CLLR_LA / 32) * STM32_DMA3_MAX_BLOCK_SIZE)
> +#define STM32_DMA3_DESC_SIZE		ALIGN(sizeof(struct stm32_dma3_hwdesc), \
> +					      __alignof__(struct stm32_dma3_hwdesc))
> +#define STM32_DMA3_MAX_DESC_COUNT	((CLLR_LA / STM32_DMA3_DESC_SIZE) + 1)
> +#define STM32_DMA3_MAX_SEG_SIZE		(STM32_DMA3_MAX_DESC_COUNT * STM32_DMA3_MAX_BLOCK_SIZE)
>
>  /*
>   * Linked-list items
> @@ -401,11 +403,10 @@ static struct stm32_dma3_swdesc *stm32_dma3_chan_desc_alloc(struct stm32_dma3_ch
>  	dma_addr_t base_addr = 0;
>
>  	/*
> -	 * If the memory to be allocated for the number of hwdesc (6 u32 members but 32-bytes
> -	 * aligned) is greater than the maximum address of CLLR_LA, then the last items can't be
> -	 * addressed, so abort the allocation.
> +	 * If the memory to be allocated for the number of hwdesc is greater than the maximum
> +	 * addressable by CLLR_LA, then the last items can't be addressed, so abort the allocation.
>  	 */
> -	if ((count * 32) > CLLR_LA) {
> +	if (count > STM32_DMA3_MAX_DESC_COUNT) {
>  		dev_err(vchan_chan_dev(&chan->vchan), "Transfer is too big (> %luB)\n", STM32_DMA3_MAX_SEG_SIZE);
>  		return NULL;
>  	}
>
> --
> 2.43.0
>

      reply	other threads:[~2026-11-20 18:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  9:18 [PATCH 0/4] dmaengine: stm32-dma3: fix IRQ flag race and linked-list handling Amelie Delaunay
2026-11-20  9:18 ` [PATCH 1/4] dmaengine: stm32-dma3: clear flags before signaling transfer completion Amelie Delaunay
2026-11-20 17:48   ` Frank Li
2026-11-20  9:18 ` [PATCH 2/4] dmaengine: stm32-dma3: set LL base address when transfer starts Amelie Delaunay
2026-11-20 17:51   ` Frank Li
2026-11-20  9:18 ` [PATCH 3/4] dmaengine: stm32-dma3: validate LLI pool allocations and fix cleanup Amelie Delaunay
2026-11-20 18:02   ` Frank Li
2026-11-20  9:18 ` [PATCH 4/4] dmaengine: stm32-dma3: replace hardcoded LLI size with aligned descriptor size Amelie Delaunay
2026-11-20 18:05   ` Frank Li [this message]

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=awCMBWXquRi3_WFZ@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=alexandre.torgue@foss.st.com \
    --cc=amelie.delaunay@foss.st.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --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

all inboxes | Powered by JetHome®