Small fixes and improvement for Rockchip pm-domains driver
Subsystems (2)
v2 cover Small fixes and improvement for Rockchip pm-domains driver
The first 3 patches are for fixing. And the last one is for improvement.
Changes in v2:
- switch to use devm_kzalloc()
- add Sebastian's tag
Shawn Lin (4):
pmdomain: rockchip: propagate subdomain add errors
pmdomain: rockchip: fix clock leak on domain probe failure
pmdomain: rockchip: don't ignore clock lookup errors on attach
pmdomain: rockchip: drop duplicated errno from supply failure message
drivers/pmdomain/rockchip/pm-domains.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
Signature · 7 lines
2.7.4 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
PATCH v2 1/4 pmdomain: rockchip: propagate subdomain add errors
rockchip_pm_add_subdomain() ignored the return value of its recursive call, so a failure deeper in the hierarchy was silently dropped and probe still succeeded with an incomplete domain tree.
---
Changes in v2: None
drivers/pmdomain/rockchip/pm-domains.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pmdomain/rockchip/pm-domains.c +3 -1
@@ -1018,7 +1018,9 @@ static int rockchip_pm_add_subdomain(struct rockchip_pmu *pmu, parent_domain->name, child_domain->name); } -rockchip_pm_add_subdomain (pmu, np); + error =rockchip_pm_add_subdomain (pmu, np); +if (error) +return error; }return 0 ;
Signature · 7 lines
2.7.4 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
PATCH v2 2/4 pmdomain: rockchip: fix clock leak on domain probe failure
In reply to Shawn LinWhen of_clk_get() failed in the middle of the loop, the references of the clocks acquired so far were leaked instead of being released by the error path.
Also switch the clks array allocation from devm_kcalloc() to devm_kzalloc() so that clk_bulk_put() cannot run over uninitialized entries.
---
Changes in v2:
- switch to use devm_kzalloc()
- add Sebastian's tag
drivers/pmdomain/rockchip/pm-domains.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pmdomain/rockchip/pm-domains.c +2 -2
@@ -825,7 +825,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, pd->num_clks =of_clk_get_parent_count (node);if (pd->num_clks >0 ) { - pd->clks =devm_kcalloc (pmu->dev, pd->num_clks, + pd->clks =devm_kzalloc (pmu->dev, pd->num_clks,sizeof (*pd->clks),GFP_KERNEL );if (!pd->clks)return -ENOMEM ;
@@ -842,7 +842,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu,dev_err (pmu->dev,"%pOFn: failed to get clk at index %d: %d\n" , node, i, error); -return error; + goto err_put_clocks; } }
Signature · 7 lines
2.7.4 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
Re: [PATCH v2 2/4] pmdomain: rockchip: fix clock leak on domain probe failure
Quoted 25 lines · Shawn Lin
When
of_clk_get()failed in the middle of the loop, the references of the clocks acquired so far were leaked instead of being released by the error path.Also switch the clks array allocation from
devm_kcalloc()todevm_kzalloc()so thatclk_bulk_put()cannot run over uninitialized entries.Fixes d909072d0521 ("soc: rockchip: power-domain: use clk_bulk APIs")Signed-off-by Shawn Lin <[email protected]>Reviewed-by Sebastian Reichel <[email protected]>---
Changes in v2:
- switch to usedevm_kzalloc()
- add Sebastian's tagdrivers/pmdomain/rockchip/pm-domains.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pmdomain/rockchip/pm-domains.c +0
-0
drivers/pmdomain/rockchip/pm-domains.c static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, · line 829
Quoted 6 lines
drivers/pmdomain/rockchip/pm-domains.c +1
-1@@ -825,7 +825,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu, pd->num_clks =of_clk_get_parent_count (node);if (pd->num_clks >0 ) { - pd->clks =devm_kcalloc (pmu->dev, pd->num_clks, + pd->clks =devm_kzalloc (pmu->dev, pd->num_clks,sizeof (*pd->clks),GFP_KERNEL );
/media/nvme/dev/debian/salsa/kernel-team/linux/drivers/pmdomain/rockchip/pm-domains.c: In function ‘rockchip_pm_add_one_domain’:
/media/nvme/dev/debian/salsa/kernel-team/linux/drivers/pmdomain/rockchip/pm-domains.c:840:28: error: too many arguments to function ‘devm_kzalloc’; expected 3, have 4
840 | pd->clks = devm_kzalloc(pmu->dev, pd->num_clks,
| ^~~~~~~~~~~~
In file included from /media/nvme/dev/debian/salsa/kernel-team/linux/include/linux/device.h:31,
from /media/nvme/dev/debian/salsa/kernel-team/linux/include/linux/platform_device.h:13, from /media/nvme/dev/debian/salsa/kernel-team/linux/drivers/pmdomain/rockchip/pm-domains.c:13:
/media/nvme/dev/debian/salsa/kernel-team/linux/include/linux/device/devres.h:48:21: note: declared here
48 | static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp)
| ^~~~~~~~~~~~
Seems legit:
https://elixir.bootlin.com/linux/v7.3-rc3/source/include/linux/device/devres.h#L48
Cheers,
Diederik
Quoted 11 lines
drivers/pmdomain/rockchip/pm-domains.c +1
-1if (!pd->clks)return -ENOMEM ;@@ -842,7 +842,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu,dev_err (pmu->dev,"%pOFn: failed to get clk at index %d: %d\n" , node, i, error); -return error; + goto err_put_clocks; } }
PATCH v2 3/4 pmdomain: rockchip: don't ignore clock lookup errors on attach
In reply to Shawn Linrockchip_pd_attach_dev() treated every of_clk_get() error as the end of the clock list, so a clock that exists but is not available yet (e.g. -EPROBE_DEFER) was silently skipped and the device ended up without pm_clk management. Only -ENOENT means there are no more clocks.
---
Changes in v2: None
drivers/pmdomain/rockchip/pm-domains.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/pmdomain/rockchip/pm-domains.c +13 -1
@@ -759,7 +759,19 @@ static int rockchip_pd_attach_dev(struct generic_pm_domain *genpd, } i =0 ; -while ((clk =of_clk_get (dev->of_node, i++)) && !IS_ERR (clk)) { +while (1 ) { + clk =of_clk_get (dev->of_node, i++); +if (IS_ERR (clk)) { + error =PTR_ERR (clk); +if (error == -ENOENT ) +break ; + +dev_err (dev,"failed to get clock %d: %d\n" , i -1 , + error); +pm_clk_destroy (dev); +return error; + } +dev_dbg (dev,"adding clock '%pC' to list of PM clocks\n" , clk); error =pm_clk_add_clk (dev, clk);if (error) {
Signature · 7 lines
2.7.4 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip
PATCH v2 4/4 pmdomain: rockchip: drop duplicated errno from supply failure message
In reply to Shawn Lindev_err_probe() already appends the error code.
---
Changes in v2: None
drivers/pmdomain/rockchip/pm-domains.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pmdomain/rockchip/pm-domains.c +1 -1
@@ -721,7 +721,7 @@ static int rockchip_pd_power_on(struct generic_pm_domain *domain) ret =rockchip_pd_regulator_enable (pd);if (ret)return dev_err_probe (pd->pmu->dev, ret, -"Failed to enable supply: %d\n" , ret); +"Failed to enable supply\n" ); ret =rockchip_pd_power (pd, true);if (ret)
Signature · 7 lines
2.7.4 _______________________________________________ Linux-rockchip mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-rockchip