* [PATCH 0/2] tools: iio: iio_generic_buffer: fix exit status
@ 2026-11-27 8:57 Marco Chen
2026-11-27 8:57 ` [PATCH 1/2] tools: iio: iio_generic_buffer: return 0 on success Marco Chen
2026-11-27 8:57 ` [PATCH 2/2] tools: iio: iio_generic_buffer: return error if no channels can be enabled Marco Chen
0 siblings, 2 replies; 3+ messages in thread
From: Marco Chen @ 2026-11-27 8:57 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Hartmut Knaack,
Daniel Baluta, Linus Walleij, linux-iio, skhan,
linux-kernel-mentees
This series fixes a wrong exit status in two cases for
iio_generic_buffer. These issues were found during the process of
using iio_generic_buffer in a bash shell script while testing
buffered reads with the max30102 pulse oximeter.
All patches were tested on a Raspberry Pi 4 running the IIO
subsystem tree testing branch with the max30102.
For patch 1, a normal buffered capture exited with 1 before and
0 after, with and without the -e flag.
For patch 2, running iio_generic_buffer as a non-root user exited
with 0 before and 254 (-ENOENT) after.
Marco Chen (2):
tools: iio: iio_generic_buffer: return 0 on success
tools: iio: iio_generic_buffer: return error if no channels can be
enabled
tools/iio/iio_generic_buffer.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
base-commit: 39508411b82d4dc29dd245bb471ec9ecc1111c9d
--
2.56.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] tools: iio: iio_generic_buffer: return 0 on success
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
2026-11-27 8:57 ` [PATCH 2/2] tools: iio: iio_generic_buffer: return error if no channels can be enabled Marco Chen
1 sibling, 0 replies; 3+ messages in thread
From: Marco Chen @ 2026-11-27 8:57 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Hartmut Knaack,
Daniel Baluta, Linus Walleij, linux-iio, skhan,
linux-kernel-mentees
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] tools: iio: iio_generic_buffer: return error if no channels can be enabled
2026-11-27 8:57 [PATCH 0/2] tools: iio: iio_generic_buffer: fix exit status Marco Chen
2026-11-27 8:57 ` [PATCH 1/2] tools: iio: iio_generic_buffer: return 0 on success Marco Chen
@ 2026-11-27 8:57 ` Marco Chen
1 sibling, 0 replies; 3+ messages in thread
From: Marco Chen @ 2026-11-27 8:57 UTC (permalink / raw)
To: Jonathan Cameron
Cc: David Lechner, Nuno Sá, Andy Shevchenko, Hartmut Knaack,
Daniel Baluta, Linus Walleij, linux-iio, skhan,
linux-kernel-mentees
If no channels end up being enabled when using the -a flag,
iio_generic_buffer prints "Still no channels after auto-enabling, giving
up". However, it exits with status 0 because ret still holds 0 from
the preceding build_channel_array() call, so callers see success even
though no data was captured. This happens, for example, when
iio_generic_buffer runs without permission to write to the scan element
enable files.
Set ret=-ENOENT before jumping to the error label. This fix matches the
"No channels are enabled" error directly below, which already returns
-ENOENT.
Fixes: 5f991a921a08 ("iio: tools: generic_buffer: auto-enable channels")
Signed-off-by: Marco Chen <marcochen.dev@gmail.com>
---
I used -ENOENT to match the existing "No channels are enabled" path,
but I am not 100% sure if this is the right error code to return here.
I would be glad to hear your input on this.
Thank you.
tools/iio/iio_generic_buffer.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/iio/iio_generic_buffer.c b/tools/iio/iio_generic_buffer.c
index 122fa54bb74a..974548150eb1 100644
--- a/tools/iio/iio_generic_buffer.c
+++ b/tools/iio/iio_generic_buffer.c
@@ -643,6 +643,7 @@ int main(int argc, char **argv)
if (!num_channels) {
fprintf(stderr, "Still no channels after "
"auto-enabling, giving up\n");
+ ret = -ENOENT;
goto error;
}
}
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-27 8:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 8:57 [PATCH 0/2] tools: iio: iio_generic_buffer: fix exit status Marco Chen
2026-11-27 8:57 ` [PATCH 1/2] tools: iio: iio_generic_buffer: return 0 on success Marco Chen
2026-11-27 8:57 ` [PATCH 2/2] tools: iio: iio_generic_buffer: return error if no channels can be enabled Marco Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox