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@nxp.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