clockevents: Use helpers to check the state of a clockevent device
[firefly-linux-kernel-4.4.55.git] / kernel / time / tick-oneshot.c
index 67a64b1670bfdb984c7d9edec34f7eadd04800ec..3f9715bec2910aef445bcbf75f1fbaea8af72097 100644 (file)
@@ -28,6 +28,22 @@ int tick_program_event(ktime_t expires, int force)
 {
        struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
 
+       if (unlikely(expires.tv64 == KTIME_MAX)) {
+               /*
+                * We don't need the clock event device any more, stop it.
+                */
+               clockevents_set_state(dev, CLOCK_EVT_STATE_ONESHOT_STOPPED);
+               return 0;
+       }
+
+       if (unlikely(clockevent_state_oneshot_stopped(dev))) {
+               /*
+                * We need the clock event again, configure it in ONESHOT mode
+                * before using it.
+                */
+               clockevents_set_state(dev, CLOCK_EVT_STATE_ONESHOT);
+       }
+
        return clockevents_program_event(dev, expires, force);
 }