Skip to content

Commit 3d3f43f

Browse files
perexgtiwai
authored andcommitted
ALSA: compress_offload: improve file descriptors installation for dma-buf
Avoid to use single dma_buf_fd() call for both directions. This code ensures that both file descriptors are allocated before fd_install(). Link: https://lore.kernel.org/linux-sound/6a923647-4495-4cff-a253-b73f48cfd0ea@stanley.mountain/ Fixes: 0417715 ("ALSA: compress_offload: introduce accel operation mode") Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Cc: Vinod Koul <vkoul@kernel.org> Signed-off-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20241217100726.732863-1-perex@perex.cz
1 parent f25a51b commit 3d3f43f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

sound/core/compress_offload.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ static u64 snd_compr_seqno_next(struct snd_compr_stream *stream)
10251025
static int snd_compr_task_new(struct snd_compr_stream *stream, struct snd_compr_task *utask)
10261026
{
10271027
struct snd_compr_task_runtime *task;
1028-
int retval;
1028+
int retval, fd_i, fd_o;
10291029

10301030
if (stream->runtime->total_tasks >= stream->runtime->fragments)
10311031
return -EBUSY;
@@ -1039,16 +1039,24 @@ static int snd_compr_task_new(struct snd_compr_stream *stream, struct snd_compr_
10391039
retval = stream->ops->task_create(stream, task);
10401040
if (retval < 0)
10411041
goto cleanup;
1042-
utask->input_fd = dma_buf_fd(task->input, O_WRONLY|O_CLOEXEC);
1043-
if (utask->input_fd < 0) {
1044-
retval = utask->input_fd;
1042+
/* similar functionality as in dma_buf_fd(), but ensure that both
1043+
file descriptors are allocated before fd_install() */
1044+
if (!task->input || !task->input->file || !task->output || !task->output->file) {
1045+
retval = -EINVAL;
10451046
goto cleanup;
10461047
}
1047-
utask->output_fd = dma_buf_fd(task->output, O_RDONLY|O_CLOEXEC);
1048-
if (utask->output_fd < 0) {
1049-
retval = utask->output_fd;
1048+
fd_i = get_unused_fd_flags(O_WRONLY|O_CLOEXEC);
1049+
if (fd_i < 0)
1050+
goto cleanup;
1051+
fd_o = get_unused_fd_flags(O_RDONLY|O_CLOEXEC);
1052+
if (fd_o < 0) {
1053+
put_unused_fd(fd_i);
10501054
goto cleanup;
10511055
}
1056+
fd_install(fd_i, task->input->file);
1057+
fd_install(fd_o, task->output->file);
1058+
utask->input_fd = fd_i;
1059+
utask->output_fd = fd_o;
10521060
/* keep dmabuf reference until freed with task free ioctl */
10531061
dma_buf_get(utask->input_fd);
10541062
dma_buf_get(utask->output_fd);

0 commit comments

Comments
 (0)