diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index dd07d128adc3..4d885c8e1d4f 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h @@ -320,8 +320,9 @@ static inline void dma_fence_put(struct dma_fence *fence) static inline struct dma_fence *dma_fence_get(struct dma_fence *fence) { if (fence) - kref_get(&fence->refcount); - return fence; + if (kref_get_unless_zero(&fence->refcount)) + return fence; + return NULL; } /** diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c index 8df20b0218a9..ad60ad5e5cd9 100644 --- a/drivers/dma-buf/sw_sync.c +++ b/drivers/dma-buf/sw_sync.c @@ -221,7 +221,8 @@ static void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc) if (!timeline_fence_signaled(&pt->base)) break; - dma_fence_get(&pt->base); + if (!dma_fence_get(&pt->base)) + continue; list_move_tail(&pt->link, &signalled); rb_erase(&pt->node, &obj->pt_tree);