From: Jeffy Chen <jeffy.chen@rock-chips.com>
To: linux-kernel@vger.kernel.org
Cc: Jeffy Chen <jeffy.chen@rock-chips.com>,
Heiko Stuebner <heiko@sntech.de>,
Geert Uytterhoeven <geert+renesas@glider.be>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
linux-rockchip@lists.infradead.org,
Elaine Zhang <zhangqing@rock-chips.com>,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH] soc: rockchip: power-domain: Add a sanity check on pd->num_clks
Date: Mon, 5 Mar 2018 17:17:22 +0800 [thread overview]
Message-ID: <20180305091722.22246-1-jeffy.chen@rock-chips.com> (raw)
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
next reply other threads:[~2018-03-05 9:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-05 9:17 Jeffy Chen [this message]
2018-03-05 9:33 ` [PATCH] soc: rockchip: power-domain: Add a sanity check on pd->num_clks Shawn Lin
2018-03-05 20:26 ` Heiko Stübner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180305091722.22246-1-jeffy.chen@rock-chips.com \
--to=jeffy.chen@rock-chips.com \
--cc=geert+renesas@glider.be \
--cc=heiko@sntech.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=rafael.j.wysocki@intel.com \
--cc=zhangqing@rock-chips.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox