iio: buffer: serialize buffer teardown with mode claims
PATCH 1/1 iio: buffer: serialize buffer teardown with mode claims
Buffer-mode claims hold mlock to guarantee that the device remains in buffer mode until the claim is released. Normal buffer updates take info_exist_lock followed by mlock in iio_update_buffers().
However, iio_device_unregister() disables and deactivates all buffers without taking mlock. This can invalidate buffer state, including active_scan_mask, while a buffer-mode claim is held.
Take mlock in iio_disable_all_buffers() so that unregister honors the mode-claim lifetime guarantee. The info_exist_lock -> mlock ordering matches iio_update_buffers().
--- drivers/iio/industrialio-buffer.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/iio/industrialio-buffer.c +4 -0
@@ -1377,6 +1377,10 @@ EXPORT_SYMBOL_GPL(iio_update_buffers);void iio_disable_all_buffers (struct iio_dev *indio_dev) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev); + +guard (mutex)(&iio_dev_opaque->mlock); +iio_disable_buffers (indio_dev);iio_buffer_deactivate_all (indio_dev); }
base-commit: dceba8e581e3e8f475da0efbd7a73f3d9524ddd2
Signature · 1 line
2.43.0
Quoted 8 lines · On Mon, 21 Sep 2026 15:24:21 +0900 Jinseob Kim <[email protected]> wrote:
Buffer-mode claims hold mlock to guarantee that the device remains in buffer mode until the claim is released. Normal buffer updates take
info_exist_lockfollowed by mlock iniio_update_buffers().However,
iio_device_unregister()disables and deactivates all buffers without taking mlock. This can invalidate buffer state, includingactive_scan_mask, while a buffer-mode claim is held.
Quoted 8 lines
Take mlock in
iio_disable_all_buffers()so that unregister honors the mode-claim lifetime guarantee. Theinfo_exist_lock-> mlock ordering matchesiio_update_buffers().Fixes 0a8565425afd ("iio: core: introduce iio_device_{claim|release}_buffer_mode() APIs")Suggested-by Jonathan Cameron <[email protected]>Signed-off-by Jinseob Kim <[email protected]>---
Signature · 2 lines
Kind regards, Joshua Crofts
Quoted 8 lines · Jinseob Kim
Buffer-mode claims hold mlock to guarantee that the device remains in buffer mode until the claim is released. Normal buffer updates take
info_exist_lockfollowed by mlock iniio_update_buffers().However,
iio_device_unregister()disables and deactivates all buffers without taking mlock. This can invalidate buffer state, includingactive_scan_mask, while a buffer-mode claim is held.
Quoted 8 lines
Take mlock in
iio_disable_all_buffers()so that unregister honors the mode-claim lifetime guarantee. Theinfo_exist_lock-> mlock ordering matchesiio_update_buffers().Fixes 0a8565425afd ("iio: core: introduce iio_device_{claim|release}_buffer_mode() APIs")Suggested-by Jonathan Cameron <[email protected]>Signed-off-by Jinseob Kim <[email protected]>---
Quoted 23 lines
drivers/iio/industrialio-buffer.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/iio/industrialio-buffer.c +4
-0@@ -1377,6 +1377,10 @@ EXPORT_SYMBOL_GPL(iio_update_buffers);void iio_disable_all_buffers (struct iio_dev *indio_dev) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev); + +guard (mutex)(&iio_dev_opaque->mlock); +iio_disable_buffers (indio_dev);iio_buffer_deactivate_all (indio_dev); }base-commit:
dceba8e581e3e8f475da0efbd7a73f3d9524ddd2Signature · 1 line
2.43.0
Quoted 13 lines · On Thu, 24 Sep 2026 09:24:33 +0100 Nuno Sá <[email protected]> wrote:
Quoted 12 lines · Jinseob Kim
Buffer-mode claims hold mlock to guarantee that the device remains in buffer mode until the claim is released. Normal buffer updates take
info_exist_lockfollowed by mlock iniio_update_buffers().However,
iio_device_unregister()disables and deactivates all buffers without taking mlock. This can invalidate buffer state, includingactive_scan_mask, while a buffer-mode claim is held.Take mlock in
iio_disable_all_buffers()so that unregister honors the mode-claim lifetime guarantee. Theinfo_exist_lock-> mlock ordering matchesiio_update_buffers().
Quoted 6 lines
Quoted 4 lines
Fixes 0a8565425afd ("iio: core: introduce iio_device_{claim|release}_buffer_mode() APIs")Suggested-by Jonathan Cameron <[email protected]>Signed-off-by Jinseob Kim <[email protected]>---
Reviewed-by Nuno Sá <[email protected]>
Applied to the fixes-togreg branch of iio.git and marked for stable inclusion. It should be safe enough but I do want to get some testing on this. Crossed fingers!
Thanks,
Jonathan
Quoted 24 lines
Quoted 24 lines
drivers/iio/industrialio-buffer.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/iio/industrialio-buffer.c +4
-0@@ -1377,6 +1377,10 @@ EXPORT_SYMBOL_GPL(iio_update_buffers);void iio_disable_all_buffers (struct iio_dev *indio_dev) { +struct iio_dev_opaque *iio_dev_opaque =to_iio_dev_opaque (indio_dev); + +guard (mutex)(&iio_dev_opaque->mlock); +iio_disable_buffers (indio_dev);iio_buffer_deactivate_all (indio_dev); }base-commit:
dceba8e581e3e8f475da0efbd7a73f3d9524ddd2Signature · 1 line
2.43.0