Skip to contentSkip to conversation

ASoC: fsl_asrc: Fix probe and resource management issues

PATCH Superseded [email protected] 2 participants 12 messages Nov 12 – Nov 13

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ASoC: fsl_asrc: Fix probe and resource management issues

From: bui duc phuc <[email protected]>

Hi all,

This series improves error handling and resource management in the fsl_asrc probe function. It fixes deferred clock handling and runtime PM usage count, ensures the IRQ is requested after device initialization, and moves runtime PM cleanup to devm.

Compile-tested only.

Best regards,
Phuc

bui duc phuc (5):
ASoC: fsl_asrc: Improve probe error handling
ASoC: fsl_asrc: Fix handling of deferred spba clock
ASoC: fsl_asrc: Fix runtime PM usage count on init failure
ASoC: fsl_asrc: Request the IRQ after the device is initialized
ASoC: fsl_asrc: Use devm for runtime PM cleanup

 sound/soc/fsl/fsl_asrc.c | 92 ++++++++++++++++++++++------------------
 1 file changed, 51 insertions(+), 41 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/5 ASoC: fsl_asrc: Improve probe error handling

From: bui duc phuc <[email protected]>

Use dev_err_probe() when retrieving clocks to avoid logging errors for deferred probes. Also remove redundant error messages from the probe function when failures are already reported deeper in the call chain.

---
 sound/soc/fsl/fsl_asrc.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)
sound/soc/fsl/fsl_asrc.c +11 -18
index faf348dd582d..055593d5d37b 100644
@@ -1301,22 +1301,18 @@ static int fsl_asrc_probe(struct platform_device *pdev)
 
 	ret = devm_request_irq(&pdev->dev, irq, fsl_asrc_isr, 0,
 			       dev_name(&pdev->dev), asrc);
-	if (ret) {
-		dev_err(&pdev->dev, "failed to claim irq %u: %d\n", irq, ret);
+	if (ret)
 		return ret;
-	}
 
 	asrc->mem_clk = devm_clk_get(&pdev->dev, "mem");
-	if (IS_ERR(asrc->mem_clk)) {
-		dev_err(&pdev->dev, "failed to get mem clock\n");
-		return PTR_ERR(asrc->mem_clk);
-	}
+	if (IS_ERR(asrc->mem_clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(asrc->mem_clk),
+				     "failed to get mem clock\n");
 
 	asrc->ipg_clk = devm_clk_get(&pdev->dev, "ipg");
-	if (IS_ERR(asrc->ipg_clk)) {
-		dev_err(&pdev->dev, "failed to get ipg clock\n");
-		return PTR_ERR(asrc->ipg_clk);
-	}
+	if (IS_ERR(asrc->ipg_clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(asrc->ipg_clk),
+				     "failed to get ipg clock\n");
 
 	asrc->spba_clk = devm_clk_get(&pdev->dev, "spba");
 	if (IS_ERR(asrc->spba_clk))
@@ -1325,10 +1321,9 @@ static int fsl_asrc_probe(struct platform_device *pdev)
 	for (i = 0; i < ASRC_CLK_MAX_NUM; i++) {
 		sprintf(tmp, "asrck_%x", i);
 		asrc_priv->asrck_clk[i] = devm_clk_get(&pdev->dev, tmp);
-		if (IS_ERR(asrc_priv->asrck_clk[i])) {
-			dev_err(&pdev->dev, "failed to get %s clock\n", tmp);
-			return PTR_ERR(asrc_priv->asrck_clk[i]);
-		}
+		if (IS_ERR(asrc_priv->asrck_clk[i]))
+			return dev_err_probe(&pdev->dev, PTR_ERR(asrc_priv->asrck_clk[i]),
+					     "failed to get %s clock\n", tmp);
 	}
 
 	asrc_priv->soc = of_device_get_match_data(&pdev->dev);
@@ -1443,10 +1438,8 @@ static int fsl_asrc_probe(struct platform_device *pdev)
 
 	ret = devm_snd_soc_register_component(&pdev->dev, &fsl_asrc_component,
 					      fsl_asrc_dai, ARRAY_SIZE(fsl_asrc_dai));
-	if (ret) {
-		dev_err(&pdev->dev, "failed to register ASoC DAI\n");
+	if (ret)
 		goto err_pm_get_sync;
-	}
 
 	ret = fsl_asrc_m2m_init(asrc);
 	if (ret) {
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/5 ASoC: fsl_asrc: Fix handling of deferred spba clock

In reply to [email protected]

From: bui duc phuc <[email protected]>

The current device tree binding does not describe the spba clock as optional. However, the driver currently continues probing when devm_clk_get() returns an error.

Return -EPROBE_DEFER when the clock provider is not ready, allowing the driver to retry probing later. Preserve the existing behavior for other errors.

Fixes 13b8a97a760e ("ASoC: fsl_asrc: spba clock is needed by asrc device")
---
 sound/soc/fsl/fsl_asrc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
sound/soc/fsl/fsl_asrc.c +4 -1
index 055593d5d37b..c91ffb5e0c5e 100644
@@ -1315,8 +1315,11 @@ static int fsl_asrc_probe(struct platform_device *pdev)
 				     "failed to get ipg clock\n");
 
 	asrc->spba_clk = devm_clk_get(&pdev->dev, "spba");
-	if (IS_ERR(asrc->spba_clk))
+	if (IS_ERR(asrc->spba_clk)) {
+		if (PTR_ERR(asrc->spba_clk) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
 		dev_warn(&pdev->dev, "failed to get spba clock\n");
+	}
 
 	for (i = 0; i < ASRC_CLK_MAX_NUM; i++) {
 		sprintf(tmp, "asrck_%x", i);
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH 2/5] ASoC: fsl_asrc: Fix handling of deferred spba clock

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: - [Medium] ASoC: fsl_asrc: stale register states…

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:
- [Medium] ASoC: fsl_asrc: stale register states in fsl_asrc_config_pair() [1]
--

commit 62ba61794f6dac52b1de47eef34f329de32edee9
Author: bui duc phuc <[email protected]>

ASoC: fsl_asrc: Fix handling of deferred spba clock

This commit updates fsl_asrc_probe() to return -EPROBE_DEFER when devm_clk_get() for the spba clock defers, while preserving a warning for other error codes.

Quoted 5 lines
sound/soc/fsl/fsl_asrc.c +0 -0
index 055593d5d37b6..c91ffb5e0c5e8 100644

sound/soc/fsl/fsl_asrc.c static int fsl_asrc_probe(struct platform_device *pdev) · line 1322

Quoted 9 lines
sound/soc/fsl/fsl_asrc.c +4 -1
@@ -1315,8 +1315,11 @@ static int fsl_asrc_probe(struct platform_device *pdev)
 				     "failed to get ipg clock\n");
 
 	asrc->spba_clk = devm_clk_get(&pdev->dev, "spba");
-	if (IS_ERR(asrc->spba_clk))
+	if (IS_ERR(asrc->spba_clk)) {
+		if (PTR_ERR(asrc->spba_clk) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
 		dev_warn(&pdev->dev, "failed to get spba clock\n");
+	}

[Severity: Medium]
This problem wasn't introduced by this patch, but can [1] fsl_asrc_config_pair() leave hardware registers with stale values across a warm reboot?

Earlier in fsl_asrc_probe(), devm_regmap_init_mmio() initializes the regmap cache to all-zero defaults without issuing a hardware soft-reset first:

sound/soc/fsl/fsl_asrc.c:fsl_asrc_probe() {
	...
	asrc->regmap = devm_regmap_init_mmio(&pdev->dev, regs, &fsl_asrc_regmap_config);
	...
}

When fsl_asrc_config_pair() later calls regmap_update_bits() on REG_ASRCNCR, REG_ASRCDR, REG_ASRMCR1, or REG_ASRCFG with a target field value of 0 (for example, a 24-bit audio width or 1:1 clock ratio), regmap_update_bits() sees 0 in the cache and skips the register write, leaving the hardware running with non-zero dividers and modes from the prior boot.

[1] https://sashiko.dev/#/bug/linux-75f0b96f-de73-4139-881e-4c69d6455f22

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw

Re: [PATCH 2/5] ASoC: fsl_asrc: Fix handling of deferred spba clock

Quoted 14 lines

[Severity: Medium]
This problem wasn't introduced by this patch, but can [1] fsl_asrc_config_pair() leave hardware registers with stale values across a warm reboot?

Earlier in fsl_asrc_probe(), devm_regmap_init_mmio() initializes the regmap cache to all-zero defaults without issuing a hardware soft-reset first:

sound/soc/fsl/fsl_asrc.c:fsl_asrc_probe() {
        ...
        asrc->regmap = devm_regmap_init_mmio(&pdev->dev, regs, &fsl_asrc_regmap_config);
        ...
}
Quoted 6 lines

When fsl_asrc_config_pair() later calls regmap_update_bits() on REG_ASRCNCR, REG_ASRCDR, REG_ASRMCR1, or REG_ASRCFG with a target field value of 0 (for example, a 24-bit audio width or 1:1 clock ratio), regmap_update_bits() sees 0 in the cache and skips the register write, leaving the hardware running with non-zero dividers and modes from the prior boot.

This is not related to this patch, but I checked fsl_asrc_config_pair():

- REG_ASRCFG is volatile, so it is read from the hardware and is not affected.
- REG_ASRCNCR always gets a non-zero channel count (channel_bits = 4), so the write is never skipped.
- REG_ASRMCR1 is affected: with 24-bit input and output, IWD and OW16 are both 0, so the write can be skipped and a previous width kept, e.g. after an unbind/bind.
- REG_ASRCSR and REG_ASRCDR can be affected only in rare cases

One way to fix this would be to write the register defaults to the hardware in fsl_asrc_init().
I would prefer to keep it out of this series to keep its scope unchanged.

#5 lore raw

PATCH 3/5 ASoC: fsl_asrc: Fix runtime PM usage count on init failure

In reply to [email protected]

From: bui duc phuc <[email protected]>

Balance the runtime PM usage count when fsl_asrc_init() fails after pm_runtime_get_sync() succeeds.

Fixes 286d658477a4 ("ASoC: fsl_asrc: register m2m platform device")
---
 sound/soc/fsl/fsl_asrc.c | 1 +
 1 file changed, 1 insertion(+)
sound/soc/fsl/fsl_asrc.c +1 -0
index c91ffb5e0c5e..f7ac60724c6c 100644
@@ -1432,6 +1432,7 @@ static int fsl_asrc_probe(struct platform_device *pdev)
 	ret = fsl_asrc_init(asrc);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to init asrc %d\n", ret);
+		pm_runtime_put_noidle(&pdev->dev);
 		goto err_pm_get_sync;
 	}
 
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH 3/5] ASoC: fsl_asrc: Fix runtime PM usage count on init failure

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] ASoC: fsl_asrc: wrong Fixes tag and pm_runtime_get_sync() in commit msg --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] ASoC: fsl_asrc: wrong Fixes tag and pm_runtime_get_sync() in commit msg
--

commit 503d1e3d04da11b4fe4bd7121c2929541b45d6b1
Author: bui duc phuc <[email protected]>

Quoted 7 lines

ASoC: fsl_asrc: Fix runtime PM usage count on init failure

Balance the runtime PM usage count when fsl_asrc_init() fails after pm_runtime_get_sync() succeeds.

Fixes 286d658477a4 ("ASoC: fsl_asrc: register m2m platform device")

[Severity: Low]
Commit 286d658477a4 ("ASoC: fsl_asrc: register m2m platform device") only added fsl_asrc_m2m_init() at the end of fsl_asrc_probe() and did not touch fsl_asrc_init() or its error path. The unbalanced runtime PM usage count on fsl_asrc_init() failure was introduced by commit cab04ab5900f ("ASoC:
fsl_asrc: Don't use devm_regmap_init_mmio_clk"), so the Fixes tag should point to that commit instead.

Also, fsl_asrc_probe() acquires the reference via pm_runtime_resume_and_get() rather than pm_runtime_get_sync() since commit d05040741afe ("ASoC: fsl_asrc:
using pm_runtime_resume_and_get to simplify the code").

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#7 lore raw

Re: [PATCH 3/5] ASoC: fsl_asrc: Fix runtime PM usage count on init failure

Quoted 9 lines

[Severity: Low]
Commit 286d658477a4 ("ASoC: fsl_asrc: register m2m platform device") only added fsl_asrc_m2m_init() at the end of fsl_asrc_probe() and did not touch fsl_asrc_init() or its error path. The unbalanced runtime PM usage count on fsl_asrc_init() failure was introduced by commit cab04ab5900f ("ASoC:
fsl_asrc: Don't use devm_regmap_init_mmio_clk"), so the Fixes tag should point to that commit instead.

Quoted 4 lines

Also, fsl_asrc_probe() acquires the reference via pm_runtime_resume_and_get() rather than pm_runtime_get_sync() since commit d05040741afe ("ASoC: fsl_asrc:
using pm_runtime_resume_and_get to simplify the code").

Good catch, thanks.
I will fix the Fixes tag to point to cab04ab5900f and mention pm_runtime_resume_and_get() in the commit message in v2.

#8 lore raw

PATCH 4/5 ASoC: fsl_asrc: Request the IRQ after the device is initialized

In reply to [email protected]

From: bui duc phuc <[email protected]>

Request the IRQ after fsl_asrc_init(), while the device is still runtime active, so that the interrupt handler cannot run before the device is initialized.

If requesting the IRQ fails, balance the runtime PM usage count before proceeding with cleanup.

---
 sound/soc/fsl/fsl_asrc.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
sound/soc/fsl/fsl_asrc.c +8 -5
index f7ac60724c6c..c97f814d7358 100644
@@ -1299,11 +1299,6 @@ static int fsl_asrc_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return irq;
 
-	ret = devm_request_irq(&pdev->dev, irq, fsl_asrc_isr, 0,
-			       dev_name(&pdev->dev), asrc);
-	if (ret)
-		return ret;
-
 	asrc->mem_clk = devm_clk_get(&pdev->dev, "mem");
 	if (IS_ERR(asrc->mem_clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(asrc->mem_clk),
@@ -1436,6 +1431,14 @@ static int fsl_asrc_probe(struct platform_device *pdev)
 		goto err_pm_get_sync;
 	}
 
+	/* Request the IRQ only once the device is initialized */
+	ret = devm_request_irq(&pdev->dev, irq, fsl_asrc_isr, 0,
+			       dev_name(&pdev->dev), asrc);
+	if (ret) {
+		pm_runtime_put_noidle(&pdev->dev);
+		goto err_pm_get_sync;
+	}
+
 	ret = pm_runtime_put_sync(&pdev->dev);
 	if (ret < 0 && ret != -ENOSYS)
 		goto err_pm_get_sync;
Signature · 1 line
2.43.0
#9 lore raw

PATCH 5/5 ASoC: fsl_asrc: Use devm for runtime PM cleanup

In reply to [email protected]

From: bui duc phuc <[email protected]>

On unbind, fsl_asrc_remove() gates the clocks before devres unregisters the component and frees the IRQ, while the component may still be in use.

Move the cleanup to devm. The action that disables the clocks is registered before devm_pm_runtime_enable(), so it runs last, after runtime PM is disabled, as in fsl_asrc_remove().

---
 sound/soc/fsl/fsl_asrc.c | 48 ++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 19 deletions(-)
sound/soc/fsl/fsl_asrc.c +29 -19
index c97f814d7358..09e09164a106 100644
@@ -1258,6 +1258,15 @@ static int fsl_asrc_m2m_pair_resume(struct fsl_asrc_pair *pair)
 static int fsl_asrc_runtime_resume(struct device *dev);
 static int fsl_asrc_runtime_suspend(struct device *dev);
 
+/* devm action: runtime suspend the device if it is not runtime suspended yet */
+static void fsl_asrc_runtime_suspend_action(void *data)
+{
+	struct device *dev = data;
+
+	if (!pm_runtime_status_suspended(dev))
+		fsl_asrc_runtime_suspend(dev);
+}
+
 static int fsl_asrc_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
@@ -1413,22 +1422,34 @@ static int fsl_asrc_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, asrc);
 	spin_lock_init(&asrc->lock);
-	pm_runtime_enable(&pdev->dev);
+
+	/*
+	 * Ensure the device is suspended after the IRQ and component
+	 * have been released.
+	 */
+	ret = devm_add_action(&pdev->dev, fsl_asrc_runtime_suspend_action,
+			      &pdev->dev);
+	if (ret)
+		return ret;
+
+	ret = devm_pm_runtime_enable(&pdev->dev);
+	if (ret)
+		return ret;
 	if (!pm_runtime_enabled(&pdev->dev)) {
 		ret = fsl_asrc_runtime_resume(&pdev->dev);
 		if (ret)
-			goto err_pm_disable;
+			return ret;
 	}
 
 	ret = pm_runtime_resume_and_get(&pdev->dev);
 	if (ret < 0)
-		goto err_pm_get_sync;
+		return ret;
 
 	ret = fsl_asrc_init(asrc);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to init asrc %d\n", ret);
 		pm_runtime_put_noidle(&pdev->dev);
-		goto err_pm_get_sync;
+		return ret;
 	}
 
 	/* Request the IRQ only once the device is initialized */
@@ -1436,32 +1457,25 @@ static int fsl_asrc_probe(struct platform_device *pdev)
 			       dev_name(&pdev->dev), asrc);
 	if (ret) {
 		pm_runtime_put_noidle(&pdev->dev);
-		goto err_pm_get_sync;
+		return ret;
 	}
 
 	ret = pm_runtime_put_sync(&pdev->dev);
 	if (ret < 0 && ret != -ENOSYS)
-		goto err_pm_get_sync;
+		return ret;
 
 	ret = devm_snd_soc_register_component(&pdev->dev, &fsl_asrc_component,
 					      fsl_asrc_dai, ARRAY_SIZE(fsl_asrc_dai));
 	if (ret)
-		goto err_pm_get_sync;
+		return ret;
 
 	ret = fsl_asrc_m2m_init(asrc);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to init m2m device %d\n", ret);
-		goto err_pm_get_sync;
+		return ret;
 	}
 
 	return 0;
-
-err_pm_get_sync:
-	if (!pm_runtime_status_suspended(&pdev->dev))
-		fsl_asrc_runtime_suspend(&pdev->dev);
-err_pm_disable:
-	pm_runtime_disable(&pdev->dev);
-	return ret;
 }
 
 static void fsl_asrc_remove(struct platform_device *pdev)
@@ -1469,10 +1483,6 @@ static void fsl_asrc_remove(struct platform_device *pdev)
 	struct fsl_asrc *asrc = dev_get_drvdata(&pdev->dev);
 
 	fsl_asrc_m2m_exit(asrc);
-
-	pm_runtime_disable(&pdev->dev);
-	if (!pm_runtime_status_suspended(&pdev->dev))
-		fsl_asrc_runtime_suspend(&pdev->dev);
 }
 
 static int fsl_asrc_runtime_resume(struct device *dev)
Signature · 1 line
2.43.0
#10 lore raw

Re: [PATCH 5/5] ASoC: fsl_asrc: Use devm for runtime PM cleanup

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] ASoC: fsl_asrc: premature suspend action registration in fsl_asrc_probe() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] ASoC: fsl_asrc: premature suspend action registration in fsl_asrc_probe()
--

commit d552655304748475ea350f20bd450d9524c4e316
Author: bui duc phuc <[email protected]>

ASoC: fsl_asrc: Use devm for runtime PM cleanup

This commit replaces manual runtime PM cleanup in fsl_asrc_probe() and fsl_asrc_remove() with devm_add_action() and devm_pm_runtime_enable().

Quoted 34 lines
sound/soc/fsl/fsl_asrc.c +18 -1
index c97f814d7358b..09e09164a1061 100644
@@ -1258,6 +1258,15 @@ static int fsl_asrc_m2m_pair_resume(struct fsl_asrc_pair *pair)
 static int fsl_asrc_runtime_resume(struct device *dev);
 static int fsl_asrc_runtime_suspend(struct device *dev);
 
+/* devm action: runtime suspend the device if it is not runtime suspended yet */
+static void fsl_asrc_runtime_suspend_action(void *data)
+{
+	struct device *dev = data;
+
+	if (!pm_runtime_status_suspended(dev))
+		fsl_asrc_runtime_suspend(dev);
+}
+
 static int fsl_asrc_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
@@ -1413,22 +1422,34 @@ static int fsl_asrc_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, asrc);
 	spin_lock_init(&asrc->lock);
-	pm_runtime_enable(&pdev->dev);
+
+	/*
+	 * Ensure the device is suspended after the IRQ and component
+	 * have been released.
+	 */
+	ret = devm_add_action(&pdev->dev, fsl_asrc_runtime_suspend_action,
+			      &pdev->dev);
+	if (ret)
+		return ret;

sound/soc/fsl/fsl_asrc.c static int fsl_asrc_probe(struct platform_device *pdev) · line 1442

Quoted 10 lines
sound/soc/fsl/fsl_asrc.c +5 -1
+
+	ret = devm_pm_runtime_enable(&pdev->dev);
+	if (ret)
+		return ret;
 	if (!pm_runtime_enabled(&pdev->dev)) {
 		ret = fsl_asrc_runtime_resume(&pdev->dev);
 		if (ret)
-			goto err_pm_disable;
+			return ret;
 	}

[Severity: Medium]
If CONFIG_PM is disabled and fsl_asrc_runtime_resume() fails here, does devres unwind end up calling fsl_asrc_runtime_suspend() while the clocks are still disabled?

When CONFIG_PM is disabled, pm_runtime_enabled() and pm_runtime_status_suspended() both return false. If fsl_asrc_runtime_resume() fails, it cleans up any clocks it enabled and returns an error, which now triggers fsl_asrc_runtime_suspend_action(). fsl_asrc_runtime_suspend() then reads the volatile REG_ASRCFG register over MMIO with all ASRC clocks gated (which can cause an external abort or bus hang on i.MX) and calls clk_disable_unprepare() on clocks that were never enabled.

Registering fsl_asrc_runtime_suspend_action() after the !pm_runtime_enabled() block (or using devm_add_action_or_reset() after devm_pm_runtime_enable() with the !pm_runtime_enabled() resume handled first) would avoid suspending an unresumed device.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#11 lore raw

Re: [PATCH 5/5] ASoC: fsl_asrc: Use devm for runtime PM cleanup

Quoted 14 lines

[Severity: Medium]
If CONFIG_PM is disabled and fsl_asrc_runtime_resume() fails here, does devres unwind end up calling fsl_asrc_runtime_suspend() while the clocks are still disabled?

When CONFIG_PM is disabled, pm_runtime_enabled() and pm_runtime_status_suspended() both return false. If fsl_asrc_runtime_resume() fails, it cleans up any clocks it enabled and returns an error, which now triggers fsl_asrc_runtime_suspend_action(). fsl_asrc_runtime_suspend() then reads the volatile REG_ASRCFG register over MMIO with all ASRC clocks gated (which can cause an external abort or bus hang on i.MX) and calls clk_disable_unprepare() on clocks that were never enabled.

Quoted 5 lines

Registering fsl_asrc_runtime_suspend_action() after the !pm_runtime_enabled() block (or using devm_add_action_or_reset() after devm_pm_runtime_enable() with the !pm_runtime_enabled() resume handled first) would avoid suspending an unresumed device.

Good catch, thanks. With CONFIG_PM disabled, a failed fsl_asrc_runtime_resume() would indeed run the action on a device that is not powered.

I'd like to keep the action registered before devm_pm_runtime_enable(), so it still runs after runtime PM is disabled. In v2 I'll drop it with devm_remove_action() in that error path instead.