Skip to content

Commit d27326a

Browse files
Dan CarpenterChristianKoenigAMD
authored andcommitted
dma-buf/sw_sync: Decrement refcount on error in sw_sync_ioctl_get_deadline()
Call dma_fence_put(fence) before returning an error if dma_fence_to_sync_pt() fails. Use an unwind ladder at the end of the function to do the cleanup. Fixes: 70e67aa ("dma-buf/sw_sync: Add fence deadline support") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Christian König <christian.koenig@amd.com> Link: https://patchwork.freedesktop.org/patch/msgid/a010a1ac-107b-4fc0-a052-9fd3706ad690@stanley.mountain Signed-off-by: Christian König <christian.koenig@amd.com>
1 parent 31660b4 commit d27326a

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

drivers/dma-buf/sw_sync.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,15 +438,17 @@ static int sw_sync_ioctl_get_deadline(struct sync_timeline *obj, unsigned long a
438438
return -EINVAL;
439439

440440
pt = dma_fence_to_sync_pt(fence);
441-
if (!pt)
442-
return -EINVAL;
441+
if (!pt) {
442+
ret = -EINVAL;
443+
goto put_fence;
444+
}
443445

444446
spin_lock_irqsave(fence->lock, flags);
445-
if (test_bit(SW_SYNC_HAS_DEADLINE_BIT, &fence->flags)) {
446-
data.deadline_ns = ktime_to_ns(pt->deadline);
447-
} else {
447+
if (!test_bit(SW_SYNC_HAS_DEADLINE_BIT, &fence->flags)) {
448448
ret = -ENOENT;
449+
goto unlock;
449450
}
451+
data.deadline_ns = ktime_to_ns(pt->deadline);
450452
spin_unlock_irqrestore(fence->lock, flags);
451453

452454
dma_fence_put(fence);
@@ -458,6 +460,13 @@ static int sw_sync_ioctl_get_deadline(struct sync_timeline *obj, unsigned long a
458460
return -EFAULT;
459461

460462
return 0;
463+
464+
unlock:
465+
spin_unlock_irqrestore(fence->lock, flags);
466+
put_fence:
467+
dma_fence_put(fence);
468+
469+
return ret;
461470
}
462471

463472
static long sw_sync_ioctl(struct file *file, unsigned int cmd,

0 commit comments

Comments
 (0)