Rely on the fd exit path machinery. Signed-off-by: Christian Brauner (Amutable) --- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index 03b41f803520..e5c0f7201cea 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -1581,7 +1581,8 @@ int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data, struct dma_fence *fence; struct drm_syncobj *syncobj; struct sync_file *sync_file; - int fd, r; + const struct fd_slot *fd; + int r; fence = amdgpu_cs_get_fence(adev, filp, &info->in.fence); if (IS_ERR(fence)) @@ -1610,21 +1611,18 @@ int amdgpu_cs_fence_to_handle_ioctl(struct drm_device *dev, void *data, return r; case AMDGPU_FENCE_TO_HANDLE_GET_SYNC_FILE_FD: - fd = get_unused_fd_flags(O_CLOEXEC); - if (fd < 0) { + fd = fd_prepare(O_CLOEXEC); + if (IS_ERR(fd)) { dma_fence_put(fence); - return fd; + return PTR_ERR(fd); } sync_file = sync_file_create(fence); dma_fence_put(fence); - if (!sync_file) { - put_unused_fd(fd); + if (!sync_file) return -ENOMEM; - } - fd_install(fd, sync_file->file); - info->out.handle = fd; + info->out.handle = fd_stage(fd, sync_file->file); return 0; default: -- 2.53.0