Skip to contentSkip to conversation

ASoC: fsl_asrc: Fix probe and resource management issues

PATCH In review [email protected] 2 participants 8 messages Nov 13 – Nov 20

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 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.

Link v1:
https://lore.kernel.org/all/[email protected]/

Change in v2:
- Update the commit based on Sashiko's review.
- Add handling for CONFIG_PM being disabled.
- Add a patch to use devm for M2M cleanup.

Compile-tested only.

Best regards,
Phuc

bui duc phuc (6):
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
ASoC: fsl_asrc: Use devm for m2m cleanup

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

PATCH v2 1/6 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 v2 2/6 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

PATCH v2 3/6 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_resume_and_get() succeeds.

Fixes cab04ab5900f ("ASoC: fsl_asrc: Don't use devm_regmap_init_mmio_clk")

---

Change in v2:
- Update the commit based on Sashiko's review.

 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
#4 lore raw

PATCH v2 4/6 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
#5 lore raw

PATCH v2 5/6 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().

---

Change in v2:
- Remove fsl_asrc_runtime_suspend_action when CONFIG_PM is disabled.

 sound/soc/fsl/fsl_asrc.c | 54 +++++++++++++++++++++++++---------------
 1 file changed, 34 insertions(+), 20 deletions(-)
sound/soc/fsl/fsl_asrc.c +34 -20
index c97f814d7358..317ce0a5c765 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,38 @@ 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;
+		if (ret) {
+			devm_remove_action(&pdev->dev,
+					   fsl_asrc_runtime_suspend_action,
+					   &pdev->dev);
+			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 +1461,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 +1487,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
#6 lore raw

PATCH v2 6/6 ASoC: fsl_asrc: Use devm for m2m cleanup

In reply to [email protected]

From: bui duc phuc <[email protected]>

Register fsl_asrc_m2m_exit() as a devm action and drop fsl_asrc_remove(), which has nothing else left to do.

---
 sound/soc/fsl/fsl_asrc.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
sound/soc/fsl/fsl_asrc.c +6 -9
index 317ce0a5c765..c8db02f16453 100644
@@ -1267,6 +1267,11 @@ static void fsl_asrc_runtime_suspend_action(void *data)
 		fsl_asrc_runtime_suspend(dev);
 }
 
+static void fsl_asrc_m2m_exit_action(void *data)
+{
+	fsl_asrc_m2m_exit(data);
+}
+
 static int fsl_asrc_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
@@ -1479,14 +1484,7 @@ static int fsl_asrc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	return 0;
-}
-
-static void fsl_asrc_remove(struct platform_device *pdev)
-{
-	struct fsl_asrc *asrc = dev_get_drvdata(&pdev->dev);
-
-	fsl_asrc_m2m_exit(asrc);
+	return devm_add_action_or_reset(&pdev->dev, fsl_asrc_m2m_exit_action, asrc);
 }
 
 static int fsl_asrc_runtime_resume(struct device *dev)
@@ -1648,7 +1646,6 @@ MODULE_DEVICE_TABLE(of, fsl_asrc_ids);
 
 static struct platform_driver fsl_asrc_driver = {
 	.probe = fsl_asrc_probe,
-	.remove = fsl_asrc_remove,
 	.driver = {
 		.name = "fsl-asrc",
 		.of_match_table = fsl_asrc_ids,
Signature · 1 line
2.43.0
maintainer
#7 lore raw
In reply to [email protected]
Quoted 4 lines · On Fri, 13 Nov 2026 12:07:21 +0700, [email protected] wrote:

ASoC: fsl_asrc: Fix probe and resource management issues

From: bui duc phuc <[email protected]>

Quoted 8 lines

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.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.5

Thanks!

[1/6] ASoC: fsl_asrc: Improve probe error handling

      https://git.kernel.org/broonie/sound/c/c41412f46219
[2/6] ASoC: fsl_asrc: Fix handling of deferred spba clock
      https://git.kernel.org/broonie/sound/c/a16853bece06
[3/6] ASoC: fsl_asrc: Fix runtime PM usage count on init failure
      https://git.kernel.org/broonie/sound/c/dcb503f01380
[4/6] ASoC: fsl_asrc: Request the IRQ after the device is initialized
      https://git.kernel.org/broonie/sound/c/ab7cfd1b36a2
[5/6] ASoC: fsl_asrc: Use devm for runtime PM cleanup
      https://git.kernel.org/broonie/sound/c/b4b22bdc2572
[6/6] ASoC: fsl_asrc: Use devm for m2m cleanup
      https://git.kernel.org/broonie/sound/c/0f8ea2391e29

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark