* [PATCH v8 0/5] add runtime suspend/resume support
@ 2026-11-25 10:58 joy.zou
2026-11-25 10:58 ` [PATCH v8 1/5] dmaengine: fsl-edma: use devm_clk_get_optional_enabled() for channel clock joy.zou
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: joy.zou @ 2026-11-25 10:58 UTC (permalink / raw)
To: Frank Li, Vinod Koul, Joe Hattori
Cc: Joy Zou, Frank Li, imx, dmaengine, linux-kernel, Joy Zou
Clean up driver FLAGs and introduce runtime suspend and resume support for
FSL eDMA.
Signed-off-by: Joy Zou <joy.zou@oss.nxp.com>
---
Changes in v8:
- deleting clk_disable_unprepare(fsl_chan->clk) avoids a double-disable
warning, However, the clock stays on and won't be turned off until
driver removed, which increases power consumption for patch #1.
- add a new patch to prevent fsl_edma_alloc_chan_resources() from failing
when CONFIG_PM is enabled for patch #4.
- changed the pm_runtime_get_if_active() return value check from <= 0 to == 0
to account for the CONFIG_PM=n case for patch #5.
- remove reduntant pd_dev pm_runtime handler due to bind the dma channel
for patch #5.
- add the pm_runtime_get_if_active() check for fsl_edma3_err_check() for patch #5.
- add chan_masked check for fsl_edma3_or_err_handler, fsl_edma_tx_handler
and fsl_edma_err_handler for patch #5.
- add synchronize_irq() for txirq_16_3 for patch #5.
- remove the manual device_link_del() call to avoid use-after-free for patch #5.
- Link to v7: https://patch.msgid.link/20261023-b4-edma-runtime-opt-mo-v7-0-418e53c5f9b7@oss.nxp.com
Changes in V7:
- replace devm_clk_get_optional() with devm_clk_get_optional_enable() for
patch #1 and #2.
- replace devm_clk_get_optional() with devm_clk_bulk_get_optional_enable()
for patch #3.
- replace devm_clk_get_optional_enable() with devm_clk_get_optional() for patch #4.
- replace devm_clk_bulk_get_optional_enable() with devm_clk_bulk_get_optional()
for patch #4.
- use PM_RUNTIME_ACQUIRE_IF_ENABLED()/PM_RUNTIME_ACQUIRE_ERR() guards to
replace pm_runtime_resume_and_get() and the manual error handling for both
the eDMA engine and per-channel devices.
- move dmaenginem_async_device_register() after runtime PM is enabled.
- move fsl_edma->drvdata->setup_irq() to the end of probe() and use
dev_err_probe() on failure.
- check "irq > 0" instead of "irq" before synchronize_irq() in
fsl_edma_chan_runtime_suspend().
- add fsl_chan txirq and errirq synchronize_irq() check in fsl_edma_chan_runtime_suspend().
- add comments explaining the pm_runtime_get_if_active() checks in the interrupt handlers.
- dropped patch #5 since this is a pre-existing issue that will be fixed in a separate patch.
- Link to v6: https://lore.kernel.org/r/20260701-b4-edma-runtime-opt-v6-0-354ff4229c00@oss.nxp.com
Changes in V6:
- add synchronize_irq() before disabling the channel clock in fsl_edma_chan_runtime_suspend()
per AI review comments.
- add pm_runtime_get_if_active() in interrupt handlers to ensure registers can be accessed
correctly per AI review comments.
- remove manual fsl_edma3_detach_pd() call when device_link_add() fails. The devres
framework will handle cleanup automatically on probe failure per AI review comments.
- clear fsl_chan->pd_dev_link after freeing the device link to prevent potential
use-after-free issues per AI review comments..
- move fsl_edma->drvdata->setup_irq() atfer edma engine pm_runtime_resume_and_get().
- replace devm_clk_bulk_get_optional_enable() with devm_clk_get_optional()
and clk_bulk_prepare_enable() in order to use runtime PM for power
management later.
- replace devm_clk_get_optional_enable() with devm_clk_get_optional()
and devm_clk_prepare_enable() in order to use runtime PM for power
management later for patch #1 and #2.
- add new patch #5 fix use-after-free issue per AI review comments.
- modify the commit message for patch #1,#2 and #3.
- add Reviewed-by tag for patch #1,#2 and #3.
- Link to v5: https://lore.kernel.org/r/20260513-b4-b4-edma-runtime-opt-v5-0-1e595bfb8423@nxp.com
Changes in V5:
- add three new patches, two of which replace devm_clk_get_enabled() with devm_clk_get_optional_enabled(),
and the other convert to clk bulk API.
- remove unnecessary flags FSL_EDMA_DRV_HAS_CHCLK and FSL_EDMA_DRV_HAS_DMACLK.
- remove redundant clk_disable_unprepare() due to the pm_runtime_put_sync_suspend() added.
- use devm_pm_runtime_enable() to replace pm_runtime_enable() and add return value check.
- add return value check for pm_runtime_get_sync().
- replace pm_runtime_get_sync() with pm_runtime_resume_and_get().
- replace DMAMUX clock handling with bulk clock API for edma engine runtime suspend/resume.
- remove dev_pm_domain_detach() when device_link_add() fail because the fsl_edma3_detach_pd()
also call dev_pm_domain_detach().
- remove device_link_add() DL_FLAG_RPM_ACTIVE flag and pm_runtime_put_sync_suspend().
- add clk_bulk_disable_unprepare() for clk_prepare_enable() fail in fsl_edma_runtime_resume().
- remove the extra space before RUNTIME_PM_OPS.
- add skip channel comments for system suspend.
- add clk_disable_unprepare() for dmaclk at the end of probe function.
- add clk_bulk_disable_unprepare() for muxclk at the end of probe function.
- Link to v4: https://lore.kernel.org/imx/20251017-b4-edma-runtime-v4-1-87c64dd30229@nxp.com/
Changes for V4:
- fix a typo dmaegnine/dmaengine in the subject.
- Link to v3: https://lore.kernel.org/imx/20250912-b4-edma-runtime-v3-1-be22f7161745@nxp.com/
Changes for V3:
- rebased onto commit 8f21d9da4670 ("Add linux-next specific files for 20250911")
to align with latest changes.
- Remove pm_runtime_dont_use_autosuspend() from fsl_edma3_detach_pd().
because the autosuspend is not used.
- Move some edma channel registers initialization after the chan_dev
pm_runtime_enable().
- Add clk_prepare_enable() return check in fsl_edma_runtime_resume.
- Add flag FSL_EDMA_DRV_HAS_DMACLK check in fsl_edma_runtime_resume/suspend().
- Link to v2: https://lore.kernel.org/imx/20241226052643.1951886-1-joy.zou@nxp.com/
Changes for V2:
- drop ret from fsl_edma_chan_runtime_suspend().
- drop ret from fsl_edma_chan_runtime_resume() and return clk_prepare_enable().
- add review tag
- Link to v1: https://lore.kernel.org/imx/20241220021109.2102294-1-joy.zou@nxp.com/
To: Frank Li <Frank.Li@nxp.com>
To: Vinod Koul <vkoul@kernel.org>
To: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Cc: Frank Li <Frank.Li@kernel.org>
Cc: imx@lists.linux.dev
Cc: dmaengine@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
Joy Zou (5):
dmaengine: fsl-edma: use devm_clk_get_optional_enabled() for channel clock
dmaengine: fsl-edma: use devm_clk_get_optional() for DMA engine clock
dmaengine: fsl-edma: convert DMAMUX clock handling to bulk clock API
dmaengine: mcf-edma: enable runtime PM for eDMA engine and channel
dmaengine: fsl-edma: add runtime suspend/resume support
drivers/dma/fsl-edma-common.c | 14 +-
drivers/dma/fsl-edma-common.h | 4 +-
drivers/dma/fsl-edma-main.c | 340 ++++++++++++++++++++++++++++++++----------
drivers/dma/mcf-edma-main.c | 11 ++
4 files changed, 278 insertions(+), 91 deletions(-)
---
base-commit: 2637bdec0535a2044cd830eba9a79363651d9043
change-id: 20260811-b4-edma-runtime-opt-mo-0d19aeeb5dbe
Best regards,
--
Joy Zou <joy.zou@oss.nxp.com>
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v8 1/5] dmaengine: fsl-edma: use devm_clk_get_optional_enabled() for channel clock 2026-11-25 10:58 [PATCH v8 0/5] add runtime suspend/resume support joy.zou @ 2026-11-25 10:58 ` joy.zou 2026-11-25 10:58 ` [PATCH v8 2/5] dmaengine: fsl-edma: use devm_clk_get_optional() for DMA engine clock joy.zou ` (3 subsequent siblings) 4 siblings, 0 replies; 8+ messages in thread From: joy.zou @ 2026-11-25 10:58 UTC (permalink / raw) To: Frank Li, Vinod Koul, Joe Hattori Cc: Joy Zou, Frank Li, imx, dmaengine, linux-kernel, Joy Zou From: Joy Zou <joy.zou@nxp.com> The channel clock is optional and not present on all platforms. Replace devm_clk_get_enabled() with devm_clk_get_optional_enabled(), and remove FSL_EDMA_DRV_HAS_CHCLK flag to simplify clock handling. Prepare to add channel runtime pm support. Reviewed-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Joy Zou <joy.zou@nxp.com> --- Changes for v8: - Deleting clk_disable_unprepare(fsl_chan->clk) avoids a double-disable warning, However, the clock stays on and won't be turned off until driver removed, which increases power consumption. Changes for v7: - Replace devm_clk_get_optional() with devm_clk_get_optional_enable(). Changes for v6: - Replace devm_clk_get_optional_enable() with devm_clk_get_optional() and devm_clk_prepare_enable() in order to use runtime PM for power management later. - Modify the commit message. - Add Reviewed-by tag. - Link to v5: https://lore.kernel.org/imx/20260513-b4-b4-edma-runtime-opt-v5-0-1e595bfb8423@nxp.com/ --- drivers/dma/fsl-edma-common.c | 4 +--- drivers/dma/fsl-edma-common.h | 1 - drivers/dma/fsl-edma-main.c | 18 +++++------------- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/drivers/dma/fsl-edma-common.c b/drivers/dma/fsl-edma-common.c index 513b0f4e5be2..4f7a942673eb 100644 --- a/drivers/dma/fsl-edma-common.c +++ b/drivers/dma/fsl-edma-common.c @@ -1087,9 +1087,7 @@ int fsl_edma_alloc_chan_resources(struct dma_chan *chan) struct fsl_edma_chan *fsl_chan = to_fsl_edma_chan(chan); int ret = 0; - if (fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_HAS_CHCLK) - clk_prepare_enable(fsl_chan->clk); - + clk_prepare_enable(fsl_chan->clk); fsl_chan->tcd_pool = dma_pool_create("tcd_pool", chan->device->dev, fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_TCD64 ? sizeof(struct fsl_edma_hw_tcd64) : sizeof(struct fsl_edma_hw_tcd), diff --git a/drivers/dma/fsl-edma-common.h b/drivers/dma/fsl-edma-common.h index cbb077e98f55..4332b2b2e1df 100644 --- a/drivers/dma/fsl-edma-common.h +++ b/drivers/dma/fsl-edma-common.h @@ -213,7 +213,6 @@ struct fsl_edma_desc { #define FSL_EDMA_DRV_WRAP_IO BIT(3) #define FSL_EDMA_DRV_EDMA64 BIT(4) #define FSL_EDMA_DRV_HAS_PD BIT(5) -#define FSL_EDMA_DRV_HAS_CHCLK BIT(6) #define FSL_EDMA_DRV_HAS_CHMUX BIT(7) #define FSL_EDMA_DRV_MEM_REMOTE BIT(8) /* control and status register is in tcd address space, edma3 reg layout */ diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c index 630285c85482..f0930895d7e0 100644 --- a/drivers/dma/fsl-edma-main.c +++ b/drivers/dma/fsl-edma-main.c @@ -572,8 +572,7 @@ static struct fsl_edma_drvdata imx8qm_data = { }; static struct fsl_edma_drvdata imx8ulp_data = { - .flags = FSL_EDMA_DRV_HAS_CHMUX | FSL_EDMA_DRV_HAS_CHCLK | FSL_EDMA_DRV_HAS_DMACLK | - FSL_EDMA_DRV_EDMA3, + .flags = FSL_EDMA_DRV_HAS_CHMUX | FSL_EDMA_DRV_HAS_DMACLK | FSL_EDMA_DRV_EDMA3, .chreg_space_sz = 0x10000, .chreg_off = 0x10000, .mux_off = 0x10000 + offsetof(struct fsl_edma3_ch_reg, ch_mux), @@ -813,22 +812,15 @@ static int fsl_edma_probe(struct platform_device *pdev) fsl_chan->tcd = fsl_edma->membase + i * drvdata->chreg_space_sz + drvdata->chreg_off + len; fsl_chan->mux_addr = fsl_edma->membase + drvdata->mux_off + i * drvdata->mux_skip; - - if (drvdata->flags & FSL_EDMA_DRV_HAS_CHCLK) { - snprintf(clk_name, sizeof(clk_name), "ch%02d", i); - fsl_chan->clk = devm_clk_get_enabled(&pdev->dev, - (const char *)clk_name); - - if (IS_ERR(fsl_chan->clk)) - return PTR_ERR(fsl_chan->clk); - } + snprintf(clk_name, sizeof(clk_name), "ch%02d", i); + fsl_chan->clk = devm_clk_get_optional_enabled(&pdev->dev, (const char *)clk_name); + if (IS_ERR(fsl_chan->clk)) + return PTR_ERR(fsl_chan->clk); fsl_chan->pdev = pdev; vchan_init(&fsl_chan->vchan, &fsl_edma->dma_dev); edma_write_tcdreg(fsl_chan, cpu_to_le32(0), csr); fsl_edma_chan_mux(fsl_chan, 0, false); - if (fsl_chan->edma->drvdata->flags & FSL_EDMA_DRV_HAS_CHCLK) - clk_disable_unprepare(fsl_chan->clk); } ret = fsl_edma->drvdata->setup_irq(pdev, fsl_edma); -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v8 2/5] dmaengine: fsl-edma: use devm_clk_get_optional() for DMA engine clock 2026-11-25 10:58 [PATCH v8 0/5] add runtime suspend/resume support joy.zou 2026-11-25 10:58 ` [PATCH v8 1/5] dmaengine: fsl-edma: use devm_clk_get_optional_enabled() for channel clock joy.zou @ 2026-11-25 10:58 ` joy.zou 2026-11-25 10:58 ` [PATCH v8 3/5] dmaengine: fsl-edma: convert DMAMUX clock handling to bulk clock API joy.zou ` (2 subsequent siblings) 4 siblings, 0 replies; 8+ messages in thread From: joy.zou @ 2026-11-25 10:58 UTC (permalink / raw) To: Frank Li, Vinod Koul, Joe Hattori Cc: Joy Zou, Frank Li, imx, dmaengine, linux-kernel, Joy Zou From: Joy Zou <joy.zou@nxp.com> The eDMA engine clock is optional and not present on all platforms. Replace devm_clk_get_enabled() with devm_clk_get_optional_enabled(), and remove FSL_EDMA_DRV_HAS_DMACLK flag to simplify clock handling. Prepare to add channel runtime pm support. Reviewed-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Joy Zou <joy.zou@nxp.com> --- Changes for v7: - Replace devm_clk_get_optional() with devm_clk_get_optional_enable(). Changes for v6: - Replace devm_clk_get_optional_enable() with devm_clk_get_optional() and devm_clk_prepare_enable() in order to use runtime PM for power management later. - Modify the commit message. - Add Reviewed-by tag. - Link to v5: https://lore.kernel.org/imx/20260513-b4-b4-edma-runtime-opt-v5-0-1e595bfb8423@nxp.com/ --- drivers/dma/fsl-edma-common.h | 1 - drivers/dma/fsl-edma-main.c | 22 ++++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/dma/fsl-edma-common.h b/drivers/dma/fsl-edma-common.h index 4332b2b2e1df..97b3a9872e90 100644 --- a/drivers/dma/fsl-edma-common.h +++ b/drivers/dma/fsl-edma-common.h @@ -207,7 +207,6 @@ struct fsl_edma_desc { struct fsl_edma_sw_tcd tcd[]; }; -#define FSL_EDMA_DRV_HAS_DMACLK BIT(0) #define FSL_EDMA_DRV_MUX_SWAP BIT(1) #define FSL_EDMA_DRV_CONFIG32 BIT(2) #define FSL_EDMA_DRV_WRAP_IO BIT(3) diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c index f0930895d7e0..6a296fffb837 100644 --- a/drivers/dma/fsl-edma-main.c +++ b/drivers/dma/fsl-edma-main.c @@ -559,7 +559,7 @@ static struct fsl_edma_drvdata imx7ulp_data = { .dmamuxs = 1, .chreg_off = EDMA_TCD, .chreg_space_sz = sizeof(struct fsl_edma_hw_tcd), - .flags = FSL_EDMA_DRV_HAS_DMACLK | FSL_EDMA_DRV_CONFIG32, + .flags = FSL_EDMA_DRV_CONFIG32, .setup_irq = fsl_edma2_irq_init, }; @@ -572,7 +572,7 @@ static struct fsl_edma_drvdata imx8qm_data = { }; static struct fsl_edma_drvdata imx8ulp_data = { - .flags = FSL_EDMA_DRV_HAS_CHMUX | FSL_EDMA_DRV_HAS_DMACLK | FSL_EDMA_DRV_EDMA3, + .flags = FSL_EDMA_DRV_HAS_CHMUX | FSL_EDMA_DRV_EDMA3, .chreg_space_sz = 0x10000, .chreg_off = 0x10000, .mux_off = 0x10000 + offsetof(struct fsl_edma3_ch_reg, ch_mux), @@ -581,14 +581,14 @@ static struct fsl_edma_drvdata imx8ulp_data = { }; static struct fsl_edma_drvdata imx93_data3 = { - .flags = FSL_EDMA_DRV_HAS_DMACLK | FSL_EDMA_DRV_EDMA3 | FSL_EDMA_DRV_ERRIRQ_SHARE, + .flags = FSL_EDMA_DRV_EDMA3 | FSL_EDMA_DRV_ERRIRQ_SHARE, .chreg_space_sz = 0x10000, .chreg_off = 0x10000, .setup_irq = fsl_edma3_irq_init, }; static struct fsl_edma_drvdata imx93_data4 = { - .flags = FSL_EDMA_DRV_HAS_CHMUX | FSL_EDMA_DRV_HAS_DMACLK | FSL_EDMA_DRV_EDMA4 + .flags = FSL_EDMA_DRV_HAS_CHMUX | FSL_EDMA_DRV_EDMA4 | FSL_EDMA_DRV_ERRIRQ_SHARE, .chreg_space_sz = 0x8000, .chreg_off = 0x10000, @@ -598,7 +598,7 @@ static struct fsl_edma_drvdata imx93_data4 = { }; static struct fsl_edma_drvdata imx95_data5 = { - .flags = FSL_EDMA_DRV_HAS_CHMUX | FSL_EDMA_DRV_HAS_DMACLK | FSL_EDMA_DRV_EDMA4 | + .flags = FSL_EDMA_DRV_HAS_CHMUX | FSL_EDMA_DRV_EDMA4 | FSL_EDMA_DRV_TCD64 | FSL_EDMA_DRV_ERRIRQ_SHARE, .chreg_space_sz = 0x8000, .chreg_off = 0x10000, @@ -738,13 +738,11 @@ static int fsl_edma_probe(struct platform_device *pdev) regs = &fsl_edma->regs; } - if (drvdata->flags & FSL_EDMA_DRV_HAS_DMACLK) { - fsl_edma->dmaclk = devm_clk_get_enabled(&pdev->dev, "dma"); - if (IS_ERR(fsl_edma->dmaclk)) - return dev_err_probe(&pdev->dev, - PTR_ERR(fsl_edma->dmaclk), - "Missing DMA block clock.\n"); - } + fsl_edma->dmaclk = devm_clk_get_optional_enabled(&pdev->dev, "dma"); + if (IS_ERR(fsl_edma->dmaclk)) + return dev_err_probe(&pdev->dev, + PTR_ERR(fsl_edma->dmaclk), + "Failed to get/enable DMA clock.\n"); ret = of_property_read_variable_u32_array(np, "dma-channel-mask", chan_mask, 1, 2); -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v8 3/5] dmaengine: fsl-edma: convert DMAMUX clock handling to bulk clock API 2026-11-25 10:58 [PATCH v8 0/5] add runtime suspend/resume support joy.zou 2026-11-25 10:58 ` [PATCH v8 1/5] dmaengine: fsl-edma: use devm_clk_get_optional_enabled() for channel clock joy.zou 2026-11-25 10:58 ` [PATCH v8 2/5] dmaengine: fsl-edma: use devm_clk_get_optional() for DMA engine clock joy.zou @ 2026-11-25 10:58 ` joy.zou 2026-11-25 10:58 ` [PATCH v8 4/5] dmaengine: mcf-edma: enable runtime PM for eDMA engine and channel Joy Zou 2026-11-25 10:58 ` [PATCH v8 5/5] dmaengine: fsl-edma: add runtime suspend/resume support Joy Zou 4 siblings, 0 replies; 8+ messages in thread From: joy.zou @ 2026-11-25 10:58 UTC (permalink / raw) To: Frank Li, Vinod Koul, Joe Hattori Cc: Joy Zou, Frank Li, imx, dmaengine, linux-kernel, Joy Zou From: Joy Zou <joy.zou@nxp.com> Convert the DMAMUX clock management from individual clock operations to the bulk clock API to simplify the code. Prepare to add edma engine runtime pm support. Reviewed-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Joy Zou <joy.zou@nxp.com> --- Changes for v7: - Replace devm_clk_bulk_get_optional() with devm_clk_bulk_get_optional_enable(). Changes for v6: - Replace devm_clk_bulk_get_optional_enable() with devm_clk_bulk_get_optional() and clk_bulk_prepare_enable() in order to use runtime PM for power management later. - add Reviewed-by tag. - Link to v5: https://lore.kernel.org/imx/20260513-b4-b4-edma-runtime-opt-v5-0-1e595bfb8423@nxp.com/ --- drivers/dma/fsl-edma-common.h | 2 +- drivers/dma/fsl-edma-main.c | 41 +++++++++++++++++++---------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/drivers/dma/fsl-edma-common.h b/drivers/dma/fsl-edma-common.h index 97b3a9872e90..12db403204c5 100644 --- a/drivers/dma/fsl-edma-common.h +++ b/drivers/dma/fsl-edma-common.h @@ -260,7 +260,7 @@ struct fsl_edma_engine { struct dma_device dma_dev; void __iomem *membase; void __iomem *muxbase[DMAMUX_NR]; - struct clk *muxclk[DMAMUX_NR]; + struct clk_bulk_data *muxclk; struct clk *dmaclk; struct mutex fsl_edma_mutex; const struct fsl_edma_drvdata *drvdata; diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c index 6a296fffb837..fdb2577d1ccb 100644 --- a/drivers/dma/fsl-edma-main.c +++ b/drivers/dma/fsl-edma-main.c @@ -531,14 +531,6 @@ static void fsl_edma_irq_exit( } } -static void fsl_disable_clocks(struct fsl_edma_engine *fsl_edma, int nr_clocks) -{ - int i; - - for (i = 0; i < nr_clocks; i++) - clk_disable_unprepare(fsl_edma->muxclk[i]); -} - static struct fsl_edma_drvdata vf610_data = { .dmamuxs = DMAMUX_NR, .flags = FSL_EDMA_DRV_WRAP_IO, @@ -752,23 +744,28 @@ static int fsl_edma_probe(struct platform_device *pdev) fsl_edma->chan_masked |= chan_mask[0]; } - for (i = 0; i < fsl_edma->drvdata->dmamuxs; i++) { - char clkname[32]; + if (fsl_edma->drvdata->dmamuxs) { + fsl_edma->muxclk = devm_kcalloc(&pdev->dev, fsl_edma->drvdata->dmamuxs, + sizeof(*fsl_edma->muxclk), GFP_KERNEL); + if (!fsl_edma->muxclk) + return -ENOMEM; + + for (i = 0; i < fsl_edma->drvdata->dmamuxs; i++) { + fsl_edma->muxbase[i] = devm_platform_ioremap_resource(pdev, 1 + i); + if (IS_ERR(fsl_edma->muxbase[i])) + return PTR_ERR(fsl_edma->muxbase[i]); - fsl_edma->muxbase[i] = devm_platform_ioremap_resource(pdev, - 1 + i); - if (IS_ERR(fsl_edma->muxbase[i])) { - /* on error: disable all previously enabled clks */ - fsl_disable_clocks(fsl_edma, i); - return PTR_ERR(fsl_edma->muxbase[i]); + fsl_edma->muxclk[i].id = devm_kasprintf(&pdev->dev, GFP_KERNEL, + "dmamux%d", i); + if (!fsl_edma->muxclk[i].id) + return -ENOMEM; } - sprintf(clkname, "dmamux%d", i); - fsl_edma->muxclk[i] = devm_clk_get_enabled(&pdev->dev, clkname); - if (IS_ERR(fsl_edma->muxclk[i])) - return dev_err_probe(&pdev->dev, - PTR_ERR(fsl_edma->muxclk[i]), - "Missing DMAMUX block clock.\n"); + ret = devm_clk_bulk_get_optional_enable(&pdev->dev, fsl_edma->drvdata->dmamuxs, + fsl_edma->muxclk); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "Failed to get/enable DMAMUX block clock.\n"); } fsl_edma->big_endian = of_property_read_bool(np, "big-endian"); -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v8 4/5] dmaengine: mcf-edma: enable runtime PM for eDMA engine and channel 2026-11-25 10:58 [PATCH v8 0/5] add runtime suspend/resume support joy.zou ` (2 preceding siblings ...) 2026-11-25 10:58 ` [PATCH v8 3/5] dmaengine: fsl-edma: convert DMAMUX clock handling to bulk clock API joy.zou @ 2026-11-25 10:58 ` Joy Zou 2026-11-25 11:03 ` sashiko-bot 2026-11-25 10:58 ` [PATCH v8 5/5] dmaengine: fsl-edma: add runtime suspend/resume support Joy Zou 4 siblings, 1 reply; 8+ messages in thread From: Joy Zou @ 2026-11-25 10:58 UTC (permalink / raw) To: Frank Li, Vinod Koul, Joe Hattori Cc: Joy Zou, Frank Li, imx, dmaengine, linux-kernel The common fsl_edma_alloc_chan_resources() implementation supports runtime PM and relies on it when allocating channel resources. Enable runtime PM for the eDMA engine and its channel devices to ensure that runtime PM operations work correctly when CONFIG_PM is enabled. This patch has only been build-tested. Signed-off-by: Joy Zou <joy.zou@oss.nxp.com> --- Changes in v8: - Add a new patch to prevent fsl_edma_alloc_chan_resources() from failing when CONFIG_PM is enabled. --- drivers/dma/mcf-edma-main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/dma/mcf-edma-main.c b/drivers/dma/mcf-edma-main.c index 9e1c6400c77b..b1b94639d4cc 100644 --- a/drivers/dma/mcf-edma-main.c +++ b/drivers/dma/mcf-edma-main.c @@ -8,6 +8,7 @@ #include <linux/dmaengine.h> #include <linux/platform_device.h> #include <linux/platform_data/dma-mcf-edma.h> +#include <linux/pm_runtime.h> #include "fsl-edma-common.h" @@ -192,7 +193,9 @@ static int mcf_edma_probe(struct platform_device *pdev) INIT_LIST_HEAD(&mcf_edma->dma_dev.channels); for (i = 0; i < mcf_edma->n_chans; i++) { struct fsl_edma_chan *mcf_chan = &mcf_edma->chans[i]; + struct device *chan_dev; + chan_dev = &mcf_chan->vchan.chan.dev->device; mcf_chan->edma = mcf_edma; mcf_chan->srcid = i; mcf_chan->dma_dir = DMA_NONE; @@ -201,6 +204,10 @@ static int mcf_edma_probe(struct platform_device *pdev) mcf_chan->tcd = mcf_edma->membase + EDMA_TCD + i * sizeof(struct fsl_edma_hw_tcd); edma_write_tcdreg(mcf_chan, cpu_to_le32(0), csr); + ret = devm_pm_runtime_enable(chan_dev); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "Can't enable eDMA channel PM runtime!\n"); } iowrite32(~0, regs->inth); @@ -240,6 +247,10 @@ static int mcf_edma_probe(struct platform_device *pdev) platform_set_drvdata(pdev, mcf_edma); + ret = devm_pm_runtime_enable(&pdev->dev); + if (ret) + return dev_err_probe(&pdev->dev, ret, "Can't enable eDMA engine PM runtime!\n"); + ret = dma_async_device_register(&mcf_edma->dma_dev); if (ret) { dev_err(&pdev->dev, -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v8 4/5] dmaengine: mcf-edma: enable runtime PM for eDMA engine and channel 2026-11-25 10:58 ` [PATCH v8 4/5] dmaengine: mcf-edma: enable runtime PM for eDMA engine and channel Joy Zou @ 2026-11-25 11:03 ` sashiko-bot 0 siblings, 0 replies; 8+ messages in thread From: sashiko-bot @ 2026-11-25 11:03 UTC (permalink / raw) To: Joy Zou; +Cc: imx, dmaengine, vkoul, Frank.Li Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] dmaengine: mcf-edma: NULL deref in mcf_edma_probe() on unregistered chan_dev - [Medium] dmaengine: mcf-edma: missing IRQ cleanup on error in mcf_edma_probe() -- commit 85c2f32e55b99ebb674415cf8e3e58e89f3b5438 Author: Joy Zou <joy.zou@oss.nxp.com> dmaengine: mcf-edma: enable runtime PM for eDMA engine and channel This commit enables runtime PM for the ColdFire eDMA engine and its channel devices during probe. > diff --git a/drivers/dma/mcf-edma-main.c b/drivers/dma/mcf-edma-main.c > index 9e1c6400c77be..b1b94639d4cc0 100644 > --- a/drivers/dma/mcf-edma-main.c > +++ b/drivers/dma/mcf-edma-main.c > @@ -8,6 +8,7 @@ > #include <linux/dmaengine.h> > #include <linux/platform_device.h> > #include <linux/platform_data/dma-mcf-edma.h> > +#include <linux/pm_runtime.h> > > #include "fsl-edma-common.h" > > @@ -192,7 +193,9 @@ static int mcf_edma_probe(struct platform_device *pdev) > INIT_LIST_HEAD(&mcf_edma->dma_dev.channels); > for (i = 0; i < mcf_edma->n_chans; i++) { > struct fsl_edma_chan *mcf_chan = &mcf_edma->chans[i]; > + struct device *chan_dev; > > + chan_dev = &mcf_chan->vchan.chan.dev->device; > mcf_chan->edma = mcf_edma; > mcf_chan->srcid = i; > mcf_chan->dma_dir = DMA_NONE; > @@ -201,6 +204,10 @@ static int mcf_edma_probe(struct platform_device *pdev) > mcf_chan->tcd = mcf_edma->membase + EDMA_TCD > + i * sizeof(struct fsl_edma_hw_tcd); > edma_write_tcdreg(mcf_chan, cpu_to_le32(0), csr); > + ret = devm_pm_runtime_enable(chan_dev); > + if (ret) > + return dev_err_probe(&pdev->dev, ret, > + "Can't enable eDMA channel PM runtime!\n"); > } [Severity: High] Does devm_pm_runtime_enable(chan_dev) cause a NULL pointer dereference when CONFIG_PM is enabled? At this point in mcf_edma_probe(), mcf_chan->vchan.chan.dev is still NULL because the per-channel struct dma_chan_dev is not allocated or registered until dma_async_device_register() runs later in probe. chan_dev is therefore an offset from NULL, and devm_pm_runtime_enable(chan_dev) immediately dereferences chan_dev->power.lock and chan_dev->devres_lock. > > iowrite32(~0, regs->inth); > @@ -240,6 +247,10 @@ static int mcf_edma_probe(struct platform_device *pdev) > > platform_set_drvdata(pdev, mcf_edma); > > + ret = devm_pm_runtime_enable(&pdev->dev); > + if (ret) > + return dev_err_probe(&pdev->dev, ret, "Can't enable eDMA engine PM runtime!\n"); > + [Severity: Medium] If devm_pm_runtime_enable(&pdev->dev) fails, does returning directly leak the IRQs requested earlier by mcf_edma->drvdata->setup_irq() and leave the vchan tasklets initialized? mcf_edma_irq_init() registers its interrupt handlers with unmanaged request_irq() using mcf_edma as the dev_id cookie. When probe fails here, devres frees mcf_edma and unmaps mcf_edma->membase while those IRQ handlers remain active with a dangling mcf_edma pointer. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261125-b4-edma-runtime-opt-mo-v8-0-81345a3bfb52@oss.nxp.com?part=4 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v8 5/5] dmaengine: fsl-edma: add runtime suspend/resume support 2026-11-25 10:58 [PATCH v8 0/5] add runtime suspend/resume support joy.zou ` (3 preceding siblings ...) 2026-11-25 10:58 ` [PATCH v8 4/5] dmaengine: mcf-edma: enable runtime PM for eDMA engine and channel Joy Zou @ 2026-11-25 10:58 ` Joy Zou 2026-11-25 11:23 ` sashiko-bot 4 siblings, 1 reply; 8+ messages in thread From: Joy Zou @ 2026-11-25 10:58 UTC (permalink / raw) To: Frank Li, Vinod Koul, Joe Hattori Cc: Joy Zou, Frank Li, imx, dmaengine, linux-kernel, Joy Zou Introduce runtime suspend and resume support for FSL eDMA. Enable per-channel power domain management to facilitate runtime suspend and resume operations. Implement runtime suspend and resume functions for the eDMA engine and individual channels. Link per-channel power domain device to eDMA per-channel device instead of eDMA engine device. So Power Manage framework manage power state of linked domain device when per-channel device request runtime resume/suspend. Trigger the eDMA engine's runtime suspend when all channels are suspended, disabling all common clocks through the runtime PM framework. ARCH_MXC selects CONFIG_PM, so CONFIG_PM=n is not a valid configuration on i.MX platforms. Clock handling for the CONFIG_PM=n case is not implemented. Signed-off-by: Joy Zou <joy.zou@nxp.com> Signed-off-by: Frank Li <Frank.Li@nxp.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> --- Changes in V8: - changed the pm_runtime_get_if_active() return value check from <= 0 to == 0 to account for the CONFIG_PM=n case. - remove reduntant pd_dev pm_runtime handler due to bind the dma channel. - add the pm_runtime_get_if_active() check for fsl_edma3_err_check(). - add chan_masked check for fsl_edma3_or_err_handler, fsl_edma_tx_handler and fsl_edma_err_handler. - add synchronize_irq() for txirq_16_3. - remove the manual device_link_del() call to avoid use-after-free. Changes in V7: - replace devm_clk_get_optional_enable() with devm_clk_get_optional(). - replace devm_clk_bulk_get_optional_enable() with devm_clk_bulk_get_optional(). - use PM_RUNTIME_ACQUIRE_IF_ENABLED()/PM_RUNTIME_ACQUIRE_ERR() guards to replace pm_runtime_resume_and_get() and the manual error handling for both the eDMA engine and per-channel devices. - move dmaenginem_async_device_register() after runtime PM is enabled. - move fsl_edma->drvdata->setup_irq() to the end of probe() and use dev_err_probe() on failure. - check "irq > 0" instead of "irq" before synchronize_irq() in fsl_edma_chan_runtime_suspend(). - add fsl_chan txirq and errirq synchronize_irq() check in fsl_edma_chan_runtime_suspend(). - add comments explaining the pm_runtime_get_if_active() checks in the interrupt handlers. - Link to v6: https://patch.msgid.link/20260701-b4-edma-runtime-opt-v6-0-354ff4229c00@oss.nxp.com Changes in V6: - add synchronize_irq() before disabling the channel clock in fsl_edma_chan_runtime_suspend() per AI review comments. - add pm_runtime_get_if_active() in interrupt handlers to ensure registers can be accessed correctly per AI review comments. - remove manual fsl_edma3_detach_pd() call when device_link_add() fails. The devres framework will handle cleanup automatically on probe failure. - clear fsl_chan->pd_dev_link after freeing the device link to prevent potential use-after-free issues. - move fsl_edma->drvdata->setup_irq() atfer edma engine pm_runtime_resume_and_get(). - Link to v5: https://lore.kernel.org/imx/20260513-b4-b4-edma-runtime-opt-v5-0-1e595bfb8423@nxp.com/ Changes in V5: - remove unnecessary flags FSL_EDMA_DRV_HAS_CHCLK and FSL_EDMA_DRV_HAS_DMACLK. - remove redundant clk_disable_unprepare() due to the pm_runtime_put_sync_suspend() added. - use devm_pm_runtime_enable() to replace pm_runtime_enable() and add return value check. - add return value check for pm_runtime_get_sync(); - replace pm_runtime_get_sync() with pm_runtime_resume_and_get(). - replace DMAMUX clock handling with bulk clock API for edma engine runtime suspend/resume. - remove dev_pm_domain_detach() when device_link_add() fail because the fsl_edma3_detach_pd() also call dev_pm_domain_detach(). - remove device_link_add() DL_FLAG_RPM_ACTIVE flag and pm_runtime_put_sync_suspend(). - add clk_bulk_disable_unprepare() for clk_prepare_enable() fail in fsl_edma_runtime_resume(). - remove the extra space before RUNTIME_PM_OPS. - add skip channel comments for system suspend. - add clk_disable_unprepare() for dmaclk at the end of probe function. - add clk_bulk_disable_unprepare() for muxclk at the end of probe function. - Link to v4: https://lore.kernel.org/imx/20251017-b4-edma-runtime-v4-1-87c64dd30229@nxp.com/ Changes for V4: - fix a typo dmaegnine/dmaengine in the subject. - Link to v3: https://lore.kernel.org/imx/20250912-b4-edma-runtime-v3-1-be22f7161745@nxp.com/ Changes for V3: - rebased onto commit 8f21d9da4670 ("Add linux-next specific files for 20250911") to align with latest changes. - Remove pm_runtime_dont_use_autosuspend() from fsl_edma3_detach_pd(). because the autosuspend is not used. - Move some edma channel registers initialization after the chan_dev pm_runtime_enable(). - Add clk_prepare_enable() return check in fsl_edma_runtime_resume. - Add flag FSL_EDMA_DRV_HAS_DMACLK check in fsl_edma_runtime_resume/suspend(). - Link to v2: https://lore.kernel.org/imx/20241226052643.1951886-1-joy.zou@nxp.com/ Changes for V2: - drop ret from fsl_edma_chan_runtime_suspend(). - drop ret from fsl_edma_chan_runtime_resume() and return clk_prepare_enable(). - add review tag - Link to v1: https://lore.kernel.org/imx/20241220021109.2102294-1-joy.zou@nxp.com/ Signed-off-by: Joy Zou <joy.zou@oss.nxp.com> --- drivers/dma/fsl-edma-common.c | 14 ++- drivers/dma/fsl-edma-main.c | 273 +++++++++++++++++++++++++++++++++++------- 2 files changed, 240 insertions(+), 47 deletions(-) diff --git a/drivers/dma/fsl-edma-common.c b/drivers/dma/fsl-edma-common.c index 4f7a942673eb..4ab56294ac77 100644 --- a/drivers/dma/fsl-edma-common.c +++ b/drivers/dma/fsl-edma-common.c @@ -274,9 +274,6 @@ int fsl_edma_terminate_all(struct dma_chan *chan) spin_unlock_irqrestore(&fsl_chan->vchan.lock, flags); vchan_dma_desc_free_list(&fsl_chan->vchan, &head); - if (fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_HAS_PD) - pm_runtime_allow(fsl_chan->pd_dev); - return 0; } @@ -1087,7 +1084,12 @@ int fsl_edma_alloc_chan_resources(struct dma_chan *chan) struct fsl_edma_chan *fsl_chan = to_fsl_edma_chan(chan); int ret = 0; - clk_prepare_enable(fsl_chan->clk); + ret = pm_runtime_resume_and_get(&fsl_chan->vchan.chan.dev->device); + if (ret < 0) { + dev_err(&fsl_chan->vchan.chan.dev->device, "Failed to resume device: %d\n", ret); + return ret; + } + fsl_chan->tcd_pool = dma_pool_create("tcd_pool", chan->device->dev, fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_TCD64 ? sizeof(struct fsl_edma_hw_tcd64) : sizeof(struct fsl_edma_hw_tcd), @@ -1114,7 +1116,7 @@ int fsl_edma_alloc_chan_resources(struct dma_chan *chan) free_irq(fsl_chan->txirq, fsl_chan); err_txirq: dma_pool_destroy(fsl_chan->tcd_pool); - clk_disable_unprepare(fsl_chan->clk); + pm_runtime_put_sync_suspend(&fsl_chan->vchan.chan.dev->device); return ret; } @@ -1146,7 +1148,7 @@ void fsl_edma_free_chan_resources(struct dma_chan *chan) fsl_chan->is_sw = false; fsl_chan->srcid = 0; fsl_chan->is_remote = false; - clk_disable_unprepare(fsl_chan->clk); + pm_runtime_put_sync_suspend(&fsl_chan->vchan.chan.dev->device); } void fsl_edma_cleanup_vchan(struct dma_device *dmadev) diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c index fdb2577d1ccb..5500eb17f579 100644 --- a/drivers/dma/fsl-edma-main.c +++ b/drivers/dma/fsl-edma-main.c @@ -37,15 +37,35 @@ static irqreturn_t fsl_edma_tx_handler(int irq, void *dev_id) unsigned int intr, ch; struct edma_regs *regs = &fsl_edma->regs; + /* + * A racy or spurious interrupt for an already-suspended + * controller or channel is an extremely rare corner case and + * highly unlikely in practice. + */ + if (pm_runtime_get_if_active(fsl_edma->dma_dev.dev) == 0) + return IRQ_NONE; + intr = edma_readl(fsl_edma, regs->intl); - if (!intr) + if (!intr) { + pm_runtime_put(fsl_edma->dma_dev.dev); return IRQ_NONE; + } + pm_runtime_put(fsl_edma->dma_dev.dev); for (ch = 0; ch < fsl_edma->n_chans; ch++) { + struct fsl_edma_chan *fsl_chan = &fsl_edma->chans[ch]; + + if (fsl_edma->chan_masked & BIT(ch)) + continue; + + if (pm_runtime_get_if_active(&fsl_chan->vchan.chan.dev->device) == 0) + continue; + if (intr & (0x1 << ch)) { edma_writeb(fsl_edma, EDMA_CINT_CINT(ch), regs->cint); fsl_edma_tx_chan_handler(&fsl_edma->chans[ch]); } + pm_runtime_put(&fsl_chan->vchan.chan.dev->device); } return IRQ_HANDLED; } @@ -55,10 +75,15 @@ static void fsl_edma3_err_check(struct fsl_edma_chan *fsl_chan) unsigned int ch_err; u32 val; + if (pm_runtime_get_if_active(&fsl_chan->vchan.chan.dev->device) == 0) + return; + scoped_guard(spinlock, &fsl_chan->vchan.lock) { ch_err = edma_readl_chreg(fsl_chan, ch_es); - if (!(ch_err & EDMA_V3_CH_ERR)) + if (!(ch_err & EDMA_V3_CH_ERR)) { + pm_runtime_put(&fsl_chan->vchan.chan.dev->device); return; + } edma_writel_chreg(fsl_chan, EDMA_V3_CH_ERR, ch_es); val = edma_readl_chreg(fsl_chan, ch_csr); @@ -66,6 +91,7 @@ static void fsl_edma3_err_check(struct fsl_edma_chan *fsl_chan) edma_writel_chreg(fsl_chan, val, ch_csr); } + pm_runtime_put(&fsl_chan->vchan.chan.dev->device); /* Ignore this interrupt since channel has been disabled already */ if (!fsl_chan->edesc) return; @@ -132,13 +158,23 @@ static irqreturn_t fsl_edma3_tx_handler(int irq, void *dev_id) struct fsl_edma_chan *fsl_chan = dev_id; unsigned int intr; - intr = edma_readl_chreg(fsl_chan, ch_int); - if (!intr) + /* + * A racy or spurious interrupt for an already-suspended + * channel is an extremely rare corner case and highly unlikely in + * practice. + */ + if (pm_runtime_get_if_active(&fsl_chan->vchan.chan.dev->device) == 0) return IRQ_NONE; + intr = edma_readl_chreg(fsl_chan, ch_int); + if (!intr) { + pm_runtime_put(&fsl_chan->vchan.chan.dev->device); + return IRQ_NONE; + } edma_writel_chreg(fsl_chan, 1, ch_int); fsl_edma_tx_chan_handler(fsl_chan); + pm_runtime_put(&fsl_chan->vchan.chan.dev->device); return IRQ_HANDLED; } @@ -185,20 +221,40 @@ static irqreturn_t fsl_edma3_or_err_handler(int irq, void *dev_id) unsigned int err, ch, ch_es; struct fsl_edma_chan *chan; + /* + * A racy or spurious interrupt for an already-suspended + * controller or channel is an extremely rare corner case and + * highly unlikely in practice. + */ + if (pm_runtime_get_if_active(fsl_edma->dma_dev.dev) == 0) + return IRQ_NONE; + err = edma_readl(fsl_edma, regs->es); - if (!(err & EDMA_V3_MP_ES_VLD)) + if (!(err & EDMA_V3_MP_ES_VLD)) { + pm_runtime_put(fsl_edma->dma_dev.dev); return IRQ_NONE; + } + pm_runtime_put(fsl_edma->dma_dev.dev); for (ch = 0; ch < fsl_edma->n_chans; ch++) { chan = &fsl_edma->chans[ch]; + if (fsl_edma->chan_masked & BIT(ch)) + continue; + + if (pm_runtime_get_if_active(&chan->vchan.chan.dev->device) == 0) + continue; + ch_es = edma_readl_chreg(chan, ch_es); - if (!(ch_es & EDMA_V3_CH_ES_ERR)) + if (!(ch_es & EDMA_V3_CH_ES_ERR)) { + pm_runtime_put(&chan->vchan.chan.dev->device); continue; + } edma_writel_chreg(chan, EDMA_V3_CH_ES_ERR, ch_es); fsl_edma_disable_request(chan); fsl_edma->chans[ch].status = DMA_ERROR; + pm_runtime_put(&chan->vchan.chan.dev->device); } return IRQ_HANDLED; @@ -210,16 +266,36 @@ static irqreturn_t fsl_edma_err_handler(int irq, void *dev_id) unsigned int err, ch; struct edma_regs *regs = &fsl_edma->regs; + /* + * A racy or spurious interrupt for an already-suspended + * controller or channel is an extremely rare corner case and + * highly unlikely in practice. + */ + if (pm_runtime_get_if_active(fsl_edma->dma_dev.dev) == 0) + return IRQ_NONE; + err = edma_readl(fsl_edma, regs->errl); - if (!err) + if (!err) { + pm_runtime_put(fsl_edma->dma_dev.dev); return IRQ_NONE; + } + pm_runtime_put(fsl_edma->dma_dev.dev); for (ch = 0; ch < fsl_edma->n_chans; ch++) { + struct fsl_edma_chan *fsl_chan = &fsl_edma->chans[ch]; + + if (fsl_edma->chan_masked & BIT(ch)) + continue; + + if (pm_runtime_get_if_active(&fsl_chan->vchan.chan.dev->device) == 0) + continue; + if (err & (0x1 << ch)) { fsl_edma_disable_request(&fsl_edma->chans[ch]); edma_writeb(fsl_edma, EDMA_CERR_CERR(ch), regs->cerr); fsl_edma_err_chan_handler(&fsl_edma->chans[ch]); } + pm_runtime_put(&fsl_chan->vchan.chan.dev->device); } return IRQ_HANDLED; } @@ -631,12 +707,10 @@ static void fsl_edma3_detach_pd(struct fsl_edma_engine *fsl_edma) continue; fsl_chan = &fsl_edma->chans[i]; if (fsl_chan->pd_dev_link) - device_link_del(fsl_chan->pd_dev_link); - if (fsl_chan->pd_dev) { + fsl_chan->pd_dev_link = NULL; + + 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); - } } } @@ -665,23 +739,8 @@ static int fsl_edma3_attach_pd(struct platform_device *pdev, struct fsl_edma_eng dev_err(dev, "Failed attach pd %d\n", i); goto detach; } - - fsl_chan->pd_dev_link = device_link_add(dev, pd_chan, DL_FLAG_STATELESS | - DL_FLAG_PM_RUNTIME | - DL_FLAG_RPM_ACTIVE); - if (!fsl_chan->pd_dev_link) { - dev_err(dev, "Failed to add device_link to %d\n", i); - dev_pm_domain_detach(pd_chan, false); - goto detach; - } - fsl_chan->pd_dev = pd_chan; - - pm_runtime_use_autosuspend(fsl_chan->pd_dev); - pm_runtime_set_autosuspend_delay(fsl_chan->pd_dev, 200); - pm_runtime_set_active(fsl_chan->pd_dev); } - return 0; detach: @@ -689,6 +748,45 @@ static int fsl_edma3_attach_pd(struct platform_device *pdev, struct fsl_edma_eng return -EINVAL; } +/* Per channel dma power domain */ +static int fsl_edma_chan_runtime_suspend(struct device *dev) +{ + struct fsl_edma_chan *fsl_chan = dev_get_drvdata(dev); + struct fsl_edma_engine *fsl_edma = fsl_chan->edma; + + if (fsl_edma->txirq > 0) + synchronize_irq(fsl_edma->txirq); + + if (fsl_edma->txirq_16_31 > 0) + synchronize_irq(fsl_edma->txirq_16_31); + + if (fsl_edma->errirq > 0) + synchronize_irq(fsl_edma->errirq); + + if (fsl_chan->txirq > 0) + synchronize_irq(fsl_chan->txirq); + + if (fsl_chan->errirq > 0) + synchronize_irq(fsl_chan->errirq); + + clk_disable_unprepare(fsl_chan->clk); + + return 0; +} + +static int fsl_edma_chan_runtime_resume(struct device *dev) +{ + struct fsl_edma_chan *fsl_chan = dev_get_drvdata(dev); + + return clk_prepare_enable(fsl_chan->clk); +} + +static struct dev_pm_domain fsl_edma_chan_pm_domain = { + .ops = { + RUNTIME_PM_OPS(fsl_edma_chan_runtime_suspend, fsl_edma_chan_runtime_resume, NULL) + } +}; + static int fsl_edma_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -730,11 +828,11 @@ static int fsl_edma_probe(struct platform_device *pdev) regs = &fsl_edma->regs; } - fsl_edma->dmaclk = devm_clk_get_optional_enabled(&pdev->dev, "dma"); + fsl_edma->dmaclk = devm_clk_get_optional(&pdev->dev, "dma"); if (IS_ERR(fsl_edma->dmaclk)) return dev_err_probe(&pdev->dev, PTR_ERR(fsl_edma->dmaclk), - "Failed to get/enable DMA clock.\n"); + "Failed to get DMA clock.\n"); ret = of_property_read_variable_u32_array(np, "dma-channel-mask", chan_mask, 1, 2); @@ -761,11 +859,11 @@ static int fsl_edma_probe(struct platform_device *pdev) return -ENOMEM; } - ret = devm_clk_bulk_get_optional_enable(&pdev->dev, fsl_edma->drvdata->dmamuxs, - fsl_edma->muxclk); + ret = devm_clk_bulk_get_optional(&pdev->dev, fsl_edma->drvdata->dmamuxs, + fsl_edma->muxclk); if (ret) return dev_err_probe(&pdev->dev, ret, - "Failed to get/enable DMAMUX block clock.\n"); + "Failed to get DMAMUX block clock.\n"); } fsl_edma->big_endian = of_property_read_bool(np, "big-endian"); @@ -808,20 +906,13 @@ static int fsl_edma_probe(struct platform_device *pdev) + i * drvdata->chreg_space_sz + drvdata->chreg_off + len; fsl_chan->mux_addr = fsl_edma->membase + drvdata->mux_off + i * drvdata->mux_skip; snprintf(clk_name, sizeof(clk_name), "ch%02d", i); - fsl_chan->clk = devm_clk_get_optional_enabled(&pdev->dev, (const char *)clk_name); + fsl_chan->clk = devm_clk_get_optional(&pdev->dev, (const char *)clk_name); if (IS_ERR(fsl_chan->clk)) return PTR_ERR(fsl_chan->clk); fsl_chan->pdev = pdev; vchan_init(&fsl_chan->vchan, &fsl_edma->dma_dev); - - edma_write_tcdreg(fsl_chan, cpu_to_le32(0), csr); - fsl_edma_chan_mux(fsl_chan, 0, false); } - ret = fsl_edma->drvdata->setup_irq(pdev, fsl_edma); - if (ret) - return ret; - dma_cap_set(DMA_PRIVATE, fsl_edma->dma_dev.cap_mask); dma_cap_set(DMA_SLAVE, fsl_edma->dma_dev.cap_mask); dma_cap_set(DMA_CYCLIC, fsl_edma->dma_dev.cap_mask); @@ -869,11 +960,56 @@ static int fsl_edma_probe(struct platform_device *pdev) platform_set_drvdata(pdev, fsl_edma); + ret = devm_pm_runtime_enable(&pdev->dev); + if (ret) + return dev_err_probe(&pdev->dev, ret, "Can't enable eDMA engine PM runtime!\n"); + + PM_RUNTIME_ACQUIRE_IF_ENABLED(&pdev->dev, pm); + ret = PM_RUNTIME_ACQUIRE_ERR(&pm); + if (ret) + return dev_err_probe(&pdev->dev, ret, "Failed to resume eDMA engine!\n"); + ret = dmaenginem_async_device_register(&fsl_edma->dma_dev); if (ret) return dev_err_probe(&pdev->dev, ret, "Can't register Freescale eDMA engine.\n"); + for (i = 0; i < fsl_edma->n_chans; i++) { + struct fsl_edma_chan *fsl_chan = &fsl_edma->chans[i]; + struct device *chan_dev; + + if (fsl_edma->chan_masked & BIT(i)) + continue; + + chan_dev = &fsl_chan->vchan.chan.dev->device; + dev_set_drvdata(chan_dev, fsl_chan); + dev_pm_domain_set(chan_dev, &fsl_edma_chan_pm_domain); + + if (fsl_chan->pd_dev) { + fsl_chan->pd_dev_link = device_link_add(chan_dev, fsl_chan->pd_dev, + DL_FLAG_STATELESS | + DL_FLAG_PM_RUNTIME); + if (!fsl_chan->pd_dev_link) { + return dev_err_probe(&pdev->dev, -EINVAL, + "Failed to add device_link to %d!\n", i); + } + } + ret = devm_pm_runtime_enable(chan_dev); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "Can't enable eDMA channel PM runtime!\n"); + + PM_RUNTIME_ACQUIRE_IF_ENABLED(chan_dev, pm); + ret = PM_RUNTIME_ACQUIRE_ERR(&pm); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "Failed to resume eDMA channel %d!\n", + fsl_chan->vchan.chan.chan_id); + + edma_write_tcdreg(fsl_chan, cpu_to_le32(0), csr); + fsl_edma_chan_mux(fsl_chan, 0, false); + } + ret = devm_of_dma_controller_register(&pdev->dev, np, drvdata->dmamuxs ? fsl_edma_xlate : fsl_edma3_xlate, fsl_edma); @@ -885,6 +1021,10 @@ static int fsl_edma_probe(struct platform_device *pdev) if (!(drvdata->flags & FSL_EDMA_DRV_SPLIT_REG)) edma_writel(fsl_edma, EDMA_CR_ERGA | EDMA_CR_ERCA, regs->cr); + ret = fsl_edma->drvdata->setup_irq(pdev, fsl_edma); + if (ret) + return dev_err_probe(&pdev->dev, ret, "Failed to setup IRQ!\n"); + return 0; } @@ -907,6 +1047,19 @@ static int fsl_edma_suspend_late(struct device *dev) fsl_chan = &fsl_edma->chans[i]; if (fsl_edma->chan_masked & BIT(i)) continue; + + /* + * Skip channel if: + * 1. Runtime PM already suspended. + * 2. Channel without power domain, and the channel source ID is zero, + * so the channel isn't assigned. + */ + if (pm_runtime_status_suspended(&fsl_chan->vchan.chan.dev->device) || + (!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_HAS_PD) && + (fsl_edma->drvdata->flags & FSL_EDMA_DRV_SPLIT_REG) && + !fsl_chan->srcid)) + continue; + spin_lock_irqsave(&fsl_chan->vchan.lock, flags); /* Make sure chan is idle or will force disable. */ if (unlikely(fsl_chan->status == DMA_IN_PROGRESS)) { @@ -926,19 +1079,56 @@ static int fsl_edma_resume_early(struct device *dev) { struct fsl_edma_engine *fsl_edma = dev_get_drvdata(dev); struct fsl_edma_chan *fsl_chan; - struct edma_regs *regs = &fsl_edma->regs; int i; for (i = 0; i < fsl_edma->n_chans; i++) { fsl_chan = &fsl_edma->chans[i]; if (fsl_edma->chan_masked & BIT(i)) continue; + + if (pm_runtime_status_suspended(&fsl_chan->vchan.chan.dev->device) || + (!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_HAS_PD) && + (fsl_edma->drvdata->flags & FSL_EDMA_DRV_SPLIT_REG) && + !fsl_chan->srcid)) + continue; + fsl_chan->pm_state = RUNNING; edma_write_tcdreg(fsl_chan, 0, csr); if (fsl_chan->srcid != 0) fsl_edma_chan_mux(fsl_chan, fsl_chan->srcid, true); } + return 0; +} + +/* edma engine runtime system/resume */ +static int fsl_edma_runtime_suspend(struct device *dev) +{ + struct fsl_edma_engine *fsl_edma = dev_get_drvdata(dev); + + clk_bulk_disable_unprepare(fsl_edma->drvdata->dmamuxs, fsl_edma->muxclk); + + clk_disable_unprepare(fsl_edma->dmaclk); + + return 0; +} + +static int fsl_edma_runtime_resume(struct device *dev) +{ + struct fsl_edma_engine *fsl_edma = dev_get_drvdata(dev); + struct edma_regs *regs = &fsl_edma->regs; + int ret; + + ret = clk_bulk_prepare_enable(fsl_edma->drvdata->dmamuxs, fsl_edma->muxclk); + if (ret) + return ret; + + ret = clk_prepare_enable(fsl_edma->dmaclk); + if (ret) { + clk_bulk_disable_unprepare(fsl_edma->drvdata->dmamuxs, fsl_edma->muxclk); + return ret; + } + if (!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_SPLIT_REG)) edma_writel(fsl_edma, EDMA_CR_ERGA | EDMA_CR_ERCA, regs->cr); @@ -953,6 +1143,7 @@ static int fsl_edma_resume_early(struct device *dev) static const struct dev_pm_ops fsl_edma_pm_ops = { .suspend_late = fsl_edma_suspend_late, .resume_early = fsl_edma_resume_early, + RUNTIME_PM_OPS(fsl_edma_runtime_suspend, fsl_edma_runtime_resume, NULL) }; static struct platform_driver fsl_edma_driver = { -- 2.34.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v8 5/5] dmaengine: fsl-edma: add runtime suspend/resume support 2026-11-25 10:58 ` [PATCH v8 5/5] dmaengine: fsl-edma: add runtime suspend/resume support Joy Zou @ 2026-11-25 11:23 ` sashiko-bot 0 siblings, 0 replies; 8+ messages in thread From: sashiko-bot @ 2026-11-25 11:23 UTC (permalink / raw) To: Joy Zou; +Cc: imx, dmaengine, vkoul, Frank.Li Thank you for your contribution! Sashiko AI review found 11 potential issues to consider: - [High] dmaengine: fsl-edma: NULL dereference on masked channels in fsl_edma3_or_tx_handler() - [High] dmaengine: fsl-edma: refcount underflow and unclocked MMIO on pm_runtime_get_if_active() < 0 - [High] dmaengine: fsl-edma: unclocked MMIO access in fsl_edma_probe() when CONFIG_PM is disabled - [High] dmaengine: fsl-edma: missing CR restore in fsl_edma_resume_early() - [High] dmaengine: fsl-edma: DMA registration before setup_irq() and channel PM - [High] dmaengine: fsl-edma: NULL deref on masked channel in fsl_edma3_or_tx_handler() - [High] dmaengine: fsl-edma: fsl_edma_cleanup_vchan() leaks chan_dev and causes UAF - [High] dmaengine: fsl-edma: IRQ storm and bad RPM ordering in fsl_edma_tx_handler() - [High] dmaengine: fsl-edma: broken channel runtime PM on mcf-edma in mcf_edma_probe() - [Medium] dmaengine: fsl-edma: async runtime PM put in fsl_edma_probe() leaks clocks - [Medium] dmaengine: fsl-edma: active channels with srcid 0 skipped in suspend/resume -- commit 904c5737dc3c2174c965ff0d6fb29328fd87a5f5 Author: Joy Zou <joy.zou@oss.nxp.com> dmaengine: fsl-edma: add runtime suspend/resume support This commit adds runtime PM support for the FSL eDMA controller and its per-channel devices, managing controller and channel clocks as well as per-channel power domains through runtime suspend and resume callbacks. > diff --git a/drivers/dma/fsl-edma-common.c b/drivers/dma/fsl-edma-common.c > index 4f7a942673ebc..4ab56294ac776 100644 > --- a/drivers/dma/fsl-edma-common.c > +++ b/drivers/dma/fsl-edma-common.c [ ... ] > @@ -1087,7 +1084,12 @@ int fsl_edma_alloc_chan_resources(struct dma_chan *chan) > struct fsl_edma_chan *fsl_chan = to_fsl_edma_chan(chan); > int ret = 0; > > - clk_prepare_enable(fsl_chan->clk); > + ret = pm_runtime_resume_and_get(&fsl_chan->vchan.chan.dev->device); > + if (ret < 0) { > + dev_err(&fsl_chan->vchan.chan.dev->device, "Failed to resume device: %d\n", ret); > + return ret; > + } [Severity: High] Does this break mcf-edma when CONFIG_PM is enabled? fsl_edma_alloc_chan_resources() is shared with mcf-edma, so pm_runtime_resume_and_get() requires runtime PM to be enabled on the registered channel device. In commit "dmaengine: mcf-edma: enable runtime PM for eDMA engine and channel" earlier in this series, mcf_edma_probe() calls devm_pm_runtime_enable(chan_dev) before dma_async_device_register() allocates mcf_chan->vchan.chan.dev: drivers/dma/mcf-edma-main.c:mcf_edma_probe() { ... for (i = 0; i < mcf_edma->n_chans; i++) { struct fsl_edma_chan *mcf_chan = &mcf_edma->chans[i]; struct device *chan_dev; chan_dev = &mcf_chan->vchan.chan.dev->device; ... ret = devm_pm_runtime_enable(chan_dev); ... ret = dma_async_device_register(&mcf_edma->dma_dev); ... } Because mcf_chan->vchan.chan.dev is still NULL in that loop, devm_pm_runtime_enable(chan_dev) dereferences a near-NULL pointer during probe when CONFIG_PM=y, and the channel devices allocated later by dma_async_device_register() never have runtime PM enabled. > diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c > index fdb2577d1ccb5..5500eb17f579e 100644 > --- a/drivers/dma/fsl-edma-main.c > +++ b/drivers/dma/fsl-edma-main.c > @@ -37,15 +37,35 @@ static irqreturn_t fsl_edma_tx_handler(int irq, void *dev_id) > unsigned int intr, ch; > struct edma_regs *regs = &fsl_edma->regs; > > + /* > + * A racy or spurious interrupt for an already-suspended > + * controller or channel is an extremely rare corner case and > + * highly unlikely in practice. > + */ > + if (pm_runtime_get_if_active(fsl_edma->dma_dev.dev) == 0) > + return IRQ_NONE; > > intr = edma_readl(fsl_edma, regs->intl); > - if (!intr) > + if (!intr) { > + pm_runtime_put(fsl_edma->dma_dev.dev); > return IRQ_NONE; > + } [Severity: High] Can checking pm_runtime_get_if_active() == 0 underflow power.usage_count and access unclocked registers when runtime PM is disabled? pm_runtime_get_if_active() returns -EINVAL without incrementing power.usage_count when runtime PM is disabled on a device, such as during system suspend and resume transitions after __device_suspend_late() disables runtime PM on idle runtime-suspended channels before IRQs are masked in dpm_suspend_noirq(). Because -EINVAL != 0, this check (along with the matching checks in fsl_edma3_err_check(), fsl_edma3_tx_handler(), fsl_edma3_or_err_handler(), and fsl_edma_err_handler()) proceeds to read channel registers on suspended channels whose clocks or power domains are off and then calls pm_runtime_put() without a matching get. > + pm_runtime_put(fsl_edma->dma_dev.dev); > for (ch = 0; ch < fsl_edma->n_chans; ch++) { > + struct fsl_edma_chan *fsl_chan = &fsl_edma->chans[ch]; > + > + if (fsl_edma->chan_masked & BIT(ch)) > + continue; > + > + if (pm_runtime_get_if_active(&fsl_chan->vchan.chan.dev->device) == 0) > + continue; > + > if (intr & (0x1 << ch)) { > edma_writeb(fsl_edma, EDMA_CINT_CINT(ch), regs->cint); > fsl_edma_tx_chan_handler(&fsl_edma->chans[ch]); > } > + pm_runtime_put(&fsl_chan->vchan.chan.dev->device); > } > return IRQ_HANDLED; > } [Severity: High] Can skipping channels when pm_runtime_get_if_active() returns 0 cause a hard-IRQ storm and hang in synchronize_irq() during channel suspend? In fsl_edma_free_chan_resources(), fsl_edma_disable_request() disables further DMA requests without clearing an already-latched interrupt flag, and then calls pm_runtime_put_sync_suspend(). rpm_suspend() sets the channel's runtime_status to RPM_SUSPENDING before calling fsl_edma_chan_runtime_suspend() -> synchronize_irq(). While the channel is in RPM_SUSPENDING, pm_runtime_get_if_active() returns 0 even though fsl_chan->clk is still enabled, so this handler (as well as fsl_edma_err_handler(), fsl_edma3_or_err_handler(), fsl_edma3_err_check(), and fsl_edma3_tx_handler()) returns IRQ_HANDLED without clearing the hardware interrupt status bit, leaving the level-triggered interrupt line asserted forever. In addition, fsl_edma_tx_handler() and fsl_edma_err_handler() call pm_runtime_get_if_active() and pm_runtime_put() on every unmasked channel before testing whether that channel's bit is set in intr or err, which cycles power.lock and usage_count on unrelated active channels and can cause a concurrent pm_runtime_put_sync_suspend() on another channel to fail with -EAGAIN. Finally, both handlers call pm_runtime_put(fsl_edma->dma_dev.dev) before the loop, even though regs->cint, regs->cerr, regs->cerq, and regs->ceei accessed inside the loop are global controller registers clocked by fsl_edma->dmaclk. [ ... ] > @@ -132,13 +158,23 @@ static irqreturn_t fsl_edma3_tx_handler(int irq, void *dev_id) > struct fsl_edma_chan *fsl_chan = dev_id; > unsigned int intr; > > - intr = edma_readl_chreg(fsl_chan, ch_int); > - if (!intr) > + /* > + * A racy or spurious interrupt for an already-suspended > + * channel is an extremely rare corner case and highly unlikely in > + * practice. > + */ > + if (pm_runtime_get_if_active(&fsl_chan->vchan.chan.dev->device) == 0) > return IRQ_NONE; [Severity: High] Can this dereference a NULL fsl_chan->vchan.chan.dev pointer when a channel is masked via dma-channel-mask on controllers using fsl_edma3_or_irq_init()? In fsl_edma_probe(), channels matching fsl_edma->chan_masked skip vchan_init(), so dmaenginem_async_device_register() never allocates fsl_chan->vchan.chan.dev for them. Unlike the other shared interrupt handlers, fsl_edma3_or_tx_handler() calls fsl_edma3_tx_handler() for every channel in [start, end) without checking fsl_edma->chan_masked: drivers/dma/fsl-edma-main.c:fsl_edma3_or_tx_handler() { ... for (i = start; i < end; i++) { chan = &fsl_edma->chans[i]; fsl_edma3_tx_handler(irq, chan); } ... } [ ... ] > @@ -730,11 +828,11 @@ static int fsl_edma_probe(struct platform_device *pdev) > regs = &fsl_edma->regs; > } > > - fsl_edma->dmaclk = devm_clk_get_optional_enabled(&pdev->dev, "dma"); > + fsl_edma->dmaclk = devm_clk_get_optional(&pdev->dev, "dma"); > if (IS_ERR(fsl_edma->dmaclk)) > return dev_err_probe(&pdev->dev, > PTR_ERR(fsl_edma->dmaclk), > - "Failed to get/enable DMA clock.\n"); > + "Failed to get DMA clock.\n"); [Severity: High] What enables dmaclk, muxclk, and fsl_chan->clk when CONFIG_PM is disabled? Although the commit message states that ARCH_MXC selects CONFIG_PM, CONFIG_FSL_EDMA does not depend on PM and also supports platforms that do not select CONFIG_PM, including ARCH_LAYERSCAPE (fsl,ls1028a-edma and fsl,vf610-edma), ARCH_S32 (nxp,s32g2-edma), and 32-bit ARM ARCH_MXC (SOC_VF610 and SOC_IMX7ULP). With devm_clk_get_optional() and devm_clk_bulk_get_optional() replacing the _enabled variants here and pm_runtime_resume_and_get() replacing clk_prepare_enable() in fsl_edma_alloc_chan_resources(), none of the clocks are enabled when CONFIG_PM=n, causing unclocked MMIO register accesses during probe and channel use. [ ... ] > @@ -869,11 +960,56 @@ static int fsl_edma_probe(struct platform_device *pdev) > > platform_set_drvdata(pdev, fsl_edma); > > + ret = devm_pm_runtime_enable(&pdev->dev); > + if (ret) > + return dev_err_probe(&pdev->dev, ret, "Can't enable eDMA engine PM runtime!\n"); > + > + PM_RUNTIME_ACQUIRE_IF_ENABLED(&pdev->dev, pm); > + ret = PM_RUNTIME_ACQUIRE_ERR(&pm); > + if (ret) > + return dev_err_probe(&pdev->dev, ret, "Failed to resume eDMA engine!\n"); > + > ret = dmaenginem_async_device_register(&fsl_edma->dma_dev); > if (ret) > return dev_err_probe(&pdev->dev, ret, > "Can't register Freescale eDMA engine.\n"); > > + for (i = 0; i < fsl_edma->n_chans; i++) { > + struct fsl_edma_chan *fsl_chan = &fsl_edma->chans[i]; > + struct device *chan_dev; > + > + if (fsl_edma->chan_masked & BIT(i)) > + continue; > + > + chan_dev = &fsl_chan->vchan.chan.dev->device; > + dev_set_drvdata(chan_dev, fsl_chan); > + dev_pm_domain_set(chan_dev, &fsl_edma_chan_pm_domain); > + > + if (fsl_chan->pd_dev) { > + fsl_chan->pd_dev_link = device_link_add(chan_dev, fsl_chan->pd_dev, > + DL_FLAG_STATELESS | > + DL_FLAG_PM_RUNTIME); > + if (!fsl_chan->pd_dev_link) { > + return dev_err_probe(&pdev->dev, -EINVAL, > + "Failed to add device_link to %d!\n", i); > + } > + } > + ret = devm_pm_runtime_enable(chan_dev); > + if (ret) > + return dev_err_probe(&pdev->dev, ret, > + "Can't enable eDMA channel PM runtime!\n"); [Severity: High] Does enabling runtime PM and attaching fsl_edma_chan_pm_domain on chan_dev lead to a use-after-free on driver unbind? dmaenginem_async_device_register() registers a devres action on &pdev->dev to run dma_async_device_unregister(), while fsl_edma_remove() runs before &pdev->dev devres teardown and calls fsl_edma_cleanup_vchan(), which removes every channel from dmadev->channels: drivers/dma/fsl-edma-common.c:fsl_edma_cleanup_vchan() { ... list_for_each_entry_safe(chan, _chan, &dmadev->channels, vchan.chan.device_node) { list_del(&chan->vchan.chan.device_node); tasklet_kill(&chan->vchan.task); } } When dma_async_device_unregister() subsequently runs during devres release, dmadev->channels is already empty, so the per-channel chan_dev devices are never unregistered and remain active with runtime PM enabled and drvdata pointing to the freed fsl_chan structure. > + > + PM_RUNTIME_ACQUIRE_IF_ENABLED(chan_dev, pm); > + ret = PM_RUNTIME_ACQUIRE_ERR(&pm); > + if (ret) > + return dev_err_probe(&pdev->dev, ret, > + "Failed to resume eDMA channel %d!\n", > + fsl_chan->vchan.chan.chan_id); > + > + edma_write_tcdreg(fsl_chan, cpu_to_le32(0), csr); > + fsl_edma_chan_mux(fsl_chan, 0, false); > + } [Severity: Medium] Can fsl_edma_probe() leak clock prepare/enable references if a later probe step fails? PM_RUNTIME_ACQUIRE_IF_ENABLED() synchronously resumes &pdev->dev and each chan_dev (enabling muxclk, dmaclk, and fsl_chan->clk), but releases them via asynchronous pm_runtime_put(), which only queues suspend work on pm_wq. If fsl_edma_probe() fails or defers after resuming the engine or any channel, devres teardown disables runtime PM on chan_dev and &pdev->dev, which cancels the pending suspend work via __pm_runtime_barrier() without running fsl_edma_chan_runtime_suspend() or fsl_edma_runtime_suspend(), leaving the clocks prepared and enabled. > ret = devm_of_dma_controller_register(&pdev->dev, np, > drvdata->dmamuxs ? fsl_edma_xlate : fsl_edma3_xlate, > fsl_edma); > @@ -885,6 +1021,10 @@ static int fsl_edma_probe(struct platform_device *pdev) > if (!(drvdata->flags & FSL_EDMA_DRV_SPLIT_REG)) > edma_writel(fsl_edma, EDMA_CR_ERGA | EDMA_CR_ERCA, regs->cr); > > + ret = fsl_edma->drvdata->setup_irq(pdev, fsl_edma); > + if (ret) > + return dev_err_probe(&pdev->dev, ret, "Failed to setup IRQ!\n"); > + > return 0; > } [Severity: High] Doesn't registering the DMA device and OF DMA controller before channel runtime PM and setup_irq() expose uninitialized channels to consumers and to pm_wq? A client requesting a channel after dmaenginem_async_device_register() or devm_of_dma_controller_register() can enter fsl_edma_alloc_chan_resources() before devm_pm_runtime_enable(chan_dev) runs (failing in pm_runtime_resume_and_get() with -EACCES) or before setup_irq() populates fsl_chan->txirq, fsl_chan->errirq, and their handlers (skipping request_irq() in fsl_edma_alloc_chan_resources()). Meanwhile, the asynchronous pm_runtime_put(chan_dev) in the channel loop queues fsl_edma_chan_runtime_suspend() on pm_wq, which reads fsl_edma->txirq, fsl_edma->txirq_16_31, fsl_edma->errirq, fsl_chan->txirq, and fsl_chan->errirq concurrently with setup_irq() writing them. > @@ -907,6 +1047,19 @@ static int fsl_edma_suspend_late(struct device *dev) > fsl_chan = &fsl_edma->chans[i]; > if (fsl_edma->chan_masked & BIT(i)) > continue; > + > + /* > + * Skip channel if: > + * 1. Runtime PM already suspended. > + * 2. Channel without power domain, and the channel source ID is zero, > + * so the channel isn't assigned. > + */ > + if (pm_runtime_status_suspended(&fsl_chan->vchan.chan.dev->device) || > + (!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_HAS_PD) && > + (fsl_edma->drvdata->flags & FSL_EDMA_DRV_SPLIT_REG) && > + !fsl_chan->srcid)) > + continue; [Severity: Medium] Doesn't checking !fsl_chan->srcid here and in fsl_edma_resume_early() skip active channels that legitimately have srcid == 0? Unassigned channels are already runtime-suspended and caught by pm_runtime_status_suspended(). On FSL_EDMA_DRV_SPLIT_REG controllers without FSL_EDMA_DRV_HAS_PD (such as imx8ulp, imx93, imx95, and s32g2), an allocated, runtime-active channel has srcid == 0 when used for DMA_MEMCPY or when channel 0 is allocated via fsl_edma3_xlate() on controllers without FSL_EDMA_DRV_HAS_CHMUX (such as imx93-edma3 and s32g2-edma). Skipping those channels leaves them in pm_state == RUNNING across system suspend and skips clearing their TCD csr on resume. > @@ -926,19 +1079,56 @@ static int fsl_edma_resume_early(struct device *dev) > { > struct fsl_edma_engine *fsl_edma = dev_get_drvdata(dev); > struct fsl_edma_chan *fsl_chan; > - struct edma_regs *regs = &fsl_edma->regs; > int i; > > for (i = 0; i < fsl_edma->n_chans; i++) { > fsl_chan = &fsl_edma->chans[i]; > if (fsl_edma->chan_masked & BIT(i)) > continue; > + > + if (pm_runtime_status_suspended(&fsl_chan->vchan.chan.dev->device) || > + (!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_HAS_PD) && > + (fsl_edma->drvdata->flags & FSL_EDMA_DRV_SPLIT_REG) && > + !fsl_chan->srcid)) > + continue; > + > fsl_chan->pm_state = RUNNING; > edma_write_tcdreg(fsl_chan, 0, csr); > if (fsl_chan->srcid != 0) > fsl_edma_chan_mux(fsl_chan, fsl_chan->srcid, true); > } > > + return 0; > +} > + > +/* edma engine runtime system/resume */ > +static int fsl_edma_runtime_suspend(struct device *dev) > +{ > + struct fsl_edma_engine *fsl_edma = dev_get_drvdata(dev); > + > + clk_bulk_disable_unprepare(fsl_edma->drvdata->dmamuxs, fsl_edma->muxclk); > + > + clk_disable_unprepare(fsl_edma->dmaclk); > + > + return 0; > +} > + > +static int fsl_edma_runtime_resume(struct device *dev) > +{ > + struct fsl_edma_engine *fsl_edma = dev_get_drvdata(dev); > + struct edma_regs *regs = &fsl_edma->regs; > + int ret; > + > + ret = clk_bulk_prepare_enable(fsl_edma->drvdata->dmamuxs, fsl_edma->muxclk); > + if (ret) > + return ret; > + > + ret = clk_prepare_enable(fsl_edma->dmaclk); > + if (ret) { > + clk_bulk_disable_unprepare(fsl_edma->drvdata->dmamuxs, fsl_edma->muxclk); > + return ret; > + } > + > if (!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_SPLIT_REG)) > edma_writel(fsl_edma, EDMA_CR_ERGA | EDMA_CR_ERCA, regs->cr); > > return 0; > } [Severity: High] Does moving the regs->cr write from fsl_edma_resume_early() to fsl_edma_runtime_resume() lose the EDMA_CR_ERGA | EDMA_CR_ERCA setting across system suspend when a channel is allocated? When any channel is allocated, fsl_edma_alloc_chan_resources() holds a runtime PM reference that keeps both the channel and the parent controller device RPM_ACTIVE across system suspend and resume. Because fsl_edma_pm_ops does not use pm_runtime_force_suspend() and pm_runtime_force_resume(), fsl_edma_runtime_resume() does not run during system resume in that case, leaving regs->cr unconfigured on non-SPLIT_REG controllers (vf610, ls1028a, and imx7ulp). -- Sashiko AI review · https://sashiko.dev/#/patchset/20261125-b4-edma-runtime-opt-mo-v8-0-81345a3bfb52@oss.nxp.com?part=5 ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-25 11:23 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-25 10:58 [PATCH v8 0/5] add runtime suspend/resume support joy.zou 2026-11-25 10:58 ` [PATCH v8 1/5] dmaengine: fsl-edma: use devm_clk_get_optional_enabled() for channel clock joy.zou 2026-11-25 10:58 ` [PATCH v8 2/5] dmaengine: fsl-edma: use devm_clk_get_optional() for DMA engine clock joy.zou 2026-11-25 10:58 ` [PATCH v8 3/5] dmaengine: fsl-edma: convert DMAMUX clock handling to bulk clock API joy.zou 2026-11-25 10:58 ` [PATCH v8 4/5] dmaengine: mcf-edma: enable runtime PM for eDMA engine and channel Joy Zou 2026-11-25 11:03 ` sashiko-bot 2026-11-25 10:58 ` [PATCH v8 5/5] dmaengine: fsl-edma: add runtime suspend/resume support Joy Zou 2026-11-25 11:23 ` sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox