Skip to contentSkip to conversation

dmaengine: fsl-edma: Fix clk leak on alloc_chan_resources failure

PATCH Superseded Zhen Ni 2 participants 5 messages Oct 10, 2025 – Oct 14, 2025

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Zhen Ni

author
#0 lore raw

PATCH 1/1 dmaengine: fsl-edma: Fix clk leak on alloc_chan_resources failure

When fsl_edma_alloc_chan_resources() fails after clk_prepare_enable(), the error paths only free IRQs and destroy the TCD pool, but forget to call clk_disable_unprepare(). This causes the channel clock to remain enabled, leaking power and resources.

Fix it by disabling the channel clock in the error unwind path.

Fixes d8d4355861d8 ("dmaengine: fsl-edma: add i.MX8ULP edma support")
---
 drivers/dma/fsl-edma-common.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/dma/fsl-edma-common.c +2 -0
index 4976d7dde080..bd673f08f610 100644
@@ -852,6 +852,8 @@ 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);
+	if (fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_HAS_CHCLK)
+		clk_disable_unprepare(fsl_chan->clk);
 
 	return ret;
 }
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 19 lines · Zhen Ni

When fsl_edma_alloc_chan_resources() fails after clk_prepare_enable(), the error paths only free IRQs and destroy the TCD pool, but forget to call clk_disable_unprepare(). This causes the channel clock to remain enabled, leaking power and resources.

Fix it by disabling the channel clock in the error unwind path.

Fixes d8d4355861d8 ("dmaengine: fsl-edma: add i.MX8ULP edma support")
---
 drivers/dma/fsl-edma-common.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/dma/fsl-edma-common.c +0 -0
index 4976d7dde080..bd673f08f610 100644

drivers/dma/fsl-edma-common.c int fsl_edma_alloc_chan_resources(struct dma_chan *chan) · line 856

Quoted 5 lines
drivers/dma/fsl-edma-common.c +2 -0
@@ -852,6 +852,8 @@ 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);
+	if (fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_HAS_CHCLK)
+		clk_disable_unprepare(fsl_chan->clk);

Thank you for your fix. clk API do nothing when input is NULL.

So check if (fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_HAS_CHCLK) is reduntante.

I saw existed code have such check. You can clean up it.

Only need keep check at probe()
fsl_chan->clk = devm_clk_get_enabled()

Frank

Quoted 6 lines
drivers/dma/fsl-edma-common.c +0 -1
 	return ret;
 }
--

2.20.1

author
#2 lore raw

PATCH v2 1/1 dmaengine: fsl-edma: Fix clk leak on alloc_chan_resources failure

In reply to Zhen Ni

When fsl_edma_alloc_chan_resources() fails after clk_prepare_enable(), the error paths only free IRQs and destroy the TCD pool, but forget to call clk_disable_unprepare(). This causes the channel clock to remain enabled, leaking power and resources. Since clk_disable_unprepare() is safe to call with a NULL clk, the FSL_EDMA_DRV_HAS_CHCLK check is reduntante.

Fix it by disabling the channel clock in the error unwind path. Also clean up similar redundant checks in the driver for consistency.

Fixes d8d4355861d8 ("dmaengine: fsl-edma: add i.MX8ULP edma support")

---
Changes in v2:
- Remove FSL_EDMA_DRV_HAS_CHCLK check

---
 drivers/dma/fsl-edma-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/fsl-edma-common.c +2 -2
index 4976d7dde080..3007d5b7db55 100644
@@ -852,6 +852,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);
 
 	return ret;
 }
@@ -883,8 +884,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;
-	if (fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_HAS_CHCLK)
-		clk_disable_unprepare(fsl_chan->clk);
+	clk_disable_unprepare(fsl_chan->clk);
 }
 
 void fsl_edma_cleanup_vchan(struct dma_device *dmadev)
Signature · 1 line
2.20.1
maintainer
#3 lore raw
Quoted 34 lines · Zhen Ni

When fsl_edma_alloc_chan_resources() fails after clk_prepare_enable(), the error paths only free IRQs and destroy the TCD pool, but forget to call clk_disable_unprepare(). This causes the channel clock to remain enabled, leaking power and resources. Since clk_disable_unprepare() is safe to call with a NULL clk, the FSL_EDMA_DRV_HAS_CHCLK check is reduntante.

Fix it by disabling the channel clock in the error unwind path. Also clean up similar redundant checks in the driver for consistency.

Fixes d8d4355861d8 ("dmaengine: fsl-edma: add i.MX8ULP edma support")

---
Changes in v2:
- Remove FSL_EDMA_DRV_HAS_CHCLK check

---
 drivers/dma/fsl-edma-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/fsl-edma-common.c +1 -0
index 4976d7dde080..3007d5b7db55 100644
@@ -852,6 +852,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);
 
 	return ret;
 }

drivers/dma/fsl-edma-common.c void fsl_edma_free_chan_resources(struct dma_chan *chan) · line 887

Quoted 6 lines
drivers/dma/fsl-edma-common.c +1 -2
@@ -883,8 +884,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;
-	if (fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_HAS_CHCLK)
-		clk_disable_unprepare(fsl_chan->clk);
+	clk_disable_unprepare(fsl_chan->clk);

I may not say clearly at v1. this is cleanup patch, need seperated patch

You need two patches

first ones with fixes tags, to fix fsl_edma_alloc_chan_resources()'s problem

the second patches to do cleanup, remove redundant check if (fsl_edma_drvflags(fsl_chan) & FSL_EDMA_DRV_HAS_CHCLK)

Frank

Quoted 6 lines
drivers/dma/fsl-edma-common.c +0 -1
 }
 
 void fsl_edma_cleanup_vchan(struct dma_device *dmadev)
--

2.20.1

author
#4 lore raw

PATCH v3 1/1 dmaengine: fsl-edma: Fix clk leak on alloc_chan_resources failure

In reply to Zhen Ni

When fsl_edma_alloc_chan_resources() fails after clk_prepare_enable(), the error paths only free IRQs and destroy the TCD pool, but forget to call clk_disable_unprepare(). This causes the channel clock to remain enabled, leaking power and resources.

Fix it by disabling the channel clock in the error unwind path.

Fixes d8d4355861d8 ("dmaengine: fsl-edma: add i.MX8ULP edma support")

---
Changes in v2:
- Remove FSL_EDMA_DRV_HAS_CHCLK check
Changes in v3:
- Remove cleanup

---
 drivers/dma/fsl-edma-common.c | 1 +
 1 file changed, 1 insertion(+)
drivers/dma/fsl-edma-common.c +1 -0
index 4976d7dde080..11655dcc4d6c 100644
@@ -852,6 +852,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);
 
 	return ret;
 }
Signature · 1 line
2.20.1