Skip to content

Commit 91b3d8e

Browse files
Rob Clarkgregkh
authored andcommitted
drm/msm: Defer fd_install in SUBMIT ioctl
[ Upstream commit f228534 ] Avoid fd_install() until there are no more potential error paths, to avoid put_unused_fd() after the fd is made visible to userspace. Fixes: 68dc6c2 ("drm/msm: Fix submit error-path leaks") Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com> Patchwork: https://patchwork.freedesktop.org/patch/665363/ Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 018afe9 commit 91b3d8e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/gpu/drm/msm/msm_gem_submit.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -869,12 +869,8 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
869869

870870
if (ret == 0 && args->flags & MSM_SUBMIT_FENCE_FD_OUT) {
871871
sync_file = sync_file_create(submit->user_fence);
872-
if (!sync_file) {
872+
if (!sync_file)
873873
ret = -ENOMEM;
874-
} else {
875-
fd_install(out_fence_fd, sync_file->file);
876-
args->fence_fd = out_fence_fd;
877-
}
878874
}
879875

880876
if (ret)
@@ -902,10 +898,14 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
902898
out_unlock:
903899
mutex_unlock(&queue->lock);
904900
out_post_unlock:
905-
if (ret && (out_fence_fd >= 0)) {
906-
put_unused_fd(out_fence_fd);
901+
if (ret) {
902+
if (out_fence_fd >= 0)
903+
put_unused_fd(out_fence_fd);
907904
if (sync_file)
908905
fput(sync_file->file);
906+
} else if (sync_file) {
907+
fd_install(out_fence_fd, sync_file->file);
908+
args->fence_fd = out_fence_fd;
909909
}
910910

911911
if (!IS_ERR_OR_NULL(submit)) {

0 commit comments

Comments
 (0)