Re: [PATCH 09/12] drm/syncobj: fix resource leak in drm_syncobj_import_sync_file_fence

From: Christian König

Date: Tue May 19 2026 - 04:39:00 EST


On 5/16/26 13:06, Julian Orth wrote:
> Previously, if dma_fence_chain_alloc() failed, the syncobj and fence
> would be leaked.

Since it is a bug fix that patch should be send out separately from the patch set.

>
> Signed-off-by: Julian Orth <ju.orth@xxxxxxxxx>
> ---
> drivers/gpu/drm/drm_syncobj.c | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
> index 9b7ecc2978f5..1da96e23dfc0 100644
> --- a/drivers/gpu/drm/drm_syncobj.c
> +++ b/drivers/gpu/drm/drm_syncobj.c
> @@ -767,30 +767,35 @@ static int drm_syncobj_import_sync_file_fence(struct drm_file *file_private,
> {
> struct dma_fence *fence = sync_file_get_fence(fd);
> struct drm_syncobj *syncobj;
> + int ret = 0;

Please don't initialize local return variables, initialize them when you know that the function is successful.

Regards,
Christian.

>
> if (!fence)
> return -EINVAL;
>
> syncobj = drm_syncobj_find(file_private, handle);
> if (!syncobj) {
> - dma_fence_put(fence);
> - return -ENOENT;
> + ret = -ENOENT;
> + goto err_syncobj;
> }
>
> if (point) {
> struct dma_fence_chain *chain = dma_fence_chain_alloc();
>
> - if (!chain)
> - return -ENOMEM;
> + if (!chain) {
> + ret = -ENOMEM;
> + goto err;
> + }
>
> drm_syncobj_add_point(syncobj, chain, fence, point);
> } else {
> drm_syncobj_replace_fence(syncobj, fence);
> }
>
> - dma_fence_put(fence);
> +err:
> drm_syncobj_put(syncobj);
> - return 0;
> +err_syncobj:
> + dma_fence_put(fence);
> + return ret;
> }
>
> static int drm_syncobj_export_sync_file(struct drm_file *file_private,
>