msm: kgsl: Correct the fence reference counting
The sync_file_create() function takes an additional refcount to the
fence. Update the refcounting to avoid a memory leak.
Change-Id: I684377e5a27a2c318fc6f26d0e6ba4a21da1cf9f
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 96873c4..817a6b1 100644
--- a/drivers/gpu/msm/kgsl_sync.c
+++ b/drivers/gpu/msm/kgsl_sync.c
@@ -52,6 +52,10 @@
fence_init(&kfence->fence, &kgsl_sync_fence_ops, &ktimeline->lock,
ktimeline->fence_context, timestamp);
+ /*
+ * sync_file_create() takes a refcount to the fence. This refcount is
+ * put when the fence is signaled.
+ */
kfence->sync_file = sync_file_create(&kfence->fence);
if (kfence->sync_file == NULL) {
@@ -61,9 +65,6 @@
return NULL;
}
- /* Get a refcount to the fence. Put when signaled */
- fence_get(&kfence->fence);
-
spin_lock_irqsave(&ktimeline->lock, flags);
list_add_tail(&kfence->child_list, &ktimeline->child_list_head);
spin_unlock_irqrestore(&ktimeline->lock, flags);
@@ -707,6 +708,14 @@
list_add_tail(&sfence->child_list, &syncsource->child_list_head);
spin_unlock(&syncsource->lock);
out:
+ /*
+ * We're transferring ownership of the fence to the sync file.
+ * The sync file takes an extra refcount when it is created, so put
+ * our refcount.
+ */
+ if (sync_file)
+ fence_put(&sfence->fence);
+
if (ret) {
if (sync_file)
fput(sync_file->file);