[PATCH] dma-buf: add dma_fence_chain_for_each_unwrap helper v2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add another for_each helper to iterate over all the fences in a chain
with unwrapping each chain node.

v2: fix typos, simplify and rename the new helper

Signed-off-by: Christian König <christian.koenig@xxxxxxx>
---
 drivers/dma-buf/dma-fence-chain.c | 11 ++++-------
 include/linux/dma-fence-chain.h   | 33 +++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c
index 93c42078cb57..6e64fcb2e6ba 100644
--- a/drivers/dma-buf/dma-fence-chain.c
+++ b/drivers/dma-buf/dma-fence-chain.c
@@ -151,12 +151,10 @@ static void dma_fence_chain_cb(struct dma_fence *f, struct dma_fence_cb *cb)
 static bool dma_fence_chain_enable_signaling(struct dma_fence *fence)
 {
 	struct dma_fence_chain *head = to_dma_fence_chain(fence);
+	struct dma_fence *f;
 
 	dma_fence_get(&head->base);
-	dma_fence_chain_for_each(fence, &head->base) {
-		struct dma_fence_chain *chain = to_dma_fence_chain(fence);
-		struct dma_fence *f = chain ? chain->fence : fence;
-
+	dma_fence_chain_for_each_fence(f, fence, &head->base) {
 		dma_fence_get(f);
 		if (!dma_fence_add_callback(f, &head->cb, dma_fence_chain_cb)) {
 			dma_fence_put(fence);
@@ -170,10 +168,9 @@ static bool dma_fence_chain_enable_signaling(struct dma_fence *fence)
 
 static bool dma_fence_chain_signaled(struct dma_fence *fence)
 {
-	dma_fence_chain_for_each(fence, fence) {
-		struct dma_fence_chain *chain = to_dma_fence_chain(fence);
-		struct dma_fence *f = chain ? chain->fence : fence;
+	struct dma_fence *f;
 
+	dma_fence_chain_for_each_fence(f, fence, fence) {
 		if (!dma_fence_is_signaled(f)) {
 			dma_fence_put(fence);
 			return false;
diff --git a/include/linux/dma-fence-chain.h b/include/linux/dma-fence-chain.h
index 934a442db8ac..13a65d65bd31 100644
--- a/include/linux/dma-fence-chain.h
+++ b/include/linux/dma-fence-chain.h
@@ -59,6 +59,24 @@ to_dma_fence_chain(struct dma_fence *fence)
 	return container_of(fence, struct dma_fence_chain, base);
 }
 
+/**
+ * dma_fence_chain_unwrap - unwrap chain node
+ * @fence: fence which could be a chain node
+ *
+ * If the parameter is a chain node return the contained fence, otherwise
+ * return the parameter itself.
+ */
+static inline struct dma_fence *
+dma_fence_chain_unwrap(struct dma_fence *fence)
+{
+	struct dma_fence_chain *chain = to_dma_fence_chain(fence);
+
+	if (!chain)
+		return fence;
+
+	return chain->fence;
+}
+
 /**
  * dma_fence_chain_for_each - iterate over all fences in chain
  * @iter: current fence
@@ -71,6 +89,21 @@ to_dma_fence_chain(struct dma_fence *fence)
 	for (iter = dma_fence_get(head); iter; \
 	     iter = dma_fence_chain_walk(iter))
 
+/**
+ * dma_fence_chain_for_each_fences - iterate over all unwrapped fences in chain
+ * @fence: the unwrapped fence
+ * @iter: current fence
+ * @head: starting point
+ *
+ * Iterate over all fences in the chain with unwrapping. We keep a reference to
+ * the current chain node while inside the loop which must be dropped when breaking
+ * out.
+ */
+#define dma_fence_chain_for_each_fence(fence, iter, head)	\
+	for (iter = dma_fence_get(head);			\
+	     (fence = dma_fence_chain_unwrap(iter));		\
+	     iter = dma_fence_chain_walk(iter))
+
 struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence);
 int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno);
 void dma_fence_chain_init(struct dma_fence_chain *chain,
-- 
2.17.1

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux