]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: rockchip: spdif: Fully convert to device managed resources
authorSebastian Reichel <sebastian.reichel@collabora.com>
Tue, 3 Feb 2026 16:46:25 +0000 (17:46 +0100)
committerMark Brown <broonie@kernel.org>
Thu, 5 Feb 2026 18:46:42 +0000 (18:46 +0000)
This driver mixes device managed resources with unmanaged ones
and (as a lot of them do) gets the order wrong resulting in
potential race condition problems at module removal time. Let's
go to full device managed resources to cleanup the code and get
rid of the potential race condition.

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Link: https://patch.msgid.link/20260203-rockchip-spdif-cleanup-and-bsp-sync-v2-3-4412016cf577@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/rockchip/rockchip_spdif.c

index 331a23d5173f2b286a76201a6fae8869122906a7..841ef499ed7fcffd0c367ce1452feec90b19a067 100644 (file)
@@ -257,6 +257,14 @@ static const struct regmap_config rk_spdif_regmap_config = {
        .cache_type = REGCACHE_FLAT,
 };
 
+static void rk_spdif_suspend(void *data)
+{
+       struct device *dev = data;
+
+       if (!pm_runtime_status_suspended(dev))
+               rk_spdif_runtime_suspend(dev);
+}
+
 static int rk_spdif_probe(struct platform_device *pdev)
 {
        struct device_node *np = pdev->dev.of_node;
@@ -311,11 +319,16 @@ static int rk_spdif_probe(struct platform_device *pdev)
        spdif->dev = &pdev->dev;
        dev_set_drvdata(&pdev->dev, spdif);
 
-       pm_runtime_enable(&pdev->dev);
+       ret = devm_add_action_or_reset(&pdev->dev, rk_spdif_suspend, &pdev->dev);
+       if (ret)
+               return ret;
+
+       devm_pm_runtime_enable(&pdev->dev);
+
        if (!pm_runtime_enabled(&pdev->dev)) {
                ret = rk_spdif_runtime_resume(&pdev->dev);
                if (ret)
-                       goto err_pm_runtime;
+                       return ret;
        }
 
        ret = devm_snd_soc_register_component(&pdev->dev,
@@ -323,31 +336,16 @@ static int rk_spdif_probe(struct platform_device *pdev)
                                              &rk_spdif_dai, 1);
        if (ret) {
                dev_err(&pdev->dev, "Could not register DAI\n");
-               goto err_pm_suspend;
+               return ret;
        }
 
        ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
        if (ret) {
                dev_err(&pdev->dev, "Could not register PCM\n");
-               goto err_pm_suspend;
+               return ret;
        }
 
        return 0;
-
-err_pm_suspend:
-       if (!pm_runtime_status_suspended(&pdev->dev))
-               rk_spdif_runtime_suspend(&pdev->dev);
-err_pm_runtime:
-       pm_runtime_disable(&pdev->dev);
-
-       return ret;
-}
-
-static void rk_spdif_remove(struct platform_device *pdev)
-{
-       pm_runtime_disable(&pdev->dev);
-       if (!pm_runtime_status_suspended(&pdev->dev))
-               rk_spdif_runtime_suspend(&pdev->dev);
 }
 
 static const struct dev_pm_ops rk_spdif_pm_ops = {
@@ -379,7 +377,6 @@ MODULE_DEVICE_TABLE(of, rk_spdif_match);
 
 static struct platform_driver rk_spdif_driver = {
        .probe = rk_spdif_probe,
-       .remove = rk_spdif_remove,
        .driver = {
                .name = "rockchip-spdif",
                .of_match_table = rk_spdif_match,