Message ID | 20190110062207.18787-1-wens@csie.org (mailing list archive) |
---|---|
State | Mainlined, archived |
Commit | e7e7e0d7beafebd11b0c065cd5fbc1e5759c5aab |
Headers | show |
Series | clocksource: sun5i: fail gracefully when clock rate is unavailable | expand |
On Thu, Jan 10, 2019 at 02:22:07PM +0800, Chen-Yu Tsai wrote: > 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: 4a59058f0b09 ("clocksource/drivers/sun5i: Refactor the current code") > Signed-off-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Thanks! Maxime
On 10/01/2019 07:22, Chen-Yu Tsai wrote: > 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: 4a59058f0b09 ("clocksource/drivers/sun5i: Refactor the current code") > Signed-off-by: Chen-Yu Tsai <wens@csie.org> > --- Applied thanks.
On Thu, Jan 10, 2019 at 5:19 PM Daniel Lezcano <daniel.lezcano@linaro.org> wrote: > > On 10/01/2019 07:22, Chen-Yu Tsai wrote: > > 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: 4a59058f0b09 ("clocksource/drivers/sun5i: Refactor the current code") > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> > > --- > > Applied thanks. I'm not seeing this in linux-next, nor the patch arm64: arch_timer: Workaround for Allwinner A64 timer instability Any idea where these ended up? Thanks ChenYu
On 24/01/2019 09:56, Chen-Yu Tsai wrote: > On Thu, Jan 10, 2019 at 5:19 PM Daniel Lezcano > <daniel.lezcano@linaro.org> wrote: >> >> On 10/01/2019 07:22, Chen-Yu Tsai wrote: >>> 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: 4a59058f0b09 ("clocksource/drivers/sun5i: Refactor the current code") >>> Signed-off-by: Chen-Yu Tsai <wens@csie.org> >>> --- >> >> Applied thanks. > > I'm not seeing this in linux-next, nor the patch > > arm64: arch_timer: Workaround for Allwinner A64 timer instability > > Any idea where these ended up? Yeah, I have a rough idea. They are now in linux-next via the clockevents/next branch.
diff --git a/drivers/clocksource/timer-sun5i.c b/drivers/clocksource/timer-sun5i.c index 3b56ea3f52af..552c5254390c 100644 --- a/drivers/clocksource/timer-sun5i.c +++ b/drivers/clocksource/timer-sun5i.c @@ -202,6 +202,11 @@ static int __init sun5i_setup_clocksource(struct device_node *node, } 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.clk = clk; @@ -275,6 +280,11 @@ static int __init sun5i_setup_clockevent(struct device_node *node, void __iomem } 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.ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);
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: 4a59058f0b09 ("clocksource/drivers/sun5i: Refactor the current code") Signed-off-by: Chen-Yu Tsai <wens@csie.org> --- drivers/clocksource/timer-sun5i.c | 10 ++++++++++ 1 file changed, 10 insertions(+)