From 8ce68f7cd1f0b242a2448a1104c9aebb527040c7 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 17 Aug 2019 15:47:34 +0100 Subject: [PATCH] dma-fence: Avoid list_del during fence->cb_list iteration MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Cc: Daniel Vetter Cc: Christian König Reviewed-by: Christian König Link: https://patchwork.freedesktop.org/patch/msgid/20190817144736.7826-4-chris@chris-wilson.co.uk --- 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 8025a891d3e9e..ff0cd6eae766d 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; } -- 2.39.5