soc: rockchip: fix probe error path in power-domain driver
Heiko Stuebner
maintainercover soc: rockchip: fix probe error path in power-domain driver
A recent change to generic power-domains revealed that the rockchip driver cannot safely fail it's probe. Also pm_genpd_init creates a situation where a probe error leads to the generic power-domains accessing already freed data.
The reason for us finding this issue (holes in power-domain lists), will get fixed in the generic power-domains, but the fixes below will only work after the newly added genpd-removal code got merged.
Therefore I hope to remember to send the two patches below as fix after 4.9-rc1.
Alternatively Rafael could include them into his branch directly.
Heiko Stuebner (1):
soc: rockchip: power-domain: use pm_genpd_remove in error cleanup
Tomeu Vizoso (1):
soc: rockchip: power-domain: Handle errors from
of_genpd_add_provider_onecell
drivers/soc/rockchip/pm_domains.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
Signature · 1 line
2.8.1
Heiko Stuebner
maintainerPATCH 1/2 soc: rockchip: power-domain: use pm_genpd_remove in error cleanup
The newly introduced pm_genpd_remove reverts the initialization done by pm_genpd_init and is necessary in the error path of the rockchip power-domain driver.
Without it the driver will in the error case cleanup the devm-allocated structures including the elements referenced in the gpd_list thus making deactivation of unused domains (and probably later genpd accesses as well) fail by accessing invalid pointers.
--- drivers/soc/rockchip/pm_domains.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/soc/rockchip/pm_domains.c +10 -1
@@ -445,7 +445,16 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu,static void rockchip_pm_remove_one_domain (struct rockchip_pm_domain *pd) { -int i; +int i, ret; + +/* +* We're in the error cleanup already, so we only complain, +* but won't emit another error on top of the original one. +*/ + ret =pm_genpd_remove (&pd->genpd); +if (ret <0 ) +dev_err (pd->pmu->dev,"failed to remove domain '%s' : %d - state may be inconsistent\n" , + pd->genpd.name, ret);for (i =0 ; i < pd->num_clks; i++) {clk_unprepare (pd->clks[i]);
Signature · 1 line
2.8.1
Heiko Stuebner
maintainerPATCH 2/2 soc: rockchip: power-domain: Handle errors from of_genpd_add_provider_onecell
In reply to Heiko StuebnerFrom: Tomeu Vizoso <[email protected]>
It was a bit surprising that the device was reported to have probed just fine, but the provider hadn't been registered.
So handle any errors when registering the provider and fail the probe accordingly.
---
unchanged from Tomeu's single-patch
drivers/soc/rockchip/pm_domains.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/soc/rockchip/pm_domains.c +5 -1
@@ -636,7 +636,11 @@ static int rockchip_pm_domain_probe(struct platform_device *pdev) goto err_out; } -of_genpd_add_provider_onecell (np, &pmu->genpd_data); + error =of_genpd_add_provider_onecell (np, &pmu->genpd_data); +if (error) { +dev_err (dev,"failed to add provider: %d\n" , error); + goto err_out; + }return 0 ;
Signature · 1 line
2.8.1
Heiko Stuebner
maintainerAm Freitag, 16. September 2016, 00:14:37 CET schrieb Heiko Stuebner:
Quoted 10 lines
A recent change to generic power-domains revealed that the rockchip driver cannot safely fail it's probe. Also
pm_genpd_initcreates a situation where a probe error leads to the generic power-domains accessing already freed data.The reason for us finding this issue (holes in power-domain lists), will get fixed in the generic power-domains, but the fixes below will only work after the newly added genpd-removal code got merged.
Quoted 4 lines
Therefore I hope to remember to send the two patches below as fix after 4.9-rc1.
Alternatively Rafael could include them into his branch directly.
I've applied now both in a fixes branch for 4.9 and plan on sending it through arm-soc later this week.