clocksource/drivers/sun5i: Fail gracefully when clock rate is unavailable
authorChen-Yu Tsai <wens@csie.org>
Thu, 10 Jan 2019 06:22:07 +0000 (14:22 +0800)
committerDaniel Lezcano <daniel.lezcano@linaro.org>
Sat, 23 Feb 2019 11:13:45 +0000 (12:13 +0100)
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>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
drivers/clocksource/timer-sun5i.c

index 3b56ea3f52afc8ee47ca21c38cd0c6aa7ec80021..552c5254390cbe3f9f74e7923c322991fa7b0bed 100644 (file)
@@ -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);