From e8c251b4f40f41685d186f4413781b0eae8e3d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20S=C3=A1?= Date: Wed, 29 Jan 2025 16:42:27 +0000 Subject: [PATCH] utils: iio_rwdev: fix cancelling streaming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we try to cancel the utility with a signal, we'll cancel the buffer (at least on linux) which means we'll likely fail to dequeue a block if we are waiting for one. On top of that the flag 'app_running' is set to false which means that the loop condition '(ret && app_running)' is false and so we do not leave it. This all means that we'll proceed with an invalid block leading to a segfault. Hence, always break the loop if iio_stream_get_next_block() fails (which was the previous behavior) but only log it if the application is running. Signed-off-by: Nuno Sá --- utils/iio_rwdev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/iio_rwdev.c b/utils/iio_rwdev.c index cbea94f33..fec536c57 100644 --- a/utils/iio_rwdev.c +++ b/utils/iio_rwdev.c @@ -459,8 +459,9 @@ int main(int argc, char **argv) block = iio_stream_get_next_block(stream); ret = iio_err(block); - if (ret && app_running) { - dev_perror(dev, ret, "Unable to get next block"); + if (ret) { + if (app_running) + dev_perror(dev, ret, "Unable to get next block"); break; }