* [PATCH v2] dma-buf/sw_sync: Decrement refcount on error in sw_sync_ioctl_get_deadline()
@ 2025-04-08 11:01 Dan Carpenter
2025-04-11 13:20 ` Christian König
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2025-04-08 11:01 UTC (permalink / raw)
To: Rob Clark
Cc: Sumit Semwal, Gustavo Padovan, Christian König,
Dmitry Baryshkov, Pekka Paalanen, linux-media, dri-devel,
linaro-mm-sig, linux-kernel, kernel-janitors
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: 70e67aaec2f4 ("dma-buf/sw_sync: Add fence deadline support")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
v2: style changes.
drivers/dma-buf/sw_sync.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c
index f5905d67dedb..22a808995f10 100644
--- a/drivers/dma-buf/sw_sync.c
+++ b/drivers/dma-buf/sw_sync.c
@@ -438,15 +438,17 @@ static int sw_sync_ioctl_get_deadline(struct sync_timeline *obj, unsigned long a
return -EINVAL;
pt = dma_fence_to_sync_pt(fence);
- if (!pt)
- return -EINVAL;
+ if (!pt) {
+ ret = -EINVAL;
+ goto put_fence;
+ }
spin_lock_irqsave(fence->lock, flags);
- if (test_bit(SW_SYNC_HAS_DEADLINE_BIT, &fence->flags)) {
- data.deadline_ns = ktime_to_ns(pt->deadline);
- } else {
+ if (!test_bit(SW_SYNC_HAS_DEADLINE_BIT, &fence->flags)) {
ret = -ENOENT;
+ goto unlock;
}
+ data.deadline_ns = ktime_to_ns(pt->deadline);
spin_unlock_irqrestore(fence->lock, flags);
dma_fence_put(fence);
@@ -458,6 +460,13 @@ static int sw_sync_ioctl_get_deadline(struct sync_timeline *obj, unsigned long a
return -EFAULT;
return 0;
+
+unlock:
+ spin_unlock_irqrestore(fence->lock, flags);
+put_fence:
+ dma_fence_put(fence);
+
+ return ret;
}
static long sw_sync_ioctl(struct file *file, unsigned int cmd,
--
2.47.2
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] dma-buf/sw_sync: Decrement refcount on error in sw_sync_ioctl_get_deadline()
2025-04-08 11:01 [PATCH v2] dma-buf/sw_sync: Decrement refcount on error in sw_sync_ioctl_get_deadline() Dan Carpenter
@ 2025-04-11 13:20 ` Christian König
0 siblings, 0 replies; 2+ messages in thread
From: Christian König @ 2025-04-11 13:20 UTC (permalink / raw)
To: Dan Carpenter, Rob Clark
Cc: Sumit Semwal, Gustavo Padovan, Dmitry Baryshkov, Pekka Paalanen,
linux-media, dri-devel, linaro-mm-sig, linux-kernel,
kernel-janitors
Am 08.04.25 um 13:01 schrieb Dan Carpenter:
> 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: 70e67aaec2f4 ("dma-buf/sw_sync: Add fence deadline support")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed and pushed to drm-misc-fixes.
Sorry for the delay, I was fighting a bit with dim after the migration.
Thanks,
Christian.
> ---
> v2: style changes.
>
> drivers/dma-buf/sw_sync.c | 19 ++++++++++++++-----
> 1 file changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c
> index f5905d67dedb..22a808995f10 100644
> --- a/drivers/dma-buf/sw_sync.c
> +++ b/drivers/dma-buf/sw_sync.c
> @@ -438,15 +438,17 @@ static int sw_sync_ioctl_get_deadline(struct sync_timeline *obj, unsigned long a
> return -EINVAL;
>
> pt = dma_fence_to_sync_pt(fence);
> - if (!pt)
> - return -EINVAL;
> + if (!pt) {
> + ret = -EINVAL;
> + goto put_fence;
> + }
>
> spin_lock_irqsave(fence->lock, flags);
> - if (test_bit(SW_SYNC_HAS_DEADLINE_BIT, &fence->flags)) {
> - data.deadline_ns = ktime_to_ns(pt->deadline);
> - } else {
> + if (!test_bit(SW_SYNC_HAS_DEADLINE_BIT, &fence->flags)) {
> ret = -ENOENT;
> + goto unlock;
> }
> + data.deadline_ns = ktime_to_ns(pt->deadline);
> spin_unlock_irqrestore(fence->lock, flags);
>
> dma_fence_put(fence);
> @@ -458,6 +460,13 @@ static int sw_sync_ioctl_get_deadline(struct sync_timeline *obj, unsigned long a
> return -EFAULT;
>
> return 0;
> +
> +unlock:
> + spin_unlock_irqrestore(fence->lock, flags);
> +put_fence:
> + dma_fence_put(fence);
> +
> + return ret;
> }
>
> static long sw_sync_ioctl(struct file *file, unsigned int cmd,
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-11 13:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-08 11:01 [PATCH v2] dma-buf/sw_sync: Decrement refcount on error in sw_sync_ioctl_get_deadline() Dan Carpenter
2025-04-11 13:20 ` Christian König
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®