提交 4f4c9120 编写于 作者: C Chen-Yu Tsai 提交者: Yang Yingliang

clocksource/drivers/sun5i: Fail gracefully when clock rate is unavailable

[ Upstream commit e7e7e0d7beafebd11b0c065cd5fbc1e5759c5aab ]

If the clock tree is not fully populated when the timer-sun5i init code
is called, attempts to get the clock rate for the timer would fail and
return 0.

Make the init code for both clock events and clocksource check the
returned clock rate and fail gracefully if the result is 0, instead of
causing a divide by 0 exception later on.

Fixes: 4a59058f ("clocksource/drivers/sun5i: Refactor the current code")
Signed-off-by: NChen-Yu Tsai <wens@csie.org>
Acked-by: NMaxime Ripard <maxime.ripard@bootlin.com>
Signed-off-by: NDaniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 ffee33e2
...@@ -202,6 +202,11 @@ static int __init sun5i_setup_clocksource(struct device_node *node, ...@@ -202,6 +202,11 @@ static int __init sun5i_setup_clocksource(struct device_node *node,
} }
rate = clk_get_rate(clk); rate = clk_get_rate(clk);
if (!rate) {
pr_err("Couldn't get parent clock rate\n");
ret = -EINVAL;
goto err_disable_clk;
}
cs->timer.base = base; cs->timer.base = base;
cs->timer.clk = clk; cs->timer.clk = clk;
...@@ -275,6 +280,11 @@ static int __init sun5i_setup_clockevent(struct device_node *node, void __iomem ...@@ -275,6 +280,11 @@ static int __init sun5i_setup_clockevent(struct device_node *node, void __iomem
} }
rate = clk_get_rate(clk); rate = clk_get_rate(clk);
if (!rate) {
pr_err("Couldn't get parent clock rate\n");
ret = -EINVAL;
goto err_disable_clk;
}
ce->timer.base = base; ce->timer.base = base;
ce->timer.ticks_per_jiffy = DIV_ROUND_UP(rate, HZ); ce->timer.ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册