Re: [PATCH v2] ALSA: compress: Fix task resource leak on copy_to_user() failure

From: Sreeraj S Kurup

Date: Tue Nov 17 2026 - 11:02:26 EST


Hi Takashi,

Thanks for reviewing.

Regarding dma_buf_put(), get_dma_buf() takes an extra reference
for each DMA-BUF. This reference is intended to be transferred
to the file descriptor through fd_install(). If copy_to_user()
fails before fd_install(), these extra references must be
released separately.

snd_compr_task_free_one() releases the task's original DMA-BUF
references through snd_compr_task_free(). So both the explicit
dma_buf_put() calls and snd_compr_task_free_one() are needed.

Regarding the file descriptor ordering, I moved fd_install()
after copy_to_user() so that the file descriptors are installed
only after the task information is successfully copied to userspace.

There is a small time gap between copying the descriptor numbers and
installing the file descriptors. Userspace should use these descriptors
only after the ioctl completes.

Please let me know if you have any further concerns.

Best regards,
Sreeraj