aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaroslav Kysela <[email protected]>2024-12-17 10:07:26 +0000
committerTakashi Iwai <[email protected]>2024-12-20 08:52:15 +0000
commit3d3f43fab4cfb9cf245e3dbffa1736ce925bb54a (patch)
tree2f8a7f472e66952bade24e03028b05968615ffa4
parentALSA: compress_offload: use safe list iteration in snd_compr_task_seq() (diff)
downloadkernel-3d3f43fab4cfb9cf245e3dbffa1736ce925bb54a.tar.gz
kernel-3d3f43fab4cfb9cf245e3dbffa1736ce925bb54a.zip
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/[email protected]/ Fixes: 04177158cf98 ("ALSA: compress_offload: introduce accel operation mode") Reported-by: Dan Carpenter <[email protected]> Cc: Vinod Koul <[email protected]> Signed-off-by: Jaroslav Kysela <[email protected]> Signed-off-by: Takashi Iwai <[email protected]> Link: https://patch.msgid.link/[email protected]
-rw-r--r--sound/core/compress_offload.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index bdb6e307e453..edf5aadf38e5 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -1025,7 +1025,7 @@ 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;
+ int retval, fd_i, fd_o;
if (stream->runtime->total_tasks >= stream->runtime->fragments)
return -EBUSY;
@@ -1039,16 +1039,24 @@ static int snd_compr_task_new(struct snd_compr_stream *stream, struct snd_compr_
retval = stream->ops->task_create(stream, task);
if (retval < 0)
goto cleanup;
- utask->input_fd = dma_buf_fd(task->input, O_WRONLY|O_CLOEXEC);
- if (utask->input_fd < 0) {
- retval = utask->input_fd;
+ /* similar functionality as in dma_buf_fd(), but ensure that both
+ file descriptors are allocated before fd_install() */
+ if (!task->input || !task->input->file || !task->output || !task->output->file) {
+ retval = -EINVAL;
goto cleanup;
}
- utask->output_fd = dma_buf_fd(task->output, O_RDONLY|O_CLOEXEC);
- if (utask->output_fd < 0) {
- retval = utask->output_fd;
+ fd_i = get_unused_fd_flags(O_WRONLY|O_CLOEXEC);
+ if (fd_i < 0)
+ goto cleanup;
+ fd_o = get_unused_fd_flags(O_RDONLY|O_CLOEXEC);
+ if (fd_o < 0) {
+ put_unused_fd(fd_i);
goto cleanup;
}
+ fd_install(fd_i, task->input->file);
+ fd_install(fd_o, task->output->file);
+ utask->input_fd = fd_i;
+ utask->output_fd = fd_o;
/* keep dmabuf reference until freed with task free ioctl */
dma_buf_get(utask->input_fd);
dma_buf_get(utask->output_fd);