drm/msm/sde: add helper macro for performing ktime comparisons

Linux ktime events can not be directly compared if the timer
has overflowed between them. This change adds a helper macro
to first take the difference between the events and then
compare the result against zero in an attempt to handle timer
overflow situations.

Change-Id: Ic32afc35fbabb757714b5a583cc384389176b239
Signed-off-by: Clarence Ip <cip@codeaurora.org>
diff --git a/drivers/gpu/drm/msm/sde/sde_kms.h b/drivers/gpu/drm/msm/sde/sde_kms.h
index 6f16281..a15e5cd 100644
--- a/drivers/gpu/drm/msm/sde/sde_kms.h
+++ b/drivers/gpu/drm/msm/sde/sde_kms.h
@@ -63,6 +63,17 @@
 #define CHECK_LAYER_BOUNDS(offset, size, max_size) \
 	(((size) > (max_size)) || ((offset) > ((max_size) - (size))))
 
+/**
+ * ktime_compare_safe - compare two ktime structures
+ *	This macro is similar to the standard ktime_compare() function, but
+ *	attempts to also handle ktime overflows.
+ * @A: First ktime value
+ * @B: Second ktime value
+ * Returns: -1 if A < B, 0 if A == B, 1 if A > B
+ */
+#define ktime_compare_safe(A, B) \
+	ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0))
+
 /*
  * struct sde_irq_callback - IRQ callback handlers
  * @func: intr handler