diff mbox series

[1/2] dma-buf: Avoid list_del during fence->cb_list iteration

Message ID 20190816152152.27550-1-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show
Series [1/2] dma-buf: Avoid list_del during fence->cb_list iteration | expand

Commit Message

Chris Wilson Aug. 16, 2019, 3:21 p.m. UTC
Before we notify the fence signal callback, we remove the cb from the
list. However, since we are processing the entire list from underneath
the spinlock, we do not need to individual delete each element, but can
simply reset the link and the entire list.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Christian König <christian.koenig@amd.com>
---
 drivers/dma-buf/dma-fence.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Christian König Aug. 16, 2019, 4:14 p.m. UTC | #1
Am 16.08.19 um 17:21 schrieb Chris Wilson:
> Before we notify the fence signal callback, we remove the cb from the
> list. However, since we are processing the entire list from underneath
> the spinlock, we do not need to individual delete each element, but can
> simply reset the link and the entire list.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Christian König <christian.koenig@amd.com>

Reviewed-by: Christian König <christian.koenig@amd.com> for the series.

> ---
>   drivers/dma-buf/dma-fence.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
> index 8025a891d3e9..ff0cd6eae766 100644
> --- a/drivers/dma-buf/dma-fence.c
> +++ b/drivers/dma-buf/dma-fence.c
> @@ -149,9 +149,12 @@ int dma_fence_signal_locked(struct dma_fence *fence)
>   		trace_dma_fence_signaled(fence);
>   	}
>   
> -	list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {
> -		list_del_init(&cur->node);
> -		cur->func(fence, cur);
> +	if (!list_empty(&fence->cb_list)) {
> +		list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {
> +			INIT_LIST_HEAD(&cur->node);
> +			cur->func(fence, cur);
> +		}
> +		INIT_LIST_HEAD(&fence->cb_list);
>   	}
>   	return ret;
>   }
diff mbox series

Patch

diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index 8025a891d3e9..ff0cd6eae766 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -149,9 +149,12 @@  int dma_fence_signal_locked(struct dma_fence *fence)
 		trace_dma_fence_signaled(fence);
 	}
 
-	list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {
-		list_del_init(&cur->node);
-		cur->func(fence, cur);
+	if (!list_empty(&fence->cb_list)) {
+		list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {
+			INIT_LIST_HEAD(&cur->node);
+			cur->func(fence, cur);
+		}
+		INIT_LIST_HEAD(&fence->cb_list);
 	}
 	return ret;
 }