Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

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>

authored by

Chen-Yu Tsai and committed by
Daniel Lezcano
e7e7e0d7 75b710af

+10
+10
drivers/clocksource/timer-sun5i.c
··· 202 202 } 203 203 204 204 rate = clk_get_rate(clk); 205 + if (!rate) { 206 + pr_err("Couldn't get parent clock rate\n"); 207 + ret = -EINVAL; 208 + goto err_disable_clk; 209 + } 205 210 206 211 cs->timer.base = base; 207 212 cs->timer.clk = clk; ··· 280 275 } 281 276 282 277 rate = clk_get_rate(clk); 278 + if (!rate) { 279 + pr_err("Couldn't get parent clock rate\n"); 280 + ret = -EINVAL; 281 + goto err_disable_clk; 282 + } 283 283 284 284 ce->timer.base = base; 285 285 ce->timer.ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);