iio: buffer: Fix wait_queue not being removed
Nuno Sá
reviewerPATCH 1/1 iio: buffer: Fix wait_queue not being removed
In the edge case where the IIO device is unregistered while we're buffering, we were directly returning an error without removing the wait queue. Instead, set 'ret' and break out of the loop.
--- drivers/iio/industrialio-buffer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iio/industrialio-buffer.c +4 -2
@@ -228,8 +228,10 @@ static ssize_t iio_buffer_write(struct file *filp, const char __user *buf, written =0 ;add_wait_queue (&rb->pollq, &wait); do { - if (!indio_dev->info) - return -ENODEV; + if (!indio_dev->info) { + ret = -ENODEV; + break; + } if (!iio_buffer_space_available(rb)) { if (signal_pending(current)) {
---
base-commit: f52690c50893ef1504990199c8a2dfbb869f38c6
change-id: 20260216-iio-buffer-write-fix-31ddf8b2a4a0 --
Thanks!
- Nuno Sá
Quoted 9 lines · On 2/16/26 7:24 AM, Nuno Sá via B4 Relay wrote:
From: Nuno Sá <[email protected]>
In the edge case where the IIO device is unregistered while we're buffering, we were directly returning an error without removing the wait queue. Instead, set 'ret' and break out of the loop.
Fixes 9eeee3b0bf19 ("iio: Add output buffer support")Signed-off-by Nuno Sá <[email protected]>---
Quoted 12 lines · On Sat, 21 Feb 2026 15:27:42 -0600 David Lechner <[email protected]> wrote:
Quoted 9 lines · On 2/16/26 7:24 AM, Nuno Sá via B4 Relay wrote:
From: Nuno Sá <[email protected]>
In the edge case where the IIO device is unregistered while we're buffering, we were directly returning an error without removing the wait queue. Instead, set 'ret' and break out of the loop.
Fixes 9eeee3b0bf19 ("iio: Add output buffer support")Signed-off-by Nuno Sá <[email protected]>---
Reviewed-by David Lechner <[email protected]>
This brings the code inline with the near identical flow in the read path.
It's been a while since I last looked at the locking / tear down (what that ->info check is all about). I'll add actually documenting all the corner cases to the todo list as IIRC there are some non obvious ordering constraints. IIRC, in the buffer paths, it is fairly straight forward as it's just an optimization to avoid queuing or draining data when the device is going down - nothing about the buffers themselves involves interacting directly with the hardware.
Applied to the fixes-togreg branch of iio.git and marked for stable.
Thanks,
Jonathan
Quoted 13 lines · Jonathan Cameron
Quoted 10 lines · On Sat, 21 Feb 2026 15:27:42 -0600 David Lechner <[email protected]> wrote:
Quoted 9 lines · On 2/16/26 7:24 AM, Nuno Sá via B4 Relay wrote:
From: Nuno Sá <[email protected]>
In the edge case where the IIO device is unregistered while we're buffering, we were directly returning an error without removing the wait queue. Instead, set 'ret' and break out of the loop.
Fixes 9eeee3b0bf19 ("iio: Add output buffer support")Signed-off-by Nuno Sá <[email protected]>---
Quoted 7 lines
Quoted 2 lines
Reviewed-by David Lechner <[email protected]>This brings the code inline with the near identical flow in the read path.
It's been a while since I last looked at the locking / tear down (what that ->info check is all about). I'll add actually
Yeah not sure if you remember but I already said this a couple of times. In the buffer paths I'm not convinced the check we have is enough. Still very open to races AFAICT. I have it in my list to try and trigger and actual issue/dump on that path so it's not just theory. Already asked the bot to write some stressor/test code :).
Quoted 10 lines
documenting all the corner cases to the todo list as IIRC there are some non obvious ordering constraints. IIRC, in the buffer paths, it is fairly straight forward as it's just an optimization to avoid queuing or draining data when the device is going down - nothing about the buffers themselves involves interacting directly with the hardware.
Applied to the fixes-togreg branch of iio.git and marked for stable.
BTW, I just realized we now have an Assisted-by: tag for getting help from AI. I should say that this bug was identified by Claude code (when bulding the stressor test app I mentioned above :)). So, maybe (or can we Reported by: Claude Code?!!):
- Nuno Sá
Quoted 19 lines · Nuno Sá
Quoted 18 lines · Jonathan Cameron
Quoted 12 lines · On Sat, 21 Feb 2026 15:27:42 -0600 David Lechner <[email protected]> wrote:
Quoted 9 lines · On 2/16/26 7:24 AM, Nuno Sá via B4 Relay wrote:
From: Nuno Sá <[email protected]>
In the edge case where the IIO device is unregistered while we're buffering, we were directly returning an error without removing the wait queue. Instead, set 'ret' and break out of the loop.
Fixes 9eeee3b0bf19 ("iio: Add output buffer support")Signed-off-by Nuno Sá <[email protected]>---
Reviewed-by David Lechner <[email protected]>This brings the code inline with the near identical flow in the read path.
Quoted 7 lines
Quoted 2 lines
It's been a while since I last looked at the locking / tear down (what that ->info check is all about). I'll add actually
Yeah not sure if you remember but I already said this a couple of times. In the buffer paths I'm not convinced the check we have is enough. Still very open to races AFAICT. I have it in my list to try and trigger and actual issue/dump on that path so it's not just theory. Already asked the bot to write some stressor/test code :).
Perhaps also a good task for stress-ng? Ask Colin!
Quoted 15 lines
Quoted 9 lines
documenting all the corner cases to the todo list as IIRC there are some non obvious ordering constraints. IIRC, in the buffer paths, it is fairly straight forward as it's just an optimization to avoid queuing or draining data when the device is going down - nothing about the buffers themselves involves interacting directly with the hardware.
Applied to the fixes-togreg branch of iio.git and marked for stable.
BTW, I just realized we now have an Assisted-by: tag for getting help from AI. I should say that this bug was identified by Claude code (when bulding the stressor test app I mentioned above :)). So, maybe (or can we Reported by: Claude Code?!!):
Assisted-by Claude Code
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 23 lines · Andy Shevchenko
Quoted 22 lines · Nuno Sá
Quoted 20 lines · Jonathan Cameron
Quoted 12 lines · On Sat, 21 Feb 2026 15:27:42 -0600 David Lechner <[email protected]> wrote:
Quoted 9 lines · On 2/16/26 7:24 AM, Nuno Sá via B4 Relay wrote:
From: Nuno Sá <[email protected]>
In the edge case where the IIO device is unregistered while we're buffering, we were directly returning an error without removing the wait queue. Instead, set 'ret' and break out of the loop.
Fixes 9eeee3b0bf19 ("iio: Add output buffer support")Signed-off-by Nuno Sá <[email protected]>---
Reviewed-by David Lechner <[email protected]>This brings the code inline with the near identical flow in the read path.
It's been a while since I last looked at the locking / tear down (what that ->info check is all about). I'll add actually
Quoted 6 lines
Quoted 4 lines
Yeah not sure if you remember but I already said this a couple of times. In the buffer paths I'm not convinced the check we have is enough. Still very open to races AFAICT. I have it in my list to try and trigger and actual issue/dump on that path so it's not just theory. Already asked the bot to write some stressor/test code :).
Perhaps also a good task for stress-ng? Ask Colin!
I would be surprised if there's a stressor for this :). We need to sample (read) an IIO buffer while unbinding the device at the same tim. It might even be that some real issues only pop for some specific HW (which provides different buffer knobs).
- Nuno Sá
Quoted 16 lines
Quoted 16 lines
Quoted 10 lines
documenting all the corner cases to the todo list as IIRC there are some non obvious ordering constraints. IIRC, in the buffer paths, it is fairly straight forward as it's just an optimization to avoid queuing or draining data when the device is going down - nothing about the buffers themselves involves interacting directly with the hardware.
Applied to the fixes-togreg branch of iio.git and marked for stable.
BTW, I just realized we now have an Assisted-by: tag for getting help from AI. I should say that this bug was identified by Claude code (when bulding the stressor test app I mentioned above :)). So, maybe (or can we Reported by: Claude Code?!!):
Assisted-by Claude Code