[PATCH 2/3] pmdomain: bcm: Unregister BCM63xx power domains on unbind
Tian Xuechen
202300460064 at mail.sdu.edu.cn
Thu Nov 26 05:27:54 PST 2026
From: Tian Xuechen <202300460064 at mail.sdu.edu.cn>
The BCM63xx provider and its domains remain registered after their
managed storage is freed. Delete the provider and remove initialized
domains on unbind, and unwind initialization when probe fails.
This issue was found by our static analysis tool under development.
Fixes: 6c41106f177e ("soc: bcm: add BCM63xx power domain driver")
Signed-off-by: Tian Xuechen <202300460064 at mail.sdu.edu.cn>
---
drivers/pmdomain/bcm/bcm63xx-power.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/drivers/pmdomain/bcm/bcm63xx-power.c b/drivers/pmdomain/bcm/bcm63xx-power.c
index 9454f9066709..51ab8c5abca1 100644
--- a/drivers/pmdomain/bcm/bcm63xx-power.c
+++ b/drivers/pmdomain/bcm/bcm63xx-power.c
@@ -86,6 +86,21 @@ static int bcm63xx_power_off(struct generic_pm_domain *genpd)
return bcm63xx_power_set_state(pmd, false);
}
+static void bcm63xx_power_remove_domains(struct bcm63xx_power *power)
+{
+ int i;
+
+ for (i = power->genpd_data.num_domains - 1; i >= 0; i--)
+ if (power->genpd[i])
+ pm_genpd_remove(power->genpd[i]);
+}
+
+static void bcm63xx_power_remove(struct platform_device *pdev)
+{
+ of_genpd_del_provider(pdev->dev.of_node);
+ bcm63xx_power_remove_domains(platform_get_drvdata(pdev));
+}
+
static int bcm63xx_power_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -150,7 +165,9 @@ static int bcm63xx_power_probe(struct platform_device *pdev)
pmd->genpd.power_on = bcm63xx_power_on;
pmd->genpd.power_off = bcm63xx_power_off;
- pm_genpd_init(&pmd->genpd, NULL, !is_on);
+ ret = pm_genpd_init(&pmd->genpd, NULL, !is_on);
+ if (ret)
+ goto err_remove_domains;
power->genpd[entry->bit] = &pmd->genpd;
ndom++;
@@ -161,12 +178,17 @@ static int bcm63xx_power_probe(struct platform_device *pdev)
ret = of_genpd_add_provider_onecell(np, &power->genpd_data);
if (ret) {
dev_err(dev, "failed to register genpd driver: %d\n", ret);
- return ret;
+ goto err_remove_domains;
}
+ platform_set_drvdata(pdev, power);
dev_info(dev, "registered %u power domains\n", ndom);
return 0;
+
+err_remove_domains:
+ bcm63xx_power_remove_domains(power);
+ return ret;
}
static const struct bcm63xx_power_data bcm6318_power_domains[] = {
@@ -369,5 +391,6 @@ static struct platform_driver bcm63xx_power_driver = {
.of_match_table = bcm63xx_power_of_match,
},
.probe = bcm63xx_power_probe,
+ .remove = bcm63xx_power_remove,
};
builtin_platform_driver(bcm63xx_power_driver);
--
2.43.0
More information about the linux-arm-kernel
mailing list