diff mbox series

[1/2] dma-buf: Fix dma_resv_wait_timeout handling of timeout = 0.

Message ID 20211015115720.79958-2-maarten.lankhorst@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series dma-buf: Fix breakages from dma_resv_iter conversion. | expand

Commit Message

Maarten Lankhorst Oct. 15, 2021, 11:57 a.m. UTC
Commit ada5c48b11a3 ("dma-buf: use new iterator in dma_resv_wait_timeout")
accidentally started mishandling timeout = 0, by forcing a blocking wait
with timeout = 1 passed to fences. This is not intended, as timeout = 0
may be used for peeking, similar to test_signaled.

Fixes: ada5c48b11a3 ("dma-buf: use new iterator in dma_resv_wait_timeout")
Cc: Christian König <christian.koenig@amd.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 drivers/dma-buf/dma-resv.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Christian König Oct. 18, 2021, 11:20 a.m. UTC | #1
Am 15.10.21 um 13:57 schrieb Maarten Lankhorst:
> Commit ada5c48b11a3 ("dma-buf: use new iterator in dma_resv_wait_timeout")
> accidentally started mishandling timeout = 0, by forcing a blocking wait
> with timeout = 1 passed to fences. This is not intended, as timeout = 0
> may be used for peeking, similar to test_signaled.
>
> Fixes: ada5c48b11a3 ("dma-buf: use new iterator in dma_resv_wait_timeout")
> Cc: Christian König <christian.koenig@amd.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>

Sorry for the delay, back from sick leave just today.

Good catch, but when I read the old code correctly that was also broken 
before by passing in 1 to dma_fence_wait_timeout() for a timeout of 0.

> ---
>   drivers/dma-buf/dma-resv.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
> index 9eb2baa387d4..70a8082660c5 100644
> --- a/drivers/dma-buf/dma-resv.c
> +++ b/drivers/dma-buf/dma-resv.c
> @@ -617,18 +617,18 @@ EXPORT_SYMBOL_GPL(dma_resv_get_fences);
>   long dma_resv_wait_timeout(struct dma_resv *obj, bool wait_all, bool intr,
>   			   unsigned long timeout)
>   {
> -	long ret = timeout ? timeout : 1;
> +	long ret = timeout ?: 1;

Please don't change the coding style here.

Apart from that looks good to me.

Christian.

>   	struct dma_resv_iter cursor;
>   	struct dma_fence *fence;
>   
>   	dma_resv_iter_begin(&cursor, obj, wait_all);
>   	dma_resv_for_each_fence_unlocked(&cursor, fence) {
> +		ret = dma_fence_wait_timeout(fence, intr, timeout);
> +		if (ret <= 0)
> +			break;
>   
> -		ret = dma_fence_wait_timeout(fence, intr, ret);
> -		if (ret <= 0) {
> -			dma_resv_iter_end(&cursor);
> -			return ret;
> -		}
> +		if (timeout)
> +			timeout = ret;
>   	}
>   	dma_resv_iter_end(&cursor);
>
diff mbox series

Patch

diff --git a/drivers/dma-buf/dma-resv.c b/drivers/dma-buf/dma-resv.c
index 9eb2baa387d4..70a8082660c5 100644
--- a/drivers/dma-buf/dma-resv.c
+++ b/drivers/dma-buf/dma-resv.c
@@ -617,18 +617,18 @@  EXPORT_SYMBOL_GPL(dma_resv_get_fences);
 long dma_resv_wait_timeout(struct dma_resv *obj, bool wait_all, bool intr,
 			   unsigned long timeout)
 {
-	long ret = timeout ? timeout : 1;
+	long ret = timeout ?: 1;
 	struct dma_resv_iter cursor;
 	struct dma_fence *fence;
 
 	dma_resv_iter_begin(&cursor, obj, wait_all);
 	dma_resv_for_each_fence_unlocked(&cursor, fence) {
+		ret = dma_fence_wait_timeout(fence, intr, timeout);
+		if (ret <= 0)
+			break;
 
-		ret = dma_fence_wait_timeout(fence, intr, ret);
-		if (ret <= 0) {
-			dma_resv_iter_end(&cursor);
-			return ret;
-		}
+		if (timeout)
+			timeout = ret;
 	}
 	dma_resv_iter_end(&cursor);