* [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
` (2 more replies)
0 siblings, 3 replies; 6+ 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] 6+ 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 2026-11-27 11:36 ` [PATCH 0/2] tools: iio: iio_generic_buffer: fix exit status Arnav Kapoor 2 siblings, 0 replies; 6+ 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] 6+ 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; 6+ 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] 6+ 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; 6+ 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] 6+ messages in thread
[parent not found: <CAAZOf24WuvdmyvpAhZsxafTiscSnjvW8Rt0fZjK9QHkfK8PN9Q@mail.gmail.com>]
* Re: [PATCH 0/2] tools: iio: iio_generic_buffer: fix exit status [not found] ` <CAAZOf24WuvdmyvpAhZsxafTiscSnjvW8Rt0fZjK9QHkfK8PN9Q@mail.gmail.com> @ 2026-11-28 18:44 ` Marco Chen 2026-11-29 1:32 ` Jonathan Cameron 0 siblings, 1 reply; 6+ messages in thread From: Marco Chen @ 2026-11-28 18:44 UTC (permalink / raw) To: David Kahurani Cc: Arnav Kapoor, Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko, Hartmut Knaack, Linus Walleij, linux-iio, Shuah Khan, linux-kernel-mentees On Fri, Nov 27, 2026 at 02:59:37PM +0300, David Kahurani wrote: > On Fri, Nov 27, 2026, 14:39 Arnav Kapoor <kapoorarnav43@gmail.com> wrote: > > > 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. > > > > Not sure about this... But, in a write and possibly read attempt a return > code of zero means no operation was performed. That end of file(EOF), zero > bytes written, zero bytes read etc Thank you Arnav for the review, and thank you David for bringing up your point on the return code of zero. For this series though, I did not change how write_sysfs_int() reports its return value. The value this series changes is only the process's exit status, where 0 indicates success. That is a different convention from the number of bytes written from the return code of a read or write attempt. Returning the write error from enable_disable_all_channels(), as Arnav suggested, would be a good solution to make the non-root case fail earlier with -EACCES. But, as Arnav said, I think that would belong in a separate patch. Thank you both, again. Marco ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] tools: iio: iio_generic_buffer: fix exit status 2026-11-28 18:44 ` Marco Chen @ 2026-11-29 1:32 ` Jonathan Cameron 0 siblings, 0 replies; 6+ messages in thread From: Jonathan Cameron @ 2026-11-29 1:32 UTC (permalink / raw) To: Marco Chen Cc: David Kahurani, Arnav Kapoor, David Lechner, Nuno Sá, Andy Shevchenko, Hartmut Knaack, Linus Walleij, linux-iio, Shuah Khan, linux-kernel-mentees On Sat, 28 Nov 2026 13:44:37 -0500 Marco Chen <marcochen.dev@gmail.com> wrote: > On Fri, Nov 27, 2026 at 02:59:37PM +0300, David Kahurani wrote: > > On Fri, Nov 27, 2026, 14:39 Arnav Kapoor <kapoorarnav43@gmail.com> wrote: > > > > > 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. > > > > > > > Not sure about this... But, in a write and possibly read attempt a return > > code of zero means no operation was performed. That end of file(EOF), zero > > bytes written, zero bytes read etc > > Thank you Arnav for the review, and thank you David for bringing up your > point on the return code of zero. > > For this series though, I did not change how write_sysfs_int() reports > its return value. The value this series changes is only the process's > exit status, where 0 indicates success. That is a different convention > from the number of bytes written from the return code of a read or write > attempt. > > Returning the write error from enable_disable_all_channels(), as Arnav > suggested, would be a good solution to make the non-root case fail > earlier with -EACCES. But, as Arnav said, I think that would belong in a > separate patch. > > Thank you both, again. > Given this is the testing / reference tool and we are fairly late in the cycle I'm not going to rush this in. It has also only been out for a few days but given the deluge of patches at the moment I'm keen to resolve as many as possible quickly. As such applied to the testing branch of iio.git. Thanks, Jonathan > Marco > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-29 1:32 UTC | newest]
Thread overview: 6+ 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
2026-11-27 11:36 ` [PATCH 0/2] tools: iio: iio_generic_buffer: fix exit status Arnav Kapoor
[not found] ` <CAAZOf24WuvdmyvpAhZsxafTiscSnjvW8Rt0fZjK9QHkfK8PN9Q@mail.gmail.com>
2026-11-28 18:44 ` Marco Chen
2026-11-29 1:32 ` Jonathan Cameron
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.