[PATCH] pmdomain: arm: Unregister SCPI domains on removal
Tian Xuechen
202300460064 at mail.sdu.edu.cn
Sat Nov 28 03:02:20 PST 2026
From: Tian Xuechen <202300460064 at mail.sdu.edu.cn>
The SCPI driver releases its domain storage on removal without
unregistering the provider or domains. Remove the provider before
freeing its domains and unwind previously initialized domains if probe
fails.
This issue was found by our static analysis tool under development.
Fixes: 8bec4337ad40 ("firmware: scpi: add device power domain support using genpd")
Signed-off-by: Tian Xuechen <202300460064 at mail.sdu.edu.cn>
---
drivers/pmdomain/arm/scpi_pm_domain.c | 41 +++++++++++++++++++++------
1 file changed, 33 insertions(+), 8 deletions(-)
diff --git a/drivers/pmdomain/arm/scpi_pm_domain.c b/drivers/pmdomain/arm/scpi_pm_domain.c
index 1d55a9e548e0..d9fa5ef7c1ec 100644
--- a/drivers/pmdomain/arm/scpi_pm_domain.c
+++ b/drivers/pmdomain/arm/scpi_pm_domain.c
@@ -62,6 +62,21 @@ static int scpi_pd_power_off(struct generic_pm_domain *domain)
return scpi_pd_power(pd, false);
}
+static void scpi_pm_remove_domains(struct genpd_onecell_data *data)
+{
+ int i;
+
+ for (i = data->num_domains - 1; i >= 0; i--)
+ if (data->domains[i])
+ pm_genpd_remove(data->domains[i]);
+}
+
+static void scpi_pm_domain_remove(struct platform_device *pdev)
+{
+ of_genpd_del_provider(pdev->dev.of_node);
+ scpi_pm_remove_domains(platform_get_drvdata(pdev));
+}
+
static int scpi_pm_domain_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -105,9 +120,10 @@ static int scpi_pm_domain_probe(struct platform_device *pdev)
if (!domains)
return -ENOMEM;
- for (i = 0; i < num_domains; i++, scpi_pd++) {
- domains[i] = &scpi_pd->genpd;
+ scpi_pd_data->domains = domains;
+ scpi_pd_data->num_domains = num_domains;
+ for (i = 0; i < num_domains; i++, scpi_pd++) {
scpi_pd->domain = i;
scpi_pd->ops = scpi_ops;
scpi_pd->genpd.name = devm_kasprintf(dev, GFP_KERNEL,
@@ -115,7 +131,8 @@ static int scpi_pm_domain_probe(struct platform_device *pdev)
if (!scpi_pd->genpd.name) {
dev_err(dev, "Failed to allocate genpd name:%pOFn.%d\n",
np, i);
- continue;
+ ret = -ENOMEM;
+ goto err_remove_domains;
}
scpi_pd->genpd.power_off = scpi_pd_power_off;
scpi_pd->genpd.power_on = scpi_pd_power_on;
@@ -126,15 +143,22 @@ static int scpi_pm_domain_probe(struct platform_device *pdev)
* The SCP firmware itself may have switched on some domains,
* but for reference counting purpose, keep it this way.
*/
- pm_genpd_init(&scpi_pd->genpd, NULL, true);
+ ret = pm_genpd_init(&scpi_pd->genpd, NULL, true);
+ if (ret)
+ goto err_remove_domains;
+ domains[i] = &scpi_pd->genpd;
}
- scpi_pd_data->domains = domains;
- scpi_pd_data->num_domains = num_domains;
-
- of_genpd_add_provider_onecell(np, scpi_pd_data);
+ ret = of_genpd_add_provider_onecell(np, scpi_pd_data);
+ if (ret)
+ goto err_remove_domains;
+ platform_set_drvdata(pdev, scpi_pd_data);
return 0;
+
+err_remove_domains:
+ scpi_pm_remove_domains(scpi_pd_data);
+ return ret;
}
static const struct of_device_id scpi_power_domain_ids[] = {
@@ -149,6 +173,7 @@ static struct platform_driver scpi_power_domain_driver = {
.of_match_table = scpi_power_domain_ids,
},
.probe = scpi_pm_domain_probe,
+ .remove = scpi_pm_domain_remove,
};
module_platform_driver(scpi_power_domain_driver);
base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
--
2.43.0
More information about the linux-arm-kernel
mailing list