pmdomain: imx-gpc: Convert to platform remove callback returning void
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Fri, 24 Nov 2023 08:06:26 +0000 (09:06 +0100)
committerUlf Hansson <ulf.hansson@linaro.org>
Thu, 30 Nov 2023 11:15:35 +0000 (12:15 +0100)
The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is ignored (apart
from emitting a warning) and this typically results in resource leaks.

To improve here there is a quest to make the remove callback return
void. In the first step of this quest all drivers are converted to
.remove_new(), which already returns void. Eventually after all drivers
are converted, .remove_new() will be renamed to .remove().

In the error path emit an error message replacing the (less useful)
message by the core. Apart from the improved error message there is no
change in behaviour.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20231124080623.564924-3-u.kleine-koenig@pengutronix.de
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/pmdomain/imx/gpc.c

index d6cf3759570bdba63684590b02100f6514bea2cd..9517cce93d8a3963ff4e5c0347473fdbd74d30a2 100644 (file)
@@ -509,7 +509,7 @@ static int imx_gpc_probe(struct platform_device *pdev)
        return 0;
 }
 
-static int imx_gpc_remove(struct platform_device *pdev)
+static void imx_gpc_remove(struct platform_device *pdev)
 {
        struct device_node *pgc_node;
        int ret;
@@ -519,7 +519,7 @@ static int imx_gpc_remove(struct platform_device *pdev)
        /* bail out if DT too old and doesn't provide the necessary info */
        if (!of_property_read_bool(pdev->dev.of_node, "#power-domain-cells") &&
            !pgc_node)
-               return 0;
+               return;
 
        /*
         * If the old DT binding is used the toplevel driver needs to
@@ -529,16 +529,20 @@ static int imx_gpc_remove(struct platform_device *pdev)
                of_genpd_del_provider(pdev->dev.of_node);
 
                ret = pm_genpd_remove(&imx_gpc_domains[GPC_PGC_DOMAIN_PU].base);
-               if (ret)
-                       return ret;
+               if (ret) {
+                       dev_err(&pdev->dev, "Failed to remove PU power domain (%pe)\n",
+                               ERR_PTR(ret));
+                       return;
+               }
                imx_pgc_put_clocks(&imx_gpc_domains[GPC_PGC_DOMAIN_PU]);
 
                ret = pm_genpd_remove(&imx_gpc_domains[GPC_PGC_DOMAIN_ARM].base);
-               if (ret)
-                       return ret;
+               if (ret) {
+                       dev_err(&pdev->dev, "Failed to remove ARM power domain (%pe)\n",
+                               ERR_PTR(ret));
+                       return;
+               }
        }
-
-       return 0;
 }
 
 static struct platform_driver imx_gpc_driver = {
@@ -547,6 +551,6 @@ static struct platform_driver imx_gpc_driver = {
                .of_match_table = imx_gpc_dt_ids,
        },
        .probe = imx_gpc_probe,
-       .remove = imx_gpc_remove,
+       .remove_new = imx_gpc_remove,
 };
 builtin_platform_driver(imx_gpc_driver)