Re: [PATCH] tools: iio: Keep the buffer index separate from the acquired fd

From: Jonathan Cameron

Date: Sat Nov 21 2026 - 16:19:12 EST


On Sat, 21 Nov 2026 02:33:17 +0530
Arnav Kapoor <kapoorarnav43@xxxxxxxxx> wrote:

> On Fri, Nov 20, 2026 at 02:19:03PM +0800, Zhu Jun wrote:
> > IIO_BUFFER_GET_FD_IOCTL takes the buffer index as input and replaces
> > it with a file descriptor on success. On failure, cleanup can mistake
> > the unchanged index for an open fd and close a different file. Only
> > assign the returned descriptor to buf_fd after successful acquisition.
>
> Checked against iio_device_buffer_getfd(): on every error path it
> returns before copy_to_user(), so the argument keeps the index, and the
> error: label then closes it because buf_fd >= 0. With the default
> buffer index 0 that closes stdin, with -b 1 stdout. The patch fixes
> that, buffer_idx is already rejected when negative, and it applies to
> iio testing, builds without warnings and is checkpatch --strict clean.
>
> Reviewed-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>

Applied to the testing branch of iio.git. That means it is queued up
for the next merge window.

Thanks,

Jonathan