From: Amelie Delaunay <amelie.delaunay@foss.st.com>
To: "Vinod Koul" <vkoul@kernel.org>, "Frank Li" <Frank.Li@kernel.org>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
"Amélie Delaunay" <amelie.delaunay@foss.st.com>
Cc: <dmaengine@vger.kernel.org>,
<linux-stm32@st-md-mailman.stormreply.com>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, "Frank Li" <Frank.Li@nxp.com>
Subject: [PATCH v2 4/4] dmaengine: stm32-dma3: replace hardcoded LLI size with aligned descriptor size
Date: Mon, 23 Nov 2026 10:17:08 +0100 [thread overview]
Message-ID: <20261123-dma3-fixes-v2-4-0a5b013f79d2@foss.st.com> (raw)
In-Reply-To: <20261123-dma3-fixes-v2-0-0a5b013f79d2@foss.st.com>
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.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.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
prev parent reply other threads:[~2026-11-23 10:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 9:17 [PATCH v2 0/4] dmaengine: stm32-dma3: fix IRQ flag race and linked-list handling Amelie Delaunay
2026-11-23 9:17 ` [PATCH v2 1/4] dmaengine: stm32-dma3: clear flags before signaling transfer completion Amelie Delaunay
2026-11-23 17:32 ` Frank Li
2026-11-23 9:17 ` [PATCH v2 2/4] dmaengine: stm32-dma3: set LL base address when transfer starts Amelie Delaunay
2026-11-23 9:17 ` [PATCH v2 3/4] dmaengine: stm32-dma3: validate LLI pool allocations and fix cleanup Amelie Delaunay
2026-11-23 9:17 ` Amelie Delaunay [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=20261123-dma3-fixes-v2-4-0a5b013f79d2@foss.st.com \
--to=amelie.delaunay@foss.st.com \
--cc=Frank.Li@kernel.org \
--cc=Frank.Li@nxp.com \
--cc=alexandre.torgue@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