From 53dabafe1b17411de82b6c4560145cf396cbb564 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Mon, 10 Aug 2015 10:55:08 +0200 Subject: [PATCH] iio: generic_buffer: be helpful about enabling channels Currently if generic_buffer is invoked without first enabling any channels in scan_elements/*_en, it will fail unable to enable the buffer because bytes_per_datum inside the kernel will be zero if no channels are available. It is implied that the user of the program should enable channels manually or with a script before executing generic_buffer. Be more helpful by stopping execution if no enabled channels can be found, and print a helptext that will tell you what is wrong and what needs to be done. Signed-off-by: Linus Walleij Acked-by: Hartmut Knaack Signed-off-by: Jonathan Cameron --- tools/iio/generic_buffer.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c index 9f7b85bf6ada..01c4f67801e0 100644 --- a/tools/iio/generic_buffer.c +++ b/tools/iio/generic_buffer.c @@ -328,6 +328,15 @@ int main(int argc, char **argv) "diag %s\n", dev_dir_name); goto error_free_triggername; } + if (!num_channels) { + fprintf(stderr, + "No channels are enabled, we have nothing to scan.\n"); + fprintf(stderr, "Enable channels manually in " + FORMAT_SCAN_ELEMENTS_DIR + "/*_en and try again.\n", dev_dir_name); + ret = -ENOENT; + goto error_free_triggername; + } /* * Construct the directory name for the associated buffer.