Rely on the fd exit path machinery.

Signed-off-by: Christian Brauner (Amutable) <[email protected]>
---
 sound/core/compress_offload.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index 23d62fede06e..94bc226f8db9 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -1065,7 +1065,8 @@ static u64 snd_compr_seqno_next(struct snd_compr_stream 
*stream)
 static int snd_compr_task_new(struct snd_compr_stream *stream, struct 
snd_compr_task *utask)
 {
        struct snd_compr_task_runtime *task;
-       int retval, fd_i, fd_o;
+       int retval;
+       const struct fd_slot *fd_i, *fd_o;
 
        if (stream->runtime->total_tasks >= stream->runtime->fragments)
                return -EBUSY;
@@ -1080,29 +1081,26 @@ static int snd_compr_task_new(struct snd_compr_stream 
*stream, struct snd_compr_
        if (retval < 0)
                goto cleanup;
        /* similar functionality as in dma_buf_fd(), but ensure that both
-          file descriptors are allocated before fd_install() */
+          file descriptors are reserved before either is staged */
        if (!task->input || !task->input->file || !task->output || 
!task->output->file) {
                retval = -EINVAL;
                goto free_driver_task;
        }
-       fd_i = get_unused_fd_flags(O_WRONLY|O_CLOEXEC);
-       if (fd_i < 0) {
-               retval = fd_i;
+       fd_i = fd_prepare(O_WRONLY|O_CLOEXEC);
+       if (IS_ERR(fd_i)) {
+               retval = PTR_ERR(fd_i);
                goto free_driver_task;
        }
-       fd_o = get_unused_fd_flags(O_RDONLY|O_CLOEXEC);
-       if (fd_o < 0) {
-               retval = fd_o;
-               put_unused_fd(fd_i);
+       fd_o = fd_prepare(O_RDONLY|O_CLOEXEC);
+       if (IS_ERR(fd_o)) {
+               retval = PTR_ERR(fd_o);
                goto free_driver_task;
        }
        /* keep dmabuf reference until freed with task free ioctl */
        get_dma_buf(task->input);
        get_dma_buf(task->output);
-       fd_install(fd_i, task->input->file);
-       fd_install(fd_o, task->output->file);
-       utask->input_fd = fd_i;
-       utask->output_fd = fd_o;
+       utask->input_fd = fd_stage(fd_i, task->input->file);
+       utask->output_fd = fd_stage(fd_o, task->output->file);
        list_add_tail(&task->list, &stream->runtime->tasks);
        stream->runtime->total_tasks++;
        return 0;

-- 
2.53.0


Reply via email to