* [PATCH 0/3] dmaengine: edma: fix vchan cleanup and improvement
@ 2026-11-23 1:32 Peng Fan (OSS)
2026-11-23 1:32 ` [PATCH 1/3] dmaengine: fsl-edma: unregister channels before vchan cleanup Peng Fan (OSS)
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Peng Fan (OSS) @ 2026-11-23 1:32 UTC (permalink / raw)
To: Frank Li, Vinod Koul; +Cc: Frank Li, imx, dmaengine, Peng Fan
To avoid delaying the fix because of the iommu discussion [1], I separate three
patches that not relavant to iommu from patchset [2].
Patch 1 is a fix, patch 2,3 are for cleanup.
All three patches have been reviewed by Frank Li. There might be a sashiko
warning about BIT_ULL in patch 2, that is false alarm, ignore it.
Detailed information could be found in each patch commit log.
[1] https://lore.kernel.org/all/20261117180945.GE2606445@ziepe.ca/
[2]https://lore.kernel.org/all/20261116-edma-iommu-v3-v7-0-32794ba8efbf@nxp.com/
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
Peng Fan (3):
dmaengine: fsl-edma: unregister channels before vchan cleanup
dmaengine: fsl-edma: use BIT_ULL for 64-bit channel mask
dmaengine: fsl-edma: use dmaengine_get_dma_device()
drivers/dma/fsl-edma-common.c | 10 +++++-----
drivers/dma/fsl-edma-main.c | 26 ++++++++++++++++++--------
2 files changed, 23 insertions(+), 13 deletions(-)
---
base-commit: 909ef7a9a30fa139e69e555e3606680f5cca7726
change-id: 20261123-edma-fixes-8493253613ca
Best regards,
--
Peng Fan <peng.fan@nxp.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] dmaengine: fsl-edma: unregister channels before vchan cleanup
2026-11-23 1:32 [PATCH 0/3] dmaengine: edma: fix vchan cleanup and improvement Peng Fan (OSS)
@ 2026-11-23 1:32 ` Peng Fan (OSS)
2026-11-23 1:32 ` [PATCH 2/3] dmaengine: fsl-edma: use BIT_ULL for 64-bit channel mask Peng Fan (OSS)
2026-11-23 1:32 ` [PATCH 3/3] dmaengine: fsl-edma: use dmaengine_get_dma_device() Peng Fan (OSS)
2 siblings, 0 replies; 6+ messages in thread
From: Peng Fan (OSS) @ 2026-11-23 1:32 UTC (permalink / raw)
To: Frank Li, Vinod Koul; +Cc: Frank Li, imx, dmaengine, Peng Fan
From: Peng Fan <peng.fan@nxp.com>
Since commit 4035726a6b72 ("dmaengine: fsl-edma: Use managed API
dmaenginem_async_device_register()"), dma_async_device_unregister() runs
as a devres action after fsl_edma_remove(). However, fsl_edma_remove()
still calls fsl_edma_cleanup_vchan() first, which removes every channel
from dma_dev.channels. When the devres action later runs,
dma_async_device_unregister() sees an empty channel list and never
unregisters the channel devices. They remain visible in /sys/class/dma.
Keep the vchan cleanup, but register it as a devres action before
dmaenginem_async_device_register(). Devres actions run in reverse
order, so the DMA channels are unregistered first and the vchan list is
cleaned up afterwards. Remove the premature cleanup call from
fsl_edma_remove().
Fixes: 4035726a6b72 ("dmaengine: fsl-edma: Use managed API dmaenginem_async_device_register()")
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/dma/fsl-edma-main.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c
index da5139911488..7f82dcb7831d 100644
--- a/drivers/dma/fsl-edma-main.c
+++ b/drivers/dma/fsl-edma-main.c
@@ -31,6 +31,11 @@ static void fsl_edma_synchronize(struct dma_chan *chan)
vchan_synchronize(&fsl_chan->vchan);
}
+static void fsl_edma_cleanup_vchan_action(void *data)
+{
+ fsl_edma_cleanup_vchan(data);
+}
+
static irqreturn_t fsl_edma_tx_handler(int irq, void *dev_id)
{
struct fsl_edma_engine *fsl_edma = dev_id;
@@ -881,6 +886,12 @@ static int fsl_edma_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, fsl_edma);
+ ret = devm_add_action_or_reset(&pdev->dev,
+ fsl_edma_cleanup_vchan_action,
+ &fsl_edma->dma_dev);
+ if (ret)
+ return ret;
+
ret = dmaenginem_async_device_register(&fsl_edma->dma_dev);
if (ret)
return dev_err_probe(&pdev->dev, ret,
@@ -905,7 +916,6 @@ static void fsl_edma_remove(struct platform_device *pdev)
struct fsl_edma_engine *fsl_edma = platform_get_drvdata(pdev);
fsl_edma_irq_exit(pdev, fsl_edma);
- fsl_edma_cleanup_vchan(&fsl_edma->dma_dev);
}
static int fsl_edma_suspend_late(struct device *dev)
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] dmaengine: fsl-edma: use BIT_ULL for 64-bit channel mask
2026-11-23 1:32 [PATCH 0/3] dmaengine: edma: fix vchan cleanup and improvement Peng Fan (OSS)
2026-11-23 1:32 ` [PATCH 1/3] dmaengine: fsl-edma: unregister channels before vchan cleanup Peng Fan (OSS)
@ 2026-11-23 1:32 ` Peng Fan (OSS)
2026-11-23 1:34 ` sashiko-bot
2026-11-23 1:32 ` [PATCH 3/3] dmaengine: fsl-edma: use dmaengine_get_dma_device() Peng Fan (OSS)
2 siblings, 1 reply; 6+ messages in thread
From: Peng Fan (OSS) @ 2026-11-23 1:32 UTC (permalink / raw)
To: Frank Li, Vinod Koul; +Cc: Frank Li, imx, dmaengine, Peng Fan
From: Peng Fan <peng.fan@nxp.com>
chan_masked is a u64 bitmap, but several checks use BIT(), which uses
unsigned long and overflows on 32-bit architectures for channels >= 32.
Use BIT_ULL() so the upper channels are tested correctly.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/dma/fsl-edma-main.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c
index 7f82dcb7831d..818b9b986f13 100644
--- a/drivers/dma/fsl-edma-main.c
+++ b/drivers/dma/fsl-edma-main.c
@@ -123,7 +123,7 @@ static irqreturn_t fsl_edma3_err_handler_shared(int irq, void *dev_id)
unsigned int ch;
for (ch = 0; ch < fsl_edma->n_chans; ch++) {
- if (fsl_edma->chan_masked & BIT(ch))
+ if (fsl_edma->chan_masked & BIT_ULL(ch))
continue;
fsl_edma3_err_check(&fsl_edma->chans[ch]);
@@ -397,7 +397,7 @@ static int fsl_edma3_irq_init(struct platform_device *pdev, struct fsl_edma_engi
struct fsl_edma_chan *fsl_chan = &fsl_edma->chans[i];
- if (fsl_edma->chan_masked & BIT(i))
+ if (fsl_edma->chan_masked & BIT_ULL(i))
continue;
/* request channel irq */
@@ -641,7 +641,7 @@ static void fsl_edma3_detach_pd(struct fsl_edma_engine *fsl_edma)
int i;
for (i = 0; i < fsl_edma->n_chans; i++) {
- if (fsl_edma->chan_masked & BIT(i))
+ if (fsl_edma->chan_masked & BIT_ULL(i))
continue;
fsl_chan = &fsl_edma->chans[i];
if (fsl_chan->pd_dev_link)
@@ -669,7 +669,7 @@ static int fsl_edma3_attach_pd(struct platform_device *pdev, struct fsl_edma_eng
dev = &pdev->dev;
for (i = 0; i < fsl_edma->n_chans; i++) {
- if (fsl_edma->chan_masked & BIT(i))
+ if (fsl_edma->chan_masked & BIT_ULL(i))
continue;
fsl_chan = &fsl_edma->chans[i];
@@ -797,7 +797,7 @@ static int fsl_edma_probe(struct platform_device *pdev)
struct fsl_edma_chan *fsl_chan = &fsl_edma->chans[i];
int len;
- if (fsl_edma->chan_masked & BIT(i))
+ if (fsl_edma->chan_masked & BIT_ULL(i))
continue;
snprintf(fsl_chan->chan_name, sizeof(fsl_chan->chan_name), "%s-CH%02d",
@@ -927,7 +927,7 @@ static int fsl_edma_suspend_late(struct device *dev)
for (i = 0; i < fsl_edma->n_chans; i++) {
fsl_chan = &fsl_edma->chans[i];
- if (fsl_edma->chan_masked & BIT(i))
+ if (fsl_edma->chan_masked & BIT_ULL(i))
continue;
spin_lock_irqsave(&fsl_chan->vchan.lock, flags);
/* Make sure chan is idle or will force disable. */
@@ -953,7 +953,7 @@ static int fsl_edma_resume_early(struct device *dev)
for (i = 0; i < fsl_edma->n_chans; i++) {
fsl_chan = &fsl_edma->chans[i];
- if (fsl_edma->chan_masked & BIT(i))
+ if (fsl_edma->chan_masked & BIT_ULL(i))
continue;
fsl_chan->pm_state = RUNNING;
edma_write_tcdreg(fsl_chan, 0, csr);
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] dmaengine: fsl-edma: use dmaengine_get_dma_device()
2026-11-23 1:32 [PATCH 0/3] dmaengine: edma: fix vchan cleanup and improvement Peng Fan (OSS)
2026-11-23 1:32 ` [PATCH 1/3] dmaengine: fsl-edma: unregister channels before vchan cleanup Peng Fan (OSS)
2026-11-23 1:32 ` [PATCH 2/3] dmaengine: fsl-edma: use BIT_ULL for 64-bit channel mask Peng Fan (OSS)
@ 2026-11-23 1:32 ` Peng Fan (OSS)
2026-11-23 1:34 ` sashiko-bot
2 siblings, 1 reply; 6+ messages in thread
From: Peng Fan (OSS) @ 2026-11-23 1:32 UTC (permalink / raw)
To: Frank Li, Vinod Koul; +Cc: Frank Li, imx, dmaengine, Peng Fan
From: Peng Fan <peng.fan@nxp.com>
Use dmaengine_get_dma_device() instead of chan->device->dev when creating
the TCD pool and when mapping the slave resource. This lets the driver use
the per-channel device once per-channel IOMMU support enables it, without
changing behaviour for existing users.
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/dma/fsl-edma-common.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/dma/fsl-edma-common.c b/drivers/dma/fsl-edma-common.c
index 513b0f4e5be2..62cd60179bc6 100644
--- a/drivers/dma/fsl-edma-common.c
+++ b/drivers/dma/fsl-edma-common.c
@@ -310,10 +310,10 @@ int fsl_edma_resume(struct dma_chan *chan)
static void fsl_edma_unprep_slave_dma(struct fsl_edma_chan *fsl_chan)
{
+ struct device *dev = dmaengine_get_dma_device(&fsl_chan->vchan.chan);
+
if (fsl_chan->dma_dir != DMA_NONE)
- dma_unmap_resource(fsl_chan->vchan.chan.device->dev,
- fsl_chan->dma_dev_addr,
- fsl_chan->dma_dev_size,
+ dma_unmap_resource(dev, fsl_chan->dma_dev_addr, fsl_chan->dma_dev_size,
fsl_chan->dma_dir, 0);
fsl_chan->dma_dir = DMA_NONE;
}
@@ -321,7 +321,7 @@ static void fsl_edma_unprep_slave_dma(struct fsl_edma_chan *fsl_chan)
static bool fsl_edma_prep_slave_dma(struct fsl_edma_chan *fsl_chan,
enum dma_transfer_direction dir)
{
- struct device *dev = fsl_chan->vchan.chan.device->dev;
+ struct device *dev = dmaengine_get_dma_device(&fsl_chan->vchan.chan);
enum dma_data_direction dma_dir;
phys_addr_t addr = 0;
u32 size = 0;
@@ -1090,7 +1090,7 @@ int fsl_edma_alloc_chan_resources(struct dma_chan *chan)
if (fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_HAS_CHCLK)
clk_prepare_enable(fsl_chan->clk);
- fsl_chan->tcd_pool = dma_pool_create("tcd_pool", chan->device->dev,
+ fsl_chan->tcd_pool = dma_pool_create("tcd_pool", dmaengine_get_dma_device(chan),
fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_TCD64 ?
sizeof(struct fsl_edma_hw_tcd64) : sizeof(struct fsl_edma_hw_tcd),
32, 0);
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] dmaengine: fsl-edma: use dmaengine_get_dma_device()
2026-11-23 1:32 ` [PATCH 3/3] dmaengine: fsl-edma: use dmaengine_get_dma_device() Peng Fan (OSS)
@ 2026-11-23 1:34 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-23 1:34 UTC (permalink / raw)
To: Peng Fan (OSS); +Cc: imx, dmaengine, vkoul, Frank.Li
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] dmaengine: fsl-edma: unchecked dma_pool_create() in
fsl_edma_alloc_chan_resources() [1]
--
commit d7d84b7032569e7e063763bff448d75503da9441
Author: Peng Fan <peng.fan@nxp.com>
dmaengine: fsl-edma: use dmaengine_get_dma_device()
This commit uses dmaengine_get_dma_device() instead of chan->device->dev
when creating the TCD pool and mapping slave DMA resources.
> diff --git a/drivers/dma/fsl-edma-common.c b/drivers/dma/fsl-edma-common.c
> index 513b0f4e5be21..62cd60179bc6f 100644
> --- a/drivers/dma/fsl-edma-common.c
> +++ b/drivers/dma/fsl-edma-common.c
[ ... ]
> @@ -1090,7 +1090,7 @@ int fsl_edma_alloc_chan_resources(struct dma_chan *chan)
> if (fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_HAS_CHCLK)
> clk_prepare_enable(fsl_chan->clk);
>
> - fsl_chan->tcd_pool = dma_pool_create("tcd_pool", chan->device->dev,
> + fsl_chan->tcd_pool = dma_pool_create("tcd_pool", dmaengine_get_dma_device(chan),
> fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_TCD64 ?
> sizeof(struct fsl_edma_hw_tcd64) : sizeof(struct fsl_edma_hw_tcd),
> 32, 0);
[Severity: High]
This problem wasn't introduced by this patch, but can a failure in
dma_pool_create() lead to a NULL pointer dereference [1]?
fsl_edma_alloc_chan_resources() does not check fsl_chan->tcd_pool for NULL
and still returns 0. A subsequent transfer preparation then passes the
NULL fsl_chan->tcd_pool to dma_pool_alloc() in fsl_edma_alloc_desc().
[1] https://sashiko.dev/#/bug/linux-39a3675f-2d52-4af1-8fbc-609bc1c22d2a
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-edma-fixes-v1-0-59d5da374a16@nxp.com?part=3
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] dmaengine: fsl-edma: use BIT_ULL for 64-bit channel mask
2026-11-23 1:32 ` [PATCH 2/3] dmaengine: fsl-edma: use BIT_ULL for 64-bit channel mask Peng Fan (OSS)
@ 2026-11-23 1:34 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-23 1:34 UTC (permalink / raw)
To: Peng Fan (OSS); +Cc: imx, dmaengine, vkoul, Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dmaengine: fsl-edma: missing Fixes: trailer for chan_masked
BIT_ULL() fix
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] dmaengine: fsl-edma: use-after-free in
fsl_edma3_detach_pd() [1]
--
commit 61ad7f34b4fcfc1b5709f370095dce7e4b0ea1d5
Author: Peng Fan <peng.fan@nxp.com>
> dmaengine: fsl-edma: use BIT_ULL for 64-bit channel mask
>
> chan_masked is a u64 bitmap, but several checks use BIT(), which uses
> unsigned long and overflows on 32-bit architectures for channels >= 32.
> Use BIT_ULL() so the upper channels are tested correctly.
>
> Reviewed-by: Frank Li <Frank.Li@nxp.com>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
[Severity: Low]
This fixes the 32-bit BIT() overflow on the 64-bit chan_masked bitmap
introduced in commit 72f5801a4e2b ("dmaengine: fsl-edma: integrate v3
support") and replicated in commits 2838a897654c ("dmaengine: fsl-edma: Do
not suspend and resume the masked dma channel when the system is
sleeping"), ccfa3131d4a0 ("dmaengine: fsl-edma: implement the cleanup path
of fsl_edma3_attach_pd()"), and d175222f5e90 ("dmaegnine: fsl-edma: add
edma error interrupt handler"). Should this include a Fixes: tag for
72f5801a4e2b ("dmaengine: fsl-edma: integrate v3 support") (and optionally
for the follow-up commits)?
> diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c
> index 7f82dcb7831d0..818b9b986f131 100644
> --- a/drivers/dma/fsl-edma-main.c
> +++ b/drivers/dma/fsl-edma-main.c
[ ... ]
> @@ -641,7 +641,7 @@ static void fsl_edma3_detach_pd(struct fsl_edma_engine *fsl_edma)
> int i;
>
> for (i = 0; i < fsl_edma->n_chans; i++) {
> - if (fsl_edma->chan_masked & BIT(i))
> + if (fsl_edma->chan_masked & BIT_ULL(i))
> continue;
> fsl_chan = &fsl_edma->chans[i];
> if (fsl_chan->pd_dev_link)
[Severity: Critical]
This problem wasn't introduced by this patch, but does
fsl_edma3_detach_pd() trigger a use-after-free on fsl_chan->pd_dev
[1]?
drivers/dma/fsl-edma-main.c:fsl_edma3_detach_pd() {
...
if (fsl_chan->pd_dev_link)
device_link_del(fsl_chan->pd_dev_link);
if (fsl_chan->pd_dev) {
dev_pm_domain_detach(fsl_chan->pd_dev, false);
pm_runtime_dont_use_autosuspend(fsl_chan->pd_dev);
pm_runtime_set_suspended(fsl_chan->pd_dev);
}
...
}
After device_link_del() removes the stateless device link,
dev_pm_domain_detach() calls genpd_dev_pm_detach() -> device_unregister(),
which drops the last reference to the virtual genpd device and frees
fsl_chan->pd_dev. The subsequent pm_runtime_dont_use_autosuspend() and
pm_runtime_set_suspended() calls then lock and modify the freed device
during an attach error, probe failure, or driver unbind.
[1] https://sashiko.dev/#/bug/linux-274f4f33-0d23-4b6b-a957-25b9d8ad2f6a
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-edma-fixes-v1-0-59d5da374a16@nxp.com?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-23 1:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 1:32 [PATCH 0/3] dmaengine: edma: fix vchan cleanup and improvement Peng Fan (OSS)
2026-11-23 1:32 ` [PATCH 1/3] dmaengine: fsl-edma: unregister channels before vchan cleanup Peng Fan (OSS)
2026-11-23 1:32 ` [PATCH 2/3] dmaengine: fsl-edma: use BIT_ULL for 64-bit channel mask Peng Fan (OSS)
2026-11-23 1:34 ` sashiko-bot
2026-11-23 1:32 ` [PATCH 3/3] dmaengine: fsl-edma: use dmaengine_get_dma_device() Peng Fan (OSS)
2026-11-23 1:34 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox