msm: kgsl: Don't signal the timeline if its refcount is zero

Sync timeline signaling is done asynchronously, and each call may
signal multiple timestamps. This means the signal function can be
called with no outstanding fences, and even after the context is
detached but not yet destroyed.  We need to check for a zero refcount
when signaling it. This is safe since we take a context refcount
before signaling the timeline, and the timeline is freed when the
context is destroyed.

Change-Id: I7f91dafc4f5fc2cf15ef6685c7c9cd6e929407a7
Signed-off-by: Lynus Vaz <lvaz@codeaurora.org>
diff --git a/drivers/gpu/msm/kgsl_sync.c b/drivers/gpu/msm/kgsl_sync.c
index 817a6b1..d75ec9d 100644
--- a/drivers/gpu/msm/kgsl_sync.c
+++ b/drivers/gpu/msm/kgsl_sync.c
@@ -370,7 +370,8 @@
 	unsigned long flags;
 	struct kgsl_sync_fence *kfence, *next;
 
-	kref_get(&ktimeline->kref);
+	if (!kref_get_unless_zero(&ktimeline->kref))
+		return;
 
 	spin_lock_irqsave(&ktimeline->lock, flags);
 	if (timestamp_cmp(timestamp, ktimeline->last_timestamp) > 0)