[PATCH] consolidate

Tvrtko Ursulin tvrtko.ursulin at linux.intel.com
Thu Nov 7 13:29:31 UTC 2019


From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
---
 drivers/dma-buf/dma-resv.c | 64 ++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 37 deletions(-)

diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
index a05ff542be22..90df56af710c 100644
--- a/drivers/dma-buf/dma-resv.c
+++ b/drivers/dma-buf/dma-resv.c
@@ -508,6 +508,23 @@ int dma_resv_get_fences_rcu(struct dma_resv *obj,
 }
 EXPORT_SYMBOL_GPL(dma_resv_get_fences_rcu);
 
+static int dma_resv_test_signaled_single(struct dma_fence *lfence)
+{
+	int ret = 1;
+
+	if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &lfence->flags)) {
+		struct dma_fence *fence = dma_fence_get_rcu(lfence);
+
+		if (!fence)
+			return -1;
+
+		ret = !!dma_fence_is_signaled(fence);
+		dma_fence_put(fence);
+	}
+
+	return ret;
+}
+
 /**
  * dma_resv_wait_timeout_rcu - Wait on reservation's objects
  * shared and/or exclusive fences.
@@ -536,39 +553,29 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj,
 	i = -1;
 
 	fence = rcu_dereference(obj->fence_excl);
-	if (fence && !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
-		if (!dma_fence_get_rcu(fence))
-			goto unlock_retry;
+	if (fence) {
+		int lret = dma_resv_test_signaled_single(fence);
 
-		if (dma_fence_is_signaled(fence)) {
-			dma_fence_put(fence);
+		if (lret < 0)
+			goto unlock_retry;
+		else if (lret)
 			fence = NULL;
-		}
-
-	} else {
-		fence = NULL;
 	}
 
-	if (wait_all) {
+	if (wait_all && !fence) {
 		struct dma_resv_list *fobj = rcu_dereference(obj->fence);
 
 		if (fobj)
 			shared_count = fobj->shared_count;
 
-		for (i = 0; !fence && i < shared_count; ++i) {
+		for (i = 0; i < shared_count; ++i) {
 			struct dma_fence *lfence = rcu_dereference(fobj->shared[i]);
+			int lret = dma_resv_test_signaled_single(lfence);
 
-			if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
-				     &lfence->flags))
-				continue;
-
-			if (!dma_fence_get_rcu(lfence))
+			if (lret < 0)
 				goto unlock_retry;
-
-			if (dma_fence_is_signaled(lfence)) {
-				dma_fence_put(lfence);
+			else if (lret)
 				continue;
-			}
 
 			fence = lfence;
 			break;
@@ -595,23 +602,6 @@ long dma_resv_wait_timeout_rcu(struct dma_resv *obj,
 }
 EXPORT_SYMBOL_GPL(dma_resv_wait_timeout_rcu);
 
-
-static inline int dma_resv_test_signaled_single(struct dma_fence *passed_fence)
-{
-	struct dma_fence *fence, *lfence = passed_fence;
-	int ret = 1;
-
-	if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &lfence->flags)) {
-		fence = dma_fence_get_rcu(lfence);
-		if (!fence)
-			return -1;
-
-		ret = !!dma_fence_is_signaled(fence);
-		dma_fence_put(fence);
-	}
-	return ret;
-}
-
 /**
  * dma_resv_test_signaled_rcu - Test if a reservation object's
  * fences have been signaled.
-- 
2.20.1



More information about the Intel-gfx-trybot mailing list