[PATCH 2/2] pmdomain: amlogic: Tear down secure domains and their OF provider
Tian Xuechen
202300460064 at mail.sdu.edu.cn
Fri Nov 27 03:33:26 PST 2026
From: Tian Xuechen <202300460064 at mail.sdu.edu.cn>
The secure power driver leaves the OF provider and domain hierarchy
registered after its memory is released. Remove the provider on unbind
and unwind subdomain links before the domains they connect. Use the same
cleanup when probe fails midway.
This issue was found by our static analysis tool under development.
Fixes: b3dde5013e13 ("soc: amlogic: Add support for Secure power domains controller")
Signed-off-by: Tian Xuechen <202300460064 at mail.sdu.edu.cn>
---
drivers/pmdomain/amlogic/meson-secure-pwrc.c | 36 ++++++++++++++++++--
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/drivers/pmdomain/amlogic/meson-secure-pwrc.c b/drivers/pmdomain/amlogic/meson-secure-pwrc.c
index c424a1e76174..53e3fa10328e 100644
--- a/drivers/pmdomain/amlogic/meson-secure-pwrc.c
+++ b/drivers/pmdomain/amlogic/meson-secure-pwrc.c
@@ -392,9 +392,26 @@ static const struct meson_secure_pwrc_domain_desc t7_pwrc_domains[] = {
SEC_PD(T7_AUDIO, 0),
};
+static void meson_secure_pwrc_remove_domain(void *data)
+{
+ pm_genpd_remove(data);
+}
+
+static void meson_secure_pwrc_remove_subdomain(void *data)
+{
+ struct meson_secure_pwrc_domain *dom = data;
+
+ pm_genpd_remove_subdomain(&dom->pwrc->domains[dom->parent].base, &dom->base);
+}
+
+static void meson_secure_pwrc_remove(struct platform_device *pdev)
+{
+ of_genpd_del_provider(pdev->dev.of_node);
+}
+
static int meson_secure_pwrc_probe(struct platform_device *pdev)
{
- int i;
+ int i, ret;
struct device_node *sm_np;
struct meson_secure_pwrc *pwrc;
const struct meson_secure_pwrc_domain_data *match;
@@ -453,7 +470,13 @@ static int meson_secure_pwrc_probe(struct platform_device *pdev)
if (match->domains[i].is_off(dom) && (dom->base.flags & GENPD_FLAG_ALWAYS_ON))
meson_secure_pwrc_on(&dom->base);
- pm_genpd_init(&dom->base, NULL, match->domains[i].is_off(dom));
+ ret = pm_genpd_init(&dom->base, NULL, match->domains[i].is_off(dom));
+ if (ret)
+ return ret;
+ ret = devm_add_action_or_reset(&pdev->dev, meson_secure_pwrc_remove_domain,
+ &dom->base);
+ if (ret)
+ return ret;
pwrc->xlate.domains[i] = &dom->base;
}
@@ -464,7 +487,13 @@ static int meson_secure_pwrc_probe(struct platform_device *pdev)
if (!match->domains[i].name || match->domains[i].parent == PWRC_NO_PARENT)
continue;
- pm_genpd_add_subdomain(&dom[dom[i].parent].base, &dom[i].base);
+ ret = pm_genpd_add_subdomain(&dom[dom[i].parent].base, &dom[i].base);
+ if (ret)
+ return ret;
+ ret = devm_add_action_or_reset(&pdev->dev, meson_secure_pwrc_remove_subdomain,
+ &dom[i]);
+ if (ret)
+ return ret;
}
return of_genpd_add_provider_onecell(pdev->dev.of_node, &pwrc->xlate);
@@ -567,6 +596,7 @@ MODULE_DEVICE_TABLE(of, meson_secure_pwrc_match_table);
static struct platform_driver meson_secure_pwrc_driver = {
.probe = meson_secure_pwrc_probe,
+ .remove = meson_secure_pwrc_remove,
.driver = {
.name = "meson_secure_pwrc",
.of_match_table = meson_secure_pwrc_match_table,
--
2.43.0
More information about the linux-arm-kernel
mailing list