Re: [PATCH 4/4] dmaengine: stm32-dma3: replace hardcoded LLI size with aligned descriptor size

From: Frank Li

Date: Fri Nov 20 2026 - 13:09:17 EST


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@xxxxxxxxxxx>
> ---

Reviewed-by: Frank Li <Frank.Li@xxxxxxx>

> 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
>