Skip to content

iio: core: Don't free buffer0 blocks when it's still in use via buffer fd API#3318

Open
nunojsa wants to merge 1 commit into
mainfrom
xlnx/fix/buf-mmap-multibuffer
Open

iio: core: Don't free buffer0 blocks when it's still in use via buffer fd API#3318
nunojsa wants to merge 1 commit into
mainfrom
xlnx/fix/buf-mmap-multibuffer

Conversation

@nunojsa
Copy link
Copy Markdown
Collaborator

@nunojsa nunojsa commented May 14, 2026

When a user opens /dev/iio:deviceN to issue IIO_BUFFER_GET_FD_IOCTL for any buffer (including buffer0), the chrdev must be opened and then closed. On close, iio_chrdev_release() unconditionally frees buffer0's mmap blocks via iio_buffer_free_blocks().

This is wrong when buffer0 is actively streaming through its own per-buffer fd — the chrdev close destroys the blocks and kills the stream.

Guard the iio_buffer_free_blocks() call by checking buffer0's IIO_BUSY_BIT_POS flag. If buffer0's fd is still open and active, its blocks are managed by the buffer's own fd and will be freed in iio_buffer_chrdev_release() instead.

This becomes a problem with multi buffer support when userspace (rightfully) opens the main chardev to get the buffer handle and then closes it again.

PR Type

  • Bug fix (a change that fixes an issue)
  • New feature (a change that adds new functionality)
  • Breaking change (a change that affects other repos or cause CIs to fail)

PR Checklist

  • I have conducted a self-review of my own code changes
  • I have compiled my changes, including the documentation
  • I have tested the changes on the relevant hardware
  • I have updated the documentation outside this repo accordingly
  • I have provided links for the relevant upstream lore

…r fd API

When a user opens /dev/iio:deviceN to issue IIO_BUFFER_GET_FD_IOCTL for
any buffer (including buffer0), the chrdev must be opened and then
closed. On close, iio_chrdev_release() unconditionally frees buffer0's
mmap blocks via iio_buffer_free_blocks().

This is wrong when buffer0 is actively streaming through its own
per-buffer fd — the chrdev close destroys the blocks and kills the
stream.

Guard the iio_buffer_free_blocks() call by checking buffer0's
IIO_BUSY_BIT_POS flag. If buffer0's fd is still open and active, its
blocks are managed by the buffer's own fd and will be freed in
iio_buffer_chrdev_release() instead.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant