From: Linus Walleij <linusw@kernel.org>
To: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org,
Ulf Hansson <ulfh@kernel.org>, Linus Walleij <linusw@kernel.org>
Subject: [PATCH] dmaengine: ste_dma40: Keep prepared descriptors across termination
Date: Wed, 04 Nov 2026 22:28:02 +0100 [thread overview]
Message-ID: <20261104-dma40-fixes-v1-1-48c5180f5210@kernel.org> (raw)
MMCI can prepare the next request while the current DMA transfer is
running. If the current request fails, its error handler terminates the
channel before the next descriptor has been submitted.
d40_term_all() frees that descriptor from prepare_queue, although MMCI
still holds its pointer. Submitting it later accesses freed memory in
d40_tx_submit(). A reported crash writes to 0x104 through a list pointer
containing LIST_POISON1, which is consistent with this sequence.
Termination only cancels transfers that have been submitted. Leave
prepared descriptors on prepare_queue so the client can still submit
them, and release any remaining prepared descriptors when the channel
resources are freed. Keep tracking them so abandoned descriptors are
reclaimed at channel teardown.
Fixes: 82babbb361f2 ("dmaengine/ste_dma40: fix memory leak due to prepared descriptors")
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
drivers/dma/ste_dma40.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
index 74dd4cbdc3c0..f1cbc719c4f0 100644
--- a/drivers/dma/ste_dma40.c
+++ b/drivers/dma/ste_dma40.c
@@ -1166,14 +1166,6 @@ static void d40_term_all(struct d40_chan *d40c)
d40_desc_free(d40c, d40d);
}
- /* Release descriptors in prepare queue */
- if (!list_empty(&d40c->prepare_queue))
- list_for_each_entry_safe(d40d, _d,
- &d40c->prepare_queue, node) {
- d40_desc_remove(d40d);
- d40_desc_free(d40c, d40d);
- }
-
d40c->pending_tx = 0;
}
@@ -2222,7 +2214,8 @@ static int d40_config_memcpy(struct d40_chan *d40c)
static int d40_free_dma(struct d40_chan *d40c)
{
-
+ struct d40_desc *d40d;
+ struct d40_desc *_d;
int res = 0;
u32 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dev_type);
struct d40_phy_res *phy = d40c->phy_chan;
@@ -2252,6 +2245,12 @@ static int d40_free_dma(struct d40_chan *d40c)
/* Release descriptor state; this does not access DMA40 registers. */
d40_term_all(d40c);
+ /* Release any prepared descriptors the client did not submit. */
+ list_for_each_entry_safe(d40d, _d, &d40c->prepare_queue, node) {
+ d40_desc_remove(d40d);
+ d40_desc_free(d40c, d40d);
+ }
+
res = pm_runtime_resume_and_get(d40c->base->dev);
if (res >= 0) {
res = d40_channel_execute_command(d40c, D40_DMA_STOP);
@@ -2508,10 +2507,7 @@ d40_prep_sg(struct dma_chan *dchan, struct scatterlist *sg_src,
goto free_desc;
}
- /*
- * add descriptor to the prepare queue in order to be able
- * to free them later in terminate_all
- */
+ /* Track prepared descriptors until submission or channel release. */
list_add_tail(&desc->node, &chan->prepare_queue);
spin_unlock_irqrestore(&chan->lock, flags);
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261104-dma40-fixes-d9db6094b7d9
Best regards,
--
Linus Walleij <linusw@kernel.org>
next reply other threads:[~2026-11-04 21:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 21:28 Linus Walleij [this message]
2026-11-12 20:59 ` [PATCH] dmaengine: ste_dma40: Keep prepared descriptors across termination 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=20261104-dma40-fixes-v1-1-48c5180f5210@kernel.org \
--to=linusw@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=ulfh@kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).