DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: Frank.Li@oss.nxp.com
Cc: vkoul@kernel.org, Frank.Li@kernel.org, dmaengine@vger.kernel.org,
	imx@lists.linux.dev
Subject: Re: [PATCH v2 1/2] dmaengine: Add helper dmaengine_prep_submit_slave_single()
Date: Fri, 22 May 2026 20:45:38 +0000	[thread overview]
Message-ID: <20260522204538.EFE9C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260522-dma_prep_submit-v2-1-7a87a5a29525@nxp.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] The macro accesses the descriptor after calling `dmaengine_submit()`, violating the DMA Engine API contract and causing a Use-After-Free.
- [Medium] Calling `dmaengine_desc_free()` fails to prevent memory leaks for standard, non-reusable DMA descriptors, defeating the primary goal of the patch.
- [Low] The fallback implementation of `dmaengine_prep_submit_slave_single` contains severe syntax errors that break compilation when `CONFIG_DMA_ENGINE` is disabled.
--

commit c731d16a7ec5a6fed71b17234ae1bc2184ad8818
Author: Frank Li <Frank.Li@nxp.com>

dmaengine: Add helper dmaengine_prep_submit_slave_single()

This commit introduces a helper macro and function to combine the preparation
and submission of a DMA slave single transfer into a single step. It also
aims to automatically free the descriptor if the submission fails.

> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index ca13cd39330ba..1e25be78a22a5 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
[ ... ]
> @@ -1619,6 +1619,34 @@ void dma_run_dependencies(struct dma_async_tx_descriptor *tx)
>  }
>  EXPORT_SYMBOL_GPL(dma_run_dependencies);
>  
> +#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);		\

[Severity: Critical]
Does this access the descriptor after ownership has been transferred?

The DMA Engine API contract specifies that once dmaengine_submit is called,
the client must consider the descriptor pointer invalid. If submission fails,
some DMA providers (like the idxd driver in idxd_dma_tx_submit) internally
free the descriptor before returning an error.

Calling dmaengine_desc_free here would read tx->flags on an already-freed
pointer on the error path, resulting in a use-after-free.

[Severity: Medium]
Will this actually free standard, non-reusable descriptors?

The dmaengine_desc_free function is explicitly designed for reusable
descriptors. It internally calls dmaengine_desc_test_reuse, which checks
the DMA_CTRL_REUSE flag and returns -EPERM immediately if it is not set. 

Since standard descriptors created via dmaengine_prep_slave_single don't 
have this flag set by default, it seems this call acts as a no-op and might
not resolve the resource leak mentioned in the commit message.

> +	}							\
> +	cookie;							\
> +})
> +
[ ... ]
> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> index 99efe2b9b4ea9..0f789fac7e91a 100644
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
[ ... ]
> @@ -1575,6 +1582,16 @@ static inline int dma_get_slave_caps(struct dma_chan *chan,
>  {
>  	return -ENXIO;
>  }
> +
> +static inline dma_cookie_t
> +dmaengine_prep_submit_slave_single(struct dma_chan *chan,
> +				   dma_async_tx_callback cb, void *cb_param;
> +				   dma_addr_t buf, size_t len,
> +				   enum dma_transfer_direction dir,
> +				   unsigned long flags);
> +{

[Severity: Low]
Are there syntax errors in this fallback implementation?

The parameter list uses a semicolon instead of a comma after cb_param, and
there is a stray semicolon immediately preceding the function body. This will
cause a build failure when CONFIG_DMA_ENGINE is disabled.

> +	return -ENODEV;
> +}
>  #endif
>  
>  static inline int dmaengine_desc_set_reuse(struct dma_async_tx_descriptor *tx)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260522-dma_prep_submit-v2-0-7a87a5a29525@nxp.com?part=1

  reply	other threads:[~2026-05-22 20:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-22 20:13 [PATCH v2 0/2] dmaengine: add helper macro dmaengine_prep_submit() Frank.Li
2026-05-22 20:13 ` [PATCH v2 1/2] dmaengine: Add helper dmaengine_prep_submit_slave_single() Frank.Li
2026-05-22 20:45   ` sashiko-bot [this message]
2026-05-22 21:36     ` Frank Li
2026-05-22 20:13 ` [PATCH v2 2/2] i2c: imx-lpi2c: use dmaengine_prep_submit() to simple code Frank.Li
2026-05-22 21:15   ` sashiko-bot

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=20260522204538.EFE9C1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=Frank.Li@oss.nxp.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --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