Skip to content

Commit 68dc6c2

Browse files
committed
drm/msm: Fix submit error-path leaks
For errors after msm_submitqueue_get(), we need to drop the submitqueue reference. Additionally after get_unused_fd() we need to drop the fd. The ordering for dropping the queue lock and put_unused_fd() is not important, so just move this all into out_post_unlock. v2: Only drop queue ref if submit doesn't take it v3: Fix unitialized submit ref in error path v4: IS_ERR_OR_NULL() Reported-by: pinkperfect2021@gmail.com Fixes: f0de40a drm/msm: ("Reorder lock vs submit alloc") Signed-off-by: Rob Clark <robdclark@chromium.org> Patchwork: https://patchwork.freedesktop.org/patch/536073/ Link: https://lore.kernel.org/r/20230509203041.440619-1-robdclark@gmail.com
1 parent db40d29 commit 68dc6c2

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

drivers/gpu/drm/msm/msm_gem_submit.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
722722
struct msm_drm_private *priv = dev->dev_private;
723723
struct drm_msm_gem_submit *args = data;
724724
struct msm_file_private *ctx = file->driver_priv;
725-
struct msm_gem_submit *submit;
725+
struct msm_gem_submit *submit = NULL;
726726
struct msm_gpu *gpu = priv->gpu;
727727
struct msm_gpu_submitqueue *queue;
728728
struct msm_ringbuffer *ring;
@@ -769,13 +769,15 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
769769
out_fence_fd = get_unused_fd_flags(O_CLOEXEC);
770770
if (out_fence_fd < 0) {
771771
ret = out_fence_fd;
772-
return ret;
772+
goto out_post_unlock;
773773
}
774774
}
775775

776776
submit = submit_create(dev, gpu, queue, args->nr_bos, args->nr_cmds);
777-
if (IS_ERR(submit))
778-
return PTR_ERR(submit);
777+
if (IS_ERR(submit)) {
778+
ret = PTR_ERR(submit);
779+
goto out_post_unlock;
780+
}
779781

780782
trace_msm_gpu_submit(pid_nr(submit->pid), ring->id, submit->ident,
781783
args->nr_bos, args->nr_cmds);
@@ -962,11 +964,20 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
962964
if (has_ww_ticket)
963965
ww_acquire_fini(&submit->ticket);
964966
out_unlock:
965-
if (ret && (out_fence_fd >= 0))
966-
put_unused_fd(out_fence_fd);
967967
mutex_unlock(&queue->lock);
968968
out_post_unlock:
969-
msm_gem_submit_put(submit);
969+
if (ret && (out_fence_fd >= 0))
970+
put_unused_fd(out_fence_fd);
971+
972+
if (!IS_ERR_OR_NULL(submit)) {
973+
msm_gem_submit_put(submit);
974+
} else {
975+
/*
976+
* If the submit hasn't yet taken ownership of the queue
977+
* then we need to drop the reference ourself:
978+
*/
979+
msm_submitqueue_put(queue);
980+
}
970981
if (!IS_ERR_OR_NULL(post_deps)) {
971982
for (i = 0; i < args->nr_out_syncobjs; ++i) {
972983
kfree(post_deps[i].chain);

0 commit comments

Comments
 (0)