Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
* [PATCH 0/2] dmaengine: add dmaengine_prep_slave_sg_context() API
@ 2026-09-17 20:08 Frank.Li
  2026-09-17 20:08 ` [PATCH 1/2] dmaengine: add dmaengine_prep_slave_sg_context() to wrap prep_slave_sg Frank.Li
  2026-09-17 20:08 ` [PATCH 2/2] ASoC: sprd: replace direct ->device_prep*() calls with standard DMA engine API Frank.Li
  0 siblings, 2 replies; 4+ messages in thread
From: Frank.Li @ 2026-09-17 20:08 UTC (permalink / raw)
  To: Vinod Koul, Frank Li, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Orson Zhai, Baolin Wang, Chunyan Zhang
  Cc: dmaengine, linux-kernel, linux-sound, imx, Frank Li

Add dmaengine_prep_slave_sg_context() for consumers that need to pass
context value when preparing slave SG transfers.

This replaces direct use of the prep_slave_sg() callback context,
which is intended for DMA engine internal use only. Mark it as deprecated
in preparation for making DMA engine internals private.

The only current user is sound/soc/sprd/sprd-pcm-compress.c.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
Frank Li (2):
      dmaengine: add dmaengine_prep_slave_sg_context() to wrap prep_slave_sg
      ASoC: sprd: replace direct ->device_prep*() calls with standard DMA engine API

 include/linux/dmaengine.h          | 13 +++++++++++++
 sound/soc/sprd/sprd-pcm-compress.c |  6 +++---
 sound/soc/sprd/sprd-pcm-dma.c      |  6 +++---
 3 files changed, 19 insertions(+), 6 deletions(-)
---
base-commit: 0d9d0dbf2fddcff5859d623e90ca73c4054276e1
change-id: 20260917-b4-dmaengine-prep-slave-sg-55e8653077aa

Best regards,
--  
Frank Li <Frank.Li@nxp.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] dmaengine: add dmaengine_prep_slave_sg_context() to wrap prep_slave_sg
  2026-09-17 20:08 [PATCH 0/2] dmaengine: add dmaengine_prep_slave_sg_context() API Frank.Li
@ 2026-09-17 20:08 ` Frank.Li
  2026-09-17 20:15   ` sashiko-bot
  2026-09-17 20:08 ` [PATCH 2/2] ASoC: sprd: replace direct ->device_prep*() calls with standard DMA engine API Frank.Li
  1 sibling, 1 reply; 4+ messages in thread
From: Frank.Li @ 2026-09-17 20:08 UTC (permalink / raw)
  To: Vinod Koul, Frank Li, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Orson Zhai, Baolin Wang, Chunyan Zhang
  Cc: dmaengine, linux-kernel, linux-sound, imx, Frank Li

From: Frank Li <Frank.Li@nxp.com>

Most DMA engine providers and consumers do not use the context argument
of prep_slave_sg().  A few do, however:

Consumers:
  sound/soc/sprd/sprd-pcm-compress.c

Providers:
  drivers/dma/sprd-dma.c - sprd_dma_prep_slave_sg() casts context to
    struct sprd_dma_linklist * to set up a linked list descriptor chain.
  drivers/dma/ti/k3-udma.c - udma_prep_slave_sg() passes context down
    to internal sub-functions for normal, PKTDMA, and BCDMA variants.
  drivers/dma/xilinx/xilinx_dma.c - xilinx_dma_prep_slave_sg() and
    xilinx_mcdma_prep_slave_sg() both cast context to u32 *app_w to
    write APP words into DMA descriptors.

Add dmaengine_prep_slave_sg_context() as a wrapper so consumers do not
need to access the DMA engine callback pointer directly.  This is a
preparatory step toward making DMA engine provider internals private.

Make it as deprecated.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 include/linux/dmaengine.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index c3a49a33307c6..b4589cad6d742 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -1084,6 +1084,19 @@ dmaengine_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
 	return dmaengine_prep_config_sg(chan, sgl, sg_len, dir, flags, NULL);
 }
 
+/* Depercated, don't use it except sound/soc/sprd/ */
+static inline struct dma_async_tx_descriptor *
+dmaengine_prep_slave_sg_context(struct dma_chan *chan, struct scatterlist *sgl,
+				unsigned int sg_len, enum dma_transfer_direction dir,
+				unsigned long flags, void *context)
+{
+	if (!chan->device->device_prep_slave_sg)
+		return NULL;
+
+	return chan->device->device_prep_slave_sg(chan, sgl, sg_len, dir,
+						  flags, context);
+}
+
 /**
  * dmaengine_prep_config_sg_safe - prepare a scatter-gather DMA transfer
  *                                 with atomic slave configuration update

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] ASoC: sprd: replace direct ->device_prep*() calls with standard DMA engine API
  2026-09-17 20:08 [PATCH 0/2] dmaengine: add dmaengine_prep_slave_sg_context() API Frank.Li
  2026-09-17 20:08 ` [PATCH 1/2] dmaengine: add dmaengine_prep_slave_sg_context() to wrap prep_slave_sg Frank.Li
@ 2026-09-17 20:08 ` Frank.Li
  1 sibling, 0 replies; 4+ messages in thread
From: Frank.Li @ 2026-09-17 20:08 UTC (permalink / raw)
  To: Vinod Koul, Frank Li, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Orson Zhai, Baolin Wang, Chunyan Zhang
  Cc: dmaengine, linux-kernel, linux-sound, imx, Frank Li

From: Frank Li <Frank.Li@nxp.com>

DMA engine consumers must not call the channel's device_prep_*() function
pointers directly. Use the standard dmaengine wrapper APIs instead.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
 sound/soc/sprd/sprd-pcm-compress.c | 6 +++---
 sound/soc/sprd/sprd-pcm-dma.c      | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/sound/soc/sprd/sprd-pcm-compress.c b/sound/soc/sprd/sprd-pcm-compress.c
index e5249924b54d9..649e59462935d 100644
--- a/sound/soc/sprd/sprd-pcm-compress.c
+++ b/sound/soc/sprd/sprd-pcm-compress.c
@@ -235,9 +235,9 @@ static int sprd_platform_compr_dma_config(struct snd_soc_component *component,
 	 * We configure the DMA request mode, interrupt mode, channel
 	 * mode and channel trigger mode by the flags.
 	 */
-	dma->desc = dma->chan->device->device_prep_slave_sg(dma->chan, sg,
-							    sg_num, dir,
-							    flags, &link);
+	dma->desc = dmaengine_prep_slave_sg_context(dma->chan, sg,
+						    sg_num, dir,
+						    flags, &link);
 	if (!dma->desc) {
 		dev_err(dev, "failed to prepare slave sg\n");
 		ret = -ENOMEM;
diff --git a/sound/soc/sprd/sprd-pcm-dma.c b/sound/soc/sprd/sprd-pcm-dma.c
index 2d5ffbe17e814..d31afbebfbd0e 100644
--- a/sound/soc/sprd/sprd-pcm-dma.c
+++ b/sound/soc/sprd/sprd-pcm-dma.c
@@ -276,9 +276,9 @@ static int sprd_pcm_hw_params(struct snd_soc_component *component,
 		 */
 		flags = SPRD_DMA_FLAGS(SPRD_DMA_CHN_MODE_NONE, SPRD_DMA_NO_TRG,
 				       SPRD_DMA_FRAG_REQ, SPRD_DMA_TRANS_INT);
-		data->desc = chan->device->device_prep_slave_sg(chan, sg,
-								sg_num, dir,
-								flags, &link);
+		data->desc = dmaengine_prep_slave_sg_context(chan, sg,
+							     sg_num, dir,
+							     flags, &link);
 		if (!data->desc) {
 			dev_err(component->dev, "failed to prepare slave sg\n");
 			ret = -ENOMEM;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] dmaengine: add dmaengine_prep_slave_sg_context() to wrap prep_slave_sg
  2026-09-17 20:08 ` [PATCH 1/2] dmaengine: add dmaengine_prep_slave_sg_context() to wrap prep_slave_sg Frank.Li
@ 2026-09-17 20:15   ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-09-17 20:15 UTC (permalink / raw)
  To: Frank.Li; +Cc: imx, Frank.Li, dmaengine, vkoul

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] dmaengine: missing NULL pointer checks in dmaengine_prep_slave_sg_context()
- [Low] dmaengine: missing __deprecated attribute on dmaengine_prep_slave_sg_context()
- [Low] dmaengine: typo 'Depercated' in API comment
--

commit 624ba4c53934aaa9d35d6692c60ed829474f761a
Author: Frank Li <Frank.Li@nxp.com>

dmaengine: add dmaengine_prep_slave_sg_context() to wrap prep_slave_sg

This adds a wrapper function for dmaengine_prep_slave_sg_context() to allow
certain consumers and providers to use the context argument without accessing
the DMA engine callback pointer directly. It also prepares to make the DMA
engine provider internals private, and marks the new wrapper as deprecated.

> diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
> index c3a49a33307c6..b4589cad6d742 100644
> --- a/include/linux/dmaengine.h
> +++ b/include/linux/dmaengine.h
> @@ -1084,6 +1084,19 @@ dmaengine_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
>  	return dmaengine_prep_config_sg(chan, sgl, sg_len, dir, flags, NULL);
>  }
>  
> +/* Depercated, don't use it except sound/soc/sprd/ */

[Severity: Low]
This isn't a bug, but there's a typo in the comment: "Depercated" instead of
"Deprecated".

> +static inline struct dma_async_tx_descriptor *

[Severity: Low]
Since the comment and commit message note this function is deprecated, should
it be marked with the __deprecated compiler attribute so that any new usages
trigger a compile-time warning?

> +dmaengine_prep_slave_sg_context(struct dma_chan *chan, struct scatterlist *sgl,
> +				unsigned int sg_len, enum dma_transfer_direction dir,
> +				unsigned long flags, void *context)
> +{
> +	if (!chan->device->device_prep_slave_sg)

[Severity: Medium]
Does this expose callers to a NULL pointer dereference if an uninitialized
or invalid channel is passed?

Other public wrappers in the DMA engine API, such as dmaengine_prep_config_sg(),
explicitly check if (!chan || !chan->device) before accessing the device
pointer.

Should this function include the same safeguard?

> +		return NULL;
> +
> +	return chan->device->device_prep_slave_sg(chan, sgl, sg_len, dir,
> +						  flags, context);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260917-b4-dmaengine-prep-slave-sg-v1-0-239c12864143@nxp.com?part=1

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-17 20:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-17 20:08 [PATCH 0/2] dmaengine: add dmaengine_prep_slave_sg_context() API Frank.Li
2026-09-17 20:08 ` [PATCH 1/2] dmaengine: add dmaengine_prep_slave_sg_context() to wrap prep_slave_sg Frank.Li
2026-09-17 20:15   ` sashiko-bot
2026-09-17 20:08 ` [PATCH 2/2] ASoC: sprd: replace direct ->device_prep*() calls with standard DMA engine API Frank.Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox