[PATCH 3/3] pmdomain: bcm: Unregister Raspberry Pi power domains on unbind
Tian Xuechen
202300460064 at mail.sdu.edu.cn
Thu Nov 26 05:27:55 PST 2026
From: Tian Xuechen <202300460064 at mail.sdu.edu.cn>
The Raspberry Pi firmware power driver leaves registered domains and an
OF provider referring to freed storage on unbind. Initialize the
available domains together so probe can unwind partial initialization.
Remove the provider before its domains on unbind.
This issue was found by our static analysis tool under development.
The unbind cleanup overlaps an earlier proposal to add a remove
callback. This patch also handles partial initialization on probe
failure.
Link: https://lore.kernel.org/r/20260715-rpi-pm-remove-v1-1-e4eed226e08a@linutronix.de
Fixes: a09cd356586d ("ARM: bcm2835: add rpi power domain driver")
Signed-off-by: Tian Xuechen <202300460064 at mail.sdu.edu.cn>
---
drivers/pmdomain/bcm/raspberrypi-power.c | 59 +++++++++++++++++++-----
1 file changed, 47 insertions(+), 12 deletions(-)
diff --git a/drivers/pmdomain/bcm/raspberrypi-power.c b/drivers/pmdomain/bcm/raspberrypi-power.c
index 1304c5545f36..816458637663 100644
--- a/drivers/pmdomain/bcm/raspberrypi-power.c
+++ b/drivers/pmdomain/bcm/raspberrypi-power.c
@@ -95,16 +95,6 @@ static void rpi_common_init_power_domain(struct rpi_power_domains *rpi_domains,
dom->base.power_on = rpi_domain_on;
dom->base.power_off = rpi_domain_off;
- /*
- * Treat all power domains as off at boot.
- *
- * The firmware itself may be keeping some domains on, but
- * from Linux's perspective all we control is the refcounts
- * that we give to the firmware, and we can't ask the firmware
- * to turn off something that we haven't ourselves turned on.
- */
- pm_genpd_init(&dom->base, NULL, true);
-
rpi_domains->xlate.domains[xlate_index] = &dom->base;
}
@@ -158,11 +148,32 @@ rpi_has_new_domain_support(struct rpi_power_domains *rpi_domains)
return ret == 0 && packet.state != ~0;
}
+static void rpi_power_remove_domains(struct rpi_power_domains *rpi_domains,
+ unsigned int count)
+{
+ while (count--) {
+ struct generic_pm_domain *pd = rpi_domains->xlate.domains[count];
+
+ if (pd)
+ pm_genpd_remove(pd);
+ }
+}
+
+static void rpi_power_remove(struct platform_device *pdev)
+{
+ struct rpi_power_domains *rpi_domains = platform_get_drvdata(pdev);
+
+ of_genpd_del_provider(pdev->dev.of_node);
+ rpi_power_remove_domains(rpi_domains, rpi_domains->xlate.num_domains);
+}
+
static int rpi_power_probe(struct platform_device *pdev)
{
struct device_node *fw_np;
struct device *dev = &pdev->dev;
struct rpi_power_domains *rpi_domains;
+ unsigned int i;
+ int ret;
rpi_domains = devm_kzalloc_obj(dev, *rpi_domains);
if (!rpi_domains)
@@ -223,11 +234,34 @@ static int rpi_power_probe(struct platform_device *pdev)
rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_CDP, "CDP");
rpi_init_power_domain(rpi_domains, RPI_POWER_DOMAIN_ARM, "ARM");
- of_genpd_add_provider_onecell(dev->of_node, &rpi_domains->xlate);
+ /*
+ * Treat all power domains as off at boot.
+ *
+ * The firmware itself may be keeping some domains on, but
+ * from Linux's perspective all we control is the refcounts
+ * that we give to the firmware, and we can't ask the firmware
+ * to turn off something that we haven't ourselves turned on.
+ */
+ for (i = 0; i < rpi_domains->xlate.num_domains; i++) {
+ struct generic_pm_domain *pd = rpi_domains->xlate.domains[i];
+
+ if (!pd)
+ continue;
+ ret = pm_genpd_init(pd, NULL, true);
+ if (ret)
+ goto err_remove_domains;
+ }
+
+ ret = of_genpd_add_provider_onecell(dev->of_node, &rpi_domains->xlate);
+ if (ret)
+ goto err_remove_domains;
platform_set_drvdata(pdev, rpi_domains);
-
return 0;
+
+err_remove_domains:
+ rpi_power_remove_domains(rpi_domains, i);
+ return ret;
}
static const struct of_device_id rpi_power_of_match[] = {
@@ -242,6 +276,7 @@ static struct platform_driver rpi_power_driver = {
.of_match_table = rpi_power_of_match,
},
.probe = rpi_power_probe,
+ .remove = rpi_power_remove,
};
builtin_platform_driver(rpi_power_driver);
--
2.43.0
More information about the linux-arm-kernel
mailing list