[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20260130-dma_prep_submit-v1-1-2198f9e848fa@nxp.com>
Date: Fri, 30 Jan 2026 10:21:14 -0500
From: Frank Li <Frank.Li@....com>
To: Vinod Koul <vkoul@...nel.org>, Dong Aisheng <aisheng.dong@....com>,
Andi Shyti <andi.shyti@...nel.org>, Shawn Guo <shawnguo@...nel.org>,
Sascha Hauer <s.hauer@...gutronix.de>,
Pengutronix Kernel Team <kernel@...gutronix.de>,
Fabio Estevam <festevam@...il.com>
Cc: dmaengine@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-i2c@...r.kernel.org, imx@...ts.linux.dev,
linux-arm-kernel@...ts.infradead.org, carlos.song@....com,
Frank Li <Frank.Li@....com>
Subject: [PATCH 1/2] dmaengine: Add helper macro dmaengine_prep_submit()
Previously, DMA users had to call dmaengine_prep_*() followed by
dmaengine_submit(). Many DMA consumers missed call dmaengine_desc_free()
when dmaengine_submit() returned an error.
Introduce dmaengine_prep_submit() to combine preparation and submission
into a single step and ensure the descriptor is freed on submission
failure.
Signed-off-by: Frank Li <Frank.Li@....com>
---
include/linux/dmaengine.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 99efe2b9b4ea9844ca6161208362ef18ef111d96..78246fd8a8294b6764d2717d73b9c49842f64696 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -1249,6 +1249,22 @@ static inline dma_cookie_t dmaengine_submit(struct dma_async_tx_descriptor *desc
return desc->tx_submit(desc);
}
+#define dmaengine_prep_submit(chan, cb, cb_param, func, ...) \
+({ struct dma_async_tx_descriptor *tx = \
+ dmaengine_prep_##func(chan, __VA_ARGS__); \
+ dma_cookie_t cookie = -ENOMEM; \
+ \
+ if (tx) { \
+ tx->callback = cb; \
+ tx->callback_param = cb_param; \
+ cookie = dmaengine_submit(tx); \
+ \
+ if (dma_submit_error(cookie)) \
+ dmaengine_desc_free(tx); \
+ } \
+ cookie; \
+})
+
static inline bool dmaengine_check_align(enum dmaengine_alignment align,
size_t off1, size_t off2, size_t len)
{
--
2.34.1
Powered by blists - more mailing lists