clk: qcom: gdsc: unwind power domains when registration fails
Subsystems (3)
PATCH 1/1 clk: qcom: gdsc: unwind power domains when registration fails
gdsc_register() leaves the power domains it has already initialized registered with genpd when a later gdsc_init() or of_genpd_add_provider_onecell() call fails. Callers only install their gdsc_unregister() devm action after gdsc_register() returns success, so nothing removes those domains, and a later probe attempt initializes the same static struct generic_pm_domain objects again while they are still on the genpd list.
Commit 86b23609d5e1 ("clk: qcom: gdsc: tear down per-domain genpds in gdsc_unregister()") made the unregister path remove the domains, and commit 16ba98dace9e ("clk: qcom: gdsc: Fix error path on registration of multiple pm subdomains") fixed the subdomain part of the registration error path. Make the rest of that error path match gdsc_unregister(): when the provider cannot be added, remove all subdomains and domains, and when gdsc_init() fails, remove the domains initialized before it.
---
Tested in QEMU on a 7.3-rc5 tree, running the real gdsc.c and genpd with a synthetic DT and fake registers, with failures injected at the first, middle and last gdsc_init(), in subdomain registration and in provider registration, plus sparse arrays, explicit parents, a device parent and a pd_list (52 cases). 36 of the 52 cases failed the cleanup checks before this patch; all 52 pass with it.
Registering the same objects again after a failed attempt still reports an existing kobject (-EEXIST), with or without this patch; that looks like a separate genpd lifecycle issue.
drivers/clk/qcom/gdsc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/clk/qcom/gdsc.c +13 -2
@@ -647,7 +647,7 @@ int gdsc_register(struct gdsc_desc *desc, scs[i]->rcdev = rcdev; ret =gdsc_init (scs[i]);if (ret) -return ret; + goto err_pm_domain_remove; data->domains[i] = &scs[i]->pd; }
@@ -666,10 +666,21 @@ int gdsc_register(struct gdsc_desc *desc, goto err_pm_subdomain_remove; } -return of_genpd_add_provider_onecell (dev->of_node, data); + ret =of_genpd_add_provider_onecell (dev->of_node, data); +if (ret) + goto err_pm_subdomain_remove; + +return 0 ; err_pm_subdomain_remove:gdsc_pm_subdomain_remove (desc, i); + i = num; + +err_pm_domain_remove: +while (i--) { +if (scs[i]) +pm_genpd_remove (&scs[i]->pd); + }return ret; }
Signature · 1 line
2.56.0