[PATCH 03/10] dma-buf: add dma_fence_array_recycle

Christian König ckoenig.leichtzumerken at gmail.com
Wed Aug 21 12:31:40 UTC 2019


Try to recycle an dma_fence_array object by dropping the last
reference to it without freeing it.

Signed-off-by: Christian König <christian.koenig at amd.com>
---
 drivers/dma-buf/dma-fence-array.c | 27 +++++++++++++++++++++++++++
 include/linux/dma-fence-array.h   |  1 +
 2 files changed, 28 insertions(+)

diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c
index e82f30551aa1..314cf0e881d9 100644
--- a/drivers/dma-buf/dma-fence-array.c
+++ b/drivers/dma-buf/dma-fence-array.c
@@ -188,6 +188,33 @@ void dma_fence_array_init(struct dma_fence_array *array, u64 context,
 }
 EXPORT_SYMBOL(dma_fence_array_init);
 
+/**
+ * dma_fence_array_reuse - dummy for dma_fence_array_recycle
+ */
+static void dma_fence_array_reuse(struct kref *kref)
+{
+	struct dma_fence_array *array = container_of(kref, typeof(*array),
+						     base.refcount);
+
+	WARN_ON_ONCE(!list_empty(&array->base.cb_list));
+}
+
+/**
+ * dma_fence_array_try_reuse - try to reuse a dma_fence_array object
+ * @array: array which we should try to reuse
+ *
+ * Try to drop the last reference to an dma_fence_array and so allow it to be
+ * reused.
+ *
+ * Returns true if this was the last reference then caller can reuse the array.
+ * In this case the array is reset into a state where it can be used with
+ * dma_fence_array_init again.
+ */
+bool dma_fence_array_recycle(struct dma_fence_array *array)
+{
+	return kref_put(&array->base.refcount, dma_fence_array_reuse);
+}
+
 /**
  * dma_fence_array_free - free a dma_fence_array object
  * @array: the object to free
diff --git a/include/linux/dma-fence-array.h b/include/linux/dma-fence-array.h
index be85c06b524d..35d1d1e7c93b 100644
--- a/include/linux/dma-fence-array.h
+++ b/include/linux/dma-fence-array.h
@@ -93,6 +93,7 @@ struct dma_fence_array *dma_fence_array_alloc(int num_fences,
 					      struct dma_fence **fences);
 void dma_fence_array_init(struct dma_fence_array *array, u64 context,
 			  unsigned int seqno, bool signal_on_any);
+bool dma_fence_array_recycle(struct dma_fence_array *array);
 void dma_fence_array_free(struct dma_fence_array *array);
 
 /**
-- 
2.17.1



More information about the dri-devel mailing list