Linux IIO development
 help / color / mirror / Atom feed
From: Marco Chen <marcochen.dev@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Hartmut Knaack" <knaack.h@gmx.de>,
	"Daniel Baluta" <daniel.baluta@intel.com>,
	"Linus Walleij" <linusw@kernel.org>,
	linux-iio@vger.kernel.org, skhan@linuxfoundation.org,
	linux-kernel-mentees@lists.linux.dev
Subject: [PATCH 1/2] tools: iio: iio_generic_buffer: return 0 on success
Date: Fri, 27 Nov 2026 03:57:21 -0500	[thread overview]
Message-ID: <20261127085722.126797-2-marcochen.dev@gmail.com> (raw)
In-Reply-To: <20261127085722.126797-1-marcochen.dev@gmail.com>

A successful buffered capture exits with status 1. As a result, shell
scripts treat this as a failure. This happens because ret still
holds the return value of poll(), which is the number of ready file
descriptors, or in the case with the -e flag set, the return value of
write_sysfs_int().

Set ret to 0 after the capture loop and before the error label. The
read() error path currently breaks out of the loop and would fall
through to that line, so make it set ret to -errno and jump to the error
label instead, just like the poll() error path already does.

Fixes: 6bb7cac8551e ("tools:iio:generic_buffer: add error handling")
Signed-off-by: Marco Chen <marcochen.dev@gmail.com>
---
The read() error path was found by inspection, but I did not actually
run or test this error path explicitly.
Thank you.

 tools/iio/iio_generic_buffer.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/iio/iio_generic_buffer.c b/tools/iio/iio_generic_buffer.c
index fd955cf444ad..122fa54bb74a 100644
--- a/tools/iio/iio_generic_buffer.c
+++ b/tools/iio/iio_generic_buffer.c
@@ -807,7 +807,8 @@ int main(int argc, char **argv)
 				fprintf(stderr, "nothing available\n");
 				continue;
 			} else {
-				break;
+				ret = -errno;
+				goto error;
 			}
 		}
 		for (i = 0; i < read_size / scan_size; i++)
@@ -815,6 +816,7 @@ int main(int argc, char **argv)
 				     num_channels);
 	}
 
+	ret = 0;
 error:
 	cleanup();
 
-- 
2.56.1


  reply	other threads:[~2026-11-27  8:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  8:57 [PATCH 0/2] tools: iio: iio_generic_buffer: fix exit status Marco Chen
2026-11-27  8:57 ` Marco Chen [this message]
2026-11-27  8:57 ` [PATCH 2/2] tools: iio: iio_generic_buffer: return error if no channels can be enabled Marco Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127085722.126797-2-marcochen.dev@gmail.com \
    --to=marcochen.dev@gmail.com \
    --cc=andy@kernel.org \
    --cc=daniel.baluta@intel.com \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=linusw@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=nuno.sa@analog.com \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox