[PATCH 2/3] ASoC: atmel: mchp-spdiftx: Use devm helpers for runtime PM

phucduc.bui at gmail.com phucduc.bui at gmail.com
Fri Nov 20 01:43:53 PST 2026


From: bui duc phuc <phucduc.bui at gmail.com>

Use devm_pm_runtime_enable() and a devm action to handle runtime PM
cleanup automatically.

This removes the manual runtime PM cleanup from the probe error
paths and the remove callback.

Signed-off-by: bui duc phuc <phucduc.bui at gmail.com>
---
 sound/soc/atmel/mchp-spdiftx.c | 46 ++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/sound/soc/atmel/mchp-spdiftx.c b/sound/soc/atmel/mchp-spdiftx.c
index 6ab32f0b8b8e..b034bd46cd5a 100644
--- a/sound/soc/atmel/mchp-spdiftx.c
+++ b/sound/soc/atmel/mchp-spdiftx.c
@@ -778,6 +778,15 @@ static const struct dev_pm_ops mchp_spdiftx_pm_ops = {
 		       NULL)
 };
 
+/* Runtime suspend the device on cleanup if necessary */
+static void mchp_spdiftx_runtime_suspend_action(void *data)
+{
+	struct device *dev = data;
+
+	if (!pm_runtime_status_suspended(dev))
+		mchp_spdiftx_runtime_suspend(dev);
+}
+
 static int mchp_spdiftx_probe(struct platform_device *pdev)
 {
 	struct mchp_spdiftx_dev *dev;
@@ -836,11 +845,22 @@ static int mchp_spdiftx_probe(struct platform_device *pdev)
 	dev->regmap = regmap;
 	platform_set_drvdata(pdev, dev);
 
-	pm_runtime_enable(dev->dev);
+	err = devm_add_action(dev->dev, mchp_spdiftx_runtime_suspend_action,
+			      dev->dev);
+	if (err)
+		return err;
+
+	err = devm_pm_runtime_enable(dev->dev);
+	if (err)
+		return err;
 	if (!pm_runtime_enabled(dev->dev)) {
 		err = mchp_spdiftx_runtime_resume(dev->dev);
-		if (err)
+		if (err) {
+			devm_remove_action(dev->dev,
+					   mchp_spdiftx_runtime_suspend_action,
+					   dev->dev);
 			return err;
+		}
 	}
 
 	dev->playback.addr = (dma_addr_t)mem->start + SPDIFTX_CDR;
@@ -849,7 +869,7 @@ static int mchp_spdiftx_probe(struct platform_device *pdev)
 	err = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
 	if (err) {
 		dev_err(&pdev->dev, "failed to register PMC: %d\n", err);
-		goto pm_runtime_suspend;
+		return err;
 	}
 
 	err = devm_snd_soc_register_component(&pdev->dev,
@@ -857,32 +877,14 @@ static int mchp_spdiftx_probe(struct platform_device *pdev)
 					      &mchp_spdiftx_dai, 1);
 	if (err) {
 		dev_err(&pdev->dev, "failed to register component: %d\n", err);
-		goto pm_runtime_suspend;
+		return err;
 	}
 
 	return 0;
-
-pm_runtime_suspend:
-	if (!pm_runtime_status_suspended(dev->dev))
-		mchp_spdiftx_runtime_suspend(dev->dev);
-	pm_runtime_disable(dev->dev);
-
-	return err;
-}
-
-static void mchp_spdiftx_remove(struct platform_device *pdev)
-{
-	struct mchp_spdiftx_dev *dev = platform_get_drvdata(pdev);
-
-	if (!pm_runtime_status_suspended(dev->dev))
-		mchp_spdiftx_runtime_suspend(dev->dev);
-
-	pm_runtime_disable(dev->dev);
 }
 
 static struct platform_driver mchp_spdiftx_driver = {
 	.probe	= mchp_spdiftx_probe,
-	.remove = mchp_spdiftx_remove,
 	.driver	= {
 		.name	= "mchp_spdiftx",
 		.of_match_table = mchp_spdiftx_dt_ids,
-- 
2.43.0




More information about the linux-arm-kernel mailing list