@@ -662,21 +662,19 @@ int dma_fence_add_callback(struct dma_fence *fence, struct dma_fence_cb *cb,
unsigned long flags;
int ret = 0;
+ __dma_fence_cb_init(cb, func);
+
if (WARN_ON(!fence || !func))
return -EINVAL;
- if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
- INIT_LIST_HEAD(&cb->node);
+ if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
return -ENOENT;
- }
spin_lock_irqsave(fence->lock, flags);
if (__dma_fence_enable_signaling(fence)) {
- cb->func = func;
list_add_tail(&cb->node, &fence->cb_list);
} else {
- INIT_LIST_HEAD(&cb->node);
ret = -ENOENT;
}
@@ -795,7 +793,7 @@ dma_fence_default_wait(struct dma_fence *fence, bool intr, signed long timeout)
goto out;
}
- cb.base.func = dma_fence_default_wait_cb;
+ __dma_fence_cb_init(&cb.base, dma_fence_default_wait_cb);
cb.task = current;
list_add(&cb.base.node, &fence->cb_list);
@@ -629,4 +629,11 @@ static inline bool dma_fence_is_container(struct dma_fence *fence)
return dma_fence_is_array(fence) || dma_fence_is_chain(fence);
}
+static inline void __dma_fence_cb_init(struct dma_fence_cb *cb,
+ dma_fence_func_t func)
+{
+ INIT_LIST_HEAD(&cb->node);
+ cb->func = func;
+}
+
#endif /* __LINUX_DMA_FENCE_H */