pmdomain: arm: scmi: Check pm_genpd_init() in probe
Subsystems (2)
PATCH 1/1 pmdomain: arm: scmi: Check pm_genpd_init() in probe
scmi_pm_domain_probe() stores each domain in the onecell domains array after calling pm_genpd_init(), but it ignores the return value from pm_genpd_init().
If pm_genpd_init() fails, the genpd has not been added to the global genpd list. The probe code nevertheless stores the genpd pointer in the domains array. A later provider registration failure then unwinds the array with pm_genpd_remove(), which can try to remove a genpd that was never registered.
Check the return value from pm_genpd_init() and only store successfully initialized domains in the onecell array. On failure, unwind the domains that were already initialized.
--- drivers/pmdomain/arm/scmi_pm_domain.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/pmdomain/arm/scmi_pm_domain.c +6 -2
@@ -99,8 +99,12 @@ static int scmi_pm_domain_probe(struct scmi_device *sdev) scmi_pd->genpd.power_on = scmi_pd_power_on; scmi_pd->genpd.flags =GENPD_FLAG_ACTIVE_WAKEUP ; -pm_genpd_init (&scmi_pd->genpd,NULL , - state ==SCMI_POWER_STATE_GENERIC_OFF ); + ret =pm_genpd_init (&scmi_pd->genpd,NULL , + state ==SCMI_POWER_STATE_GENERIC_OFF ); +if (ret) { +dev_err_probe (dev, ret,"failed to init domain %d\n" , i); + goto err_rm_genpds; + } domains[i] = &scmi_pd->genpd; }
Signature · 1 line
2.43.0
Sudeep Holla
maintainerQuoted 10 lines · Guangshuo Li
scmi_pm_domain_probe()stores each domain in the onecell domains array after callingpm_genpd_init(), but it ignores the return value frompm_genpd_init().If
pm_genpd_init()fails, the genpd has not been added to the global genpd list. The probe code nevertheless stores the genpd pointer in the domains array. A later provider registration failure then unwinds the array withpm_genpd_remove(), which can try to remove a genpd that was never registered.
Quoted 4 lines
Check the return value from
pm_genpd_init()and only store successfully initialized domains in the onecell array. On failure, unwind the domains that were already initialized.
It was done that way intentionally IIRC. We don't want to remove all the power domains if some not so important power domains fail to initialise. You can log the error if that helps but removing all the domains that have initialised seems bit of extreme.
Are you facing any issues on a real platform or is this just by code inspection.
Signature · 2 lines
Regards, Sudeep
Hi Sudeep,
Thanks for the explanation.
Quoted 22 lines · Sudeep Holla
Quoted 10 lines · Guangshuo Li
scmi_pm_domain_probe()stores each domain in the onecell domains array after callingpm_genpd_init(), but it ignores the return value frompm_genpd_init().If
pm_genpd_init()fails, the genpd has not been added to the global genpd list. The probe code nevertheless stores the genpd pointer in the domains array. A later provider registration failure then unwinds the array withpm_genpd_remove(), which can try to remove a genpd that was never registered.Quoted 4 lines
Check the return value from
pm_genpd_init()and only store successfully initialized domains in the onecell array. On failure, unwind the domains that were already initialized.It was done that way intentionally IIRC. We don't want to remove all the power domains if some not so important power domains fail to initialise. You can log the error if that helps but removing all the domains that have initialised seems bit of extreme.
Quoted 6 lines
Are you facing any issues on a real platform or is this just by code inspection.
--
Regards,
Sudeep
This was found through manual code inspection and has not been reproduced on real hardware. My concern is that a domain for which pm_genpd_init() fails is still stored in the domains array and may later be passed to pm_genpd_remove().
I agree that unwinding all initialized domains may be too aggressive.
Thanks,
Guangshuo