@@ -348,29 +348,25 @@ EXPORT_SYMBOL(dma_fence_enable_sw_signaling);
int dma_fence_add_callback(struct dma_fence *fence, struct dma_fence_cb *cb,
dma_fence_func_t func)
{
- unsigned long flags;
- int ret = 0;
+ int ret = -ENOENT;
if (WARN_ON(!fence || !func))
return -EINVAL;
- if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
- INIT_LIST_HEAD(&cb->node);
- return -ENOENT;
- }
+ cb->func = func;
+ INIT_LIST_HEAD(&cb->node);
- spin_lock_irqsave(fence->lock, flags);
+ if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
+ unsigned long 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;
+ spin_lock_irqsave(fence->lock, flags);
+ if (__dma_fence_enable_signaling(fence)) {
+ list_add_tail(&cb->node, &fence->cb_list);
+ ret = 0;
+ }
+ spin_unlock_irqrestore(fence->lock, flags);
}
- spin_unlock_irqrestore(fence->lock, flags);
-
return ret;
}
EXPORT_SYMBOL(dma_fence_add_callback);
Rearrange the code to pull the operations beore the fence->lock critical section, and remove a small amount of redundancy: Function old new delta dma_fence_add_callback 156 145 -11 Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> --- drivers/dma-buf/dma-fence.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)