linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] soc: rockchip: power-domain: Add a sanity check on pd->num_clks
@ 2018-03-05  9:17 Jeffy Chen
  2018-03-05  9:33 ` Shawn Lin
  2018-03-05 20:26 ` Heiko Stübner
  0 siblings, 2 replies; 3+ messages in thread
From: Jeffy Chen @ 2018-03-05  9:17 UTC (permalink / raw)
  To: linux-arm-kernel

The of_count_phandle_with_args() can fail and return error(for example,
rk3399 pd_vio doesn't have clocks). That would break the pd probe.

Add a sanity check on pd->num_clks to avoid that.

Fixes: 65084121d59d ("soc: rockchip: power-domain: use clk_bulk APIs")
Reported-by: Shawn Lin <shawn.lin@rock-chips.com>
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---

 drivers/soc/rockchip/pm_domains.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/soc/rockchip/pm_domains.c b/drivers/soc/rockchip/pm_domains.c
index ad96ddeaeb78..fd58fd475950 100644
--- a/drivers/soc/rockchip/pm_domains.c
+++ b/drivers/soc/rockchip/pm_domains.c
@@ -402,11 +402,16 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu,
 
 	pd->num_clks = of_count_phandle_with_args(node, "clocks",
 						  "#clock-cells");
-
-	pd->clks = devm_kcalloc(pmu->dev, pd->num_clks, sizeof(*pd->clks),
-				GFP_KERNEL);
-	if (!pd->clks)
-		return -ENOMEM;
+	if (pd->num_clks > 0) {
+		pd->clks = devm_kcalloc(pmu->dev, pd->num_clks,
+					sizeof(*pd->clks), GFP_KERNEL);
+		if (!pd->clks)
+			return -ENOMEM;
+	} else {
+		dev_dbg(pmu->dev, "%s: don't have clocks: %d\n",
+			node->name, pd->num_clks);
+		pd->num_clks = 0;
+	}
 
 	for (i = 0; i < pd->num_clks; i++) {
 		pd->clks[i].clk = of_clk_get(node, i);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] soc: rockchip: power-domain: Add a sanity check on pd->num_clks
  2018-03-05  9:17 [PATCH] soc: rockchip: power-domain: Add a sanity check on pd->num_clks Jeffy Chen
@ 2018-03-05  9:33 ` Shawn Lin
  2018-03-05 20:26 ` Heiko Stübner
  1 sibling, 0 replies; 3+ messages in thread
From: Shawn Lin @ 2018-03-05  9:33 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Jeffy,

On 2018/3/5 17:17, Jeffy Chen wrote:
> The of_count_phandle_with_args() can fail and return error(for example,
> rk3399 pd_vio doesn't have clocks). That would break the pd probe.
> 
> Add a sanity check on pd->num_clks to avoid that.
> 
> Fixes: 65084121d59d ("soc: rockchip: power-domain: use clk_bulk APIs")
> Reported-by: Shawn Lin <shawn.lin@rock-chips.com>
> Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
Tested-by: Shawn Lin <shawn.lin@rock-chips.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] soc: rockchip: power-domain: Add a sanity check on pd->num_clks
  2018-03-05  9:17 [PATCH] soc: rockchip: power-domain: Add a sanity check on pd->num_clks Jeffy Chen
  2018-03-05  9:33 ` Shawn Lin
@ 2018-03-05 20:26 ` Heiko Stübner
  1 sibling, 0 replies; 3+ messages in thread
From: Heiko Stübner @ 2018-03-05 20:26 UTC (permalink / raw)
  To: linux-arm-kernel

Am Montag, 5. M?rz 2018, 10:17:22 CET schrieb Jeffy Chen:
> The of_count_phandle_with_args() can fail and return error(for example,
> rk3399 pd_vio doesn't have clocks). That would break the pd probe.
> 
> Add a sanity check on pd->num_clks to avoid that.
> 
> Fixes: 65084121d59d ("soc: rockchip: power-domain: use clk_bulk APIs")
> Reported-by: Shawn Lin <shawn.lin@rock-chips.com>
> Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>

applied for 4.17


Thanks
Heiko

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-05 20:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-05  9:17 [PATCH] soc: rockchip: power-domain: Add a sanity check on pd->num_clks Jeffy Chen
2018-03-05  9:33 ` Shawn Lin
2018-03-05 20:26 ` Heiko Stübner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).