Merge tag 'drm-misc-next-2018-02-13' of git://anongit.freedesktop.org/drm/drm-misc...
[linux-2.6-block.git] / drivers / dma-buf / reservation.c
index 461afa9febd47cd615163af194fb9e37f4bad86c..314eb1071cce79af9d276c09acd0a832cbd55163 100644 (file)
@@ -484,13 +484,15 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
                                         unsigned long timeout)
 {
        struct dma_fence *fence;
-       unsigned seq, shared_count, i = 0;
+       unsigned seq, shared_count;
        long ret = timeout ? timeout : 1;
+       int i;
 
 retry:
        shared_count = 0;
        seq = read_seqcount_begin(&obj->seq);
        rcu_read_lock();
+       i = -1;
 
        fence = rcu_dereference(obj->fence_excl);
        if (fence && !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
@@ -506,14 +508,14 @@ retry:
                fence = NULL;
        }
 
-       if (!fence && wait_all) {
+       if (wait_all) {
                struct reservation_object_list *fobj =
                                                rcu_dereference(obj->fence);
 
                if (fobj)
                        shared_count = fobj->shared_count;
 
-               for (i = 0; i < shared_count; ++i) {
+               for (i = 0; !fence && i < shared_count; ++i) {
                        struct dma_fence *lfence = rcu_dereference(fobj->shared[i]);
 
                        if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,