* [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
2026-11-27 11:36 ` [PATCH 0/2] tools: iio: iio_generic_buffer: fix exit status Arnav Kapoor
2 siblings, 0 replies; 5+ 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] 5+ 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
2026-11-27 11:36 ` [PATCH 0/2] tools: iio: iio_generic_buffer: fix exit status Arnav Kapoor
2 siblings, 0 replies; 5+ 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] 5+ messages in thread* Re: [PATCH 0/2] tools: iio: iio_generic_buffer: fix exit status
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
@ 2026-11-27 11:36 ` Arnav Kapoor
[not found] ` <CAAZOf24WuvdmyvpAhZsxafTiscSnjvW8Rt0fZjK9QHkfK8PN9Q@mail.gmail.com>
2 siblings, 1 reply; 5+ messages in thread
From: Arnav Kapoor @ 2026-11-27 11:36 UTC (permalink / raw)
To: Marco Chen
Cc: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Hartmut Knaack, Daniel Baluta, Linus Walleij, linux-iio, skhan,
linux-kernel-mentees
On Fri, Nov 27, 2026 at 03:57:20AM -0500, Marco Chen wrote:
> This series fixes a wrong exit status in two cases for
> iio_generic_buffer.
Both look right to me. For 1/2, the exit status of 1 with -e comes from
write_sysfs_int("enable", ..., 1): without verify it returns the
fprintf() count, which is 1 for "1". Without -e it is poll()'s return
value, so resetting ret before the error label covers both, and the
read() error path now matches the poll() one.
For 2/2, -ENOENT is fine, it matches the "No channels are enabled" path
right below.
The reason you get that far as non-root, though, is that
enable_disable_all_channels() ignores failed writes: it stores the
write_sysfs_int() result in ret, only prints a message, and always
returns 0 (the ret = -ENOENT at the top is never used either). So the
"Failed to enable all channels" check in main() can't fire for a write
failure. Returning the error from there, as a separate patch, would
make the non-root case fail earlier with -EACCES. Your 2/2 is still
useful as a safety net.
Both apply to iio testing, build cleanly and are checkpatch --strict
clean.
For the series:
Reviewed-by: Arnav Kapoor <kapoorarnav43@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread