diff options
author | Jeffy Chen <jeffy.chen@rock-chips.com> | 2018-03-05 04:17:22 -0500 |
---|---|---|
committer | Heiko Stuebner <heiko@sntech.de> | 2018-03-05 13:42:29 -0500 |
commit | b1271993aa3855bda5073c6061a095fd6e6febc6 (patch) | |
tree | 2c670ccc6ab21acb8f35c92d2bf0abc19e979a56 | |
parent | d909072d0521a84e67fbe5cce602d7befffabf7e (diff) |
soc: rockchip: power-domain: Add a sanity check on pd->num_clks
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>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
-rw-r--r-- | drivers/soc/rockchip/pm_domains.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/drivers/soc/rockchip/pm_domains.c b/drivers/soc/rockchip/pm_domains.c index ad96ddeaeb78..53efc386b1ad 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, | |||
402 | 402 | ||
403 | pd->num_clks = of_count_phandle_with_args(node, "clocks", | 403 | pd->num_clks = of_count_phandle_with_args(node, "clocks", |
404 | "#clock-cells"); | 404 | "#clock-cells"); |
405 | 405 | if (pd->num_clks > 0) { | |
406 | pd->clks = devm_kcalloc(pmu->dev, pd->num_clks, sizeof(*pd->clks), | 406 | pd->clks = devm_kcalloc(pmu->dev, pd->num_clks, |
407 | GFP_KERNEL); | 407 | sizeof(*pd->clks), GFP_KERNEL); |
408 | if (!pd->clks) | 408 | if (!pd->clks) |
409 | return -ENOMEM; | 409 | return -ENOMEM; |
410 | } else { | ||
411 | dev_dbg(pmu->dev, "%s: doesn't have clocks: %d\n", | ||
412 | node->name, pd->num_clks); | ||
413 | pd->num_clks = 0; | ||
414 | } | ||
410 | 415 | ||
411 | for (i = 0; i < pd->num_clks; i++) { | 416 | for (i = 0; i < pd->num_clks; i++) { |
412 | pd->clks[i].clk = of_clk_get(node, i); | 417 | pd->clks[i].clk = of_clk_get(node, i); |