clocksource: arm_arch_timer: Discard unavailable timers correctly
authorSudeep Holla <sudeep.holla@arm.com>
Sun, 28 Sep 2014 23:50:05 +0000 (01:50 +0200)
committerDaniel Lezcano <daniel.lezcano@linaro.org>
Sun, 28 Sep 2014 23:50:05 +0000 (01:50 +0200)
Currently we wait until both cp15 and mem timers are probed if we
have both timer device nodes present in the device tree without
checking if the device is actually available. If one of the timer
device node present is disabled, the system locks up on the boot
as no timer gets registered.

This patch adds the check for the availability of the timer device
so that unavailable timers are discarded correctly. It also adds
the missing of_node_put.

Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Reviewed-by: Stephen Boyd <sboyd@codeaurora.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
drivers/clocksource/arm_arch_timer.c

index 5163ec13429d1e37082b8d32c84684284217322f..7e267e3990ab8c58eb246a1bb3d810c0a12f1918 100644 (file)
@@ -616,17 +616,29 @@ static const struct of_device_id arch_timer_mem_of_match[] __initconst = {
        {},
 };
 
+static bool __init
+arch_timer_probed(int type, const struct of_device_id *matches)
+{
+       struct device_node *dn;
+       bool probed = false;
+
+       dn = of_find_matching_node(NULL, matches);
+       if (dn && of_device_is_available(dn) && (arch_timers_present & type))
+               probed = true;
+       of_node_put(dn);
+
+       return probed;
+}
+
 static void __init arch_timer_common_init(void)
 {
        unsigned mask = ARCH_CP15_TIMER | ARCH_MEM_TIMER;
 
        /* Wait until both nodes are probed if we have two timers */
        if ((arch_timers_present & mask) != mask) {
-               if (of_find_matching_node(NULL, arch_timer_mem_of_match) &&
-                               !(arch_timers_present & ARCH_MEM_TIMER))
+               if (!arch_timer_probed(ARCH_MEM_TIMER, arch_timer_mem_of_match))
                        return;
-               if (of_find_matching_node(NULL, arch_timer_of_match) &&
-                               !(arch_timers_present & ARCH_CP15_TIMER))
+               if (!arch_timer_probed(ARCH_CP15_TIMER, arch_timer_of_match))
                        return;
        }