From 7663a4aac625268674060d78ee00f97a36a03af7 Mon Sep 17 00:00:00 2001 From: Hartmut Knaack Date: Wed, 10 Jun 2015 21:51:20 +0200 Subject: tools:iio: adjust coding style Fix various coding style issues, including: * have spaces around operators * indentation * consolidate parameters in same line * required braces * adjust/drop comments * multiline comment style * delete unnecessary empty lines * add empty lines to visualize logial code blocks * typos Signed-off-by: Hartmut Knaack Signed-off-by: Jonathan Cameron --- tools/iio/generic_buffer.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'tools/iio/generic_buffer.c') diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c index 4eebb6616e5c..fc362d2ff983 100644 --- a/tools/iio/generic_buffer.c +++ b/tools/iio/generic_buffer.c @@ -51,11 +51,13 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels) if (bytes % channels[i].bytes == 0) channels[i].location = bytes; else - channels[i].location = bytes - bytes%channels[i].bytes - + channels[i].bytes; + channels[i].location = bytes - bytes % channels[i].bytes + + channels[i].bytes; + bytes = channels[i].location + channels[i].bytes; i++; } + return bytes; } @@ -136,9 +138,9 @@ void print8byte(uint64_t input, struct iio_channel_info *info) /** * process_scan() - print out the values in SI units * @data: pointer to the start of the scan - * @channels: information about the channels. Note - * size_from_channelarray must have been called first to fill the - * location offsets. + * @channels: information about the channels. + * Note: size_from_channelarray must have been called first + * to fill the location offsets. * @num_channels: number of channels **/ void process_scan(char *data, @@ -213,6 +215,7 @@ int main(int argc, char **argv) num_loops = strtoul(optarg, &dummy, 10); if (errno) return -errno; + break; case 'e': noevents = 1; @@ -225,6 +228,7 @@ int main(int argc, char **argv) buf_len = strtoul(optarg, &dummy, 10); if (errno) return -errno; + break; case 'n': device_name = optarg; @@ -257,6 +261,7 @@ int main(int argc, char **argv) printf("Failed to find the %s\n", device_name); return dev_num; } + printf("iio device number being used is %d\n", dev_num); ret = asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); @@ -285,9 +290,11 @@ int main(int argc, char **argv) ret = trig_num; goto error_free_triggername; } + printf("iio trigger number being used is %d\n", trig_num); - } else + } else { printf("trigger-less mode selected\n"); + } /* * Parse the files in scan_elements to identify what channels are @@ -314,8 +321,10 @@ int main(int argc, char **argv) if (!notrigger) { printf("%s %s\n", dev_dir_name, trigger_name); - /* Set the device trigger to be the data ready trigger found - * above */ + /* + * Set the device trigger to be the data ready trigger found + * above + */ ret = write_sysfs_string_and_verify("trigger/current_trigger", dev_dir_name, trigger_name); @@ -334,8 +343,9 @@ int main(int argc, char **argv) ret = write_sysfs_int("enable", buf_dir_name, 1); if (ret < 0) goto error_free_buf_dir_name; + scan_size = size_from_channelarray(channels, num_channels); - data = malloc(scan_size*buf_len); + data = malloc(scan_size * buf_len); if (!data) { ret = -ENOMEM; goto error_free_buf_dir_name; @@ -349,13 +359,12 @@ int main(int argc, char **argv) /* Attempt to open non blocking the access dev */ fp = open(buffer_access, O_RDONLY | O_NONBLOCK); - if (fp == -1) { /* If it isn't there make the node */ + if (fp == -1) { /* TODO: If it isn't there make the node */ ret = -errno; printf("Failed to open %s\n", buffer_access); goto error_free_buffer_access; } - /* Wait for events 10 times */ for (j = 0; j < num_loops; j++) { if (!noevents) { struct pollfd pfd = { @@ -372,25 +381,22 @@ int main(int argc, char **argv) } toread = buf_len; - } else { usleep(timedelay); toread = 64; } - read_size = read(fp, - data, - toread*scan_size); + read_size = read(fp, data, toread * scan_size); if (read_size < 0) { if (errno == EAGAIN) { printf("nothing available\n"); continue; - } else + } else { break; + } } - for (i = 0; i < read_size/scan_size; i++) - process_scan(data + scan_size*i, - channels, + for (i = 0; i < read_size / scan_size; i++) + process_scan(data + scan_size * i, channels, num_channels); } @@ -409,6 +415,7 @@ int main(int argc, char **argv) error_close_buffer_access: if (close(fp) == -1) perror("Failed to close buffer"); + error_free_buffer_access: free(buffer_access); error_free_data: @@ -424,6 +431,7 @@ error_free_channels: error_free_triggername: if (datardytrigger) free(trigger_name); + error_free_dev_dir_name: free(dev_dir_name); -- cgit v1.2.3-70-g09d2 From e8d0927a19f11cebc4381f5f0cac8fa37154b08a Mon Sep 17 00:00:00 2001 From: Tiberiu Breana Date: Fri, 3 Jul 2015 12:57:36 +0300 Subject: tools: iio: Add single-byte case for generic_buffer Some sensors export data in an 8-bit format. Add a single-byte case for the generic_buffer tool so that these sensors' buffer data can be visualized. Signed-off-by: Tiberiu Breana Reviewed-by: Hartmut Knaack Signed-off-by: Jonathan Cameron --- tools/iio/generic_buffer.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tools/iio/generic_buffer.c') diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c index fc362d2ff983..0e737238ca74 100644 --- a/tools/iio/generic_buffer.c +++ b/tools/iio/generic_buffer.c @@ -61,6 +61,23 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels) return bytes; } +void print1byte(uint8_t input, struct iio_channel_info *info) +{ + /* + * Shift before conversion to avoid sign extension + * of left aligned data + */ + input >>= info->shift; + input &= info->mask; + if (info->is_signed) { + int8_t val = (int8_t)(input << (8 - info->bits_used)) >> + (8 - info->bits_used); + printf("%05f ", ((float)val + info->offset) * info->scale); + } else { + printf("%05f ", ((float)input + info->offset) * info->scale); + } +} + void print2byte(uint16_t input, struct iio_channel_info *info) { /* First swap if incorrect endian */ @@ -152,6 +169,10 @@ void process_scan(char *data, for (k = 0; k < num_channels; k++) switch (channels[k].bytes) { /* only a few cases implemented so far */ + case 1: + print1byte(*(uint8_t *)(data + channels[k].location), + &channels[k]); + break; case 2: print2byte(*(uint16_t *)(data + channels[k].location), &channels[k]); -- cgit v1.2.3-70-g09d2 From ff1ac639b395d58bbd99ff4a36b10eebb81544a3 Mon Sep 17 00:00:00 2001 From: Cristina Opriceana Date: Mon, 13 Jul 2015 16:15:56 +0300 Subject: tools: iio: Remove explicit NULL comparison Remove explicit NULL comparison and write it in its simpler form as recommended by checkpatch.pl. Signed-off-by: Cristina Opriceana Reviewed-by: Hartmut Knaack Signed-off-by: Jonathan Cameron --- tools/iio/generic_buffer.c | 4 ++-- tools/iio/iio_utils.c | 56 +++++++++++++++++++++++----------------------- tools/iio/lsiio.c | 10 ++++----- 3 files changed, 35 insertions(+), 35 deletions(-) (limited to 'tools/iio/generic_buffer.c') diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c index 0e737238ca74..9535c2dc25af 100644 --- a/tools/iio/generic_buffer.c +++ b/tools/iio/generic_buffer.c @@ -270,7 +270,7 @@ int main(int argc, char **argv) } } - if (device_name == NULL) { + if (!device_name) { printf("Device name not set\n"); print_usage(); return -1; @@ -290,7 +290,7 @@ int main(int argc, char **argv) return -ENOMEM; if (!notrigger) { - if (trigger_name == NULL) { + if (!trigger_name) { /* * Build the trigger name. If it is device associated * its name is _dev[n] where n matches diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c index 8fb3214c70f2..4a7e4801cebf 100644 --- a/tools/iio/iio_utils.c +++ b/tools/iio/iio_utils.c @@ -117,13 +117,13 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used, } dp = opendir(scan_el_dir); - if (dp == NULL) { + if (!dp) { ret = -errno; goto error_free_builtname_generic; } ret = -ENOENT; - while (ent = readdir(dp), ent != NULL) + while (ent = readdir(dp), ent) /* * Do we allow devices to override a generic name with * a specific one? @@ -138,7 +138,7 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used, } sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { + if (!sysfsfp) { ret = -errno; printf("failed to open %s\n", filename); goto error_free_filename; @@ -235,13 +235,13 @@ int iioutils_get_param_float(float *output, const char *param_name, } dp = opendir(device_dir); - if (dp == NULL) { + if (!dp) { ret = -errno; goto error_free_builtname_generic; } ret = -ENOENT; - while (ent = readdir(dp), ent != NULL) + while (ent = readdir(dp), ent) if ((strcmp(builtname, ent->d_name) == 0) || (strcmp(builtname_generic, ent->d_name) == 0)) { ret = asprintf(&filename, @@ -325,12 +325,12 @@ int build_channel_array(const char *device_dir, return -ENOMEM; dp = opendir(scan_el_dir); - if (dp == NULL) { + if (!dp) { ret = -errno; goto error_free_name; } - while (ent = readdir(dp), ent != NULL) + while (ent = readdir(dp), ent) if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), "_en") == 0) { ret = asprintf(&filename, @@ -341,7 +341,7 @@ int build_channel_array(const char *device_dir, } sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { + if (!sysfsfp) { ret = -errno; free(filename); goto error_close_dir; @@ -369,13 +369,13 @@ int build_channel_array(const char *device_dir, } *ci_array = malloc(sizeof(**ci_array) * (*counter)); - if (*ci_array == NULL) { + if (!*ci_array) { ret = -ENOMEM; goto error_close_dir; } seekdir(dp, 0); - while (ent = readdir(dp), ent != NULL) { + while (ent = readdir(dp), ent) { if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), "_en") == 0) { int current_enabled = 0; @@ -391,7 +391,7 @@ int build_channel_array(const char *device_dir, } sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { + if (!sysfsfp) { ret = -errno; free(filename); count--; @@ -424,7 +424,7 @@ int build_channel_array(const char *device_dir, current->name = strndup(ent->d_name, strlen(ent->d_name) - strlen("_en")); - if (current->name == NULL) { + if (!current->name) { free(filename); ret = -ENOMEM; count--; @@ -452,7 +452,7 @@ int build_channel_array(const char *device_dir, } sysfsfp = fopen(filename, "r"); - if (sysfsfp == NULL) { + if (!sysfsfp) { ret = -errno; printf("failed to open %s\n", filename); free(filename); @@ -567,12 +567,12 @@ int find_type_by_name(const char *name, const char *type) char *filename; dp = opendir(iio_dir); - if (dp == NULL) { + if (!dp) { printf("No industrialio devices available\n"); return -ENODEV; } - while (ent = readdir(dp), ent != NULL) { + while (ent = readdir(dp), ent) { if (strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0 && strlen(ent->d_name) > strlen(type) && @@ -595,7 +595,7 @@ int find_type_by_name(const char *name, const char *type) ":", 1) != 0) { filename = malloc(strlen(iio_dir) + strlen(type) + numstrlen + 6); - if (filename == NULL) { + if (!filename) { ret = -ENOMEM; goto error_close_dir; } @@ -654,7 +654,7 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val, int test; char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) + if (!temp) return -ENOMEM; ret = sprintf(temp, "%s/%s", basedir, filename); @@ -662,7 +662,7 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val, goto error_free; sysfsfp = fopen(temp, "w"); - if (sysfsfp == NULL) { + if (!sysfsfp) { ret = -errno; printf("failed to open %s\n", temp); goto error_free; @@ -683,7 +683,7 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val, if (verify) { sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { + if (!sysfsfp) { ret = -errno; printf("failed to open %s\n", temp); goto error_free; @@ -749,7 +749,7 @@ static int _write_sysfs_string(const char *filename, const char *basedir, FILE *sysfsfp; char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { + if (!temp) { printf("Memory allocation failed\n"); return -ENOMEM; } @@ -759,7 +759,7 @@ static int _write_sysfs_string(const char *filename, const char *basedir, goto error_free; sysfsfp = fopen(temp, "w"); - if (sysfsfp == NULL) { + if (!sysfsfp) { ret = -errno; printf("Could not open %s\n", temp); goto error_free; @@ -780,7 +780,7 @@ static int _write_sysfs_string(const char *filename, const char *basedir, if (verify) { sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { + if (!sysfsfp) { ret = -errno; printf("Could not open file to verify\n"); goto error_free; @@ -855,7 +855,7 @@ int read_sysfs_posint(const char *filename, const char *basedir) FILE *sysfsfp; char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { + if (!temp) { printf("Memory allocation failed"); return -ENOMEM; } @@ -865,7 +865,7 @@ int read_sysfs_posint(const char *filename, const char *basedir) goto error_free; sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { + if (!sysfsfp) { ret = -errno; goto error_free; } @@ -902,7 +902,7 @@ int read_sysfs_float(const char *filename, const char *basedir, float *val) FILE *sysfsfp; char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { + if (!temp) { printf("Memory allocation failed"); return -ENOMEM; } @@ -912,7 +912,7 @@ int read_sysfs_float(const char *filename, const char *basedir, float *val) goto error_free; sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { + if (!sysfsfp) { ret = -errno; goto error_free; } @@ -949,7 +949,7 @@ int read_sysfs_string(const char *filename, const char *basedir, char *str) FILE *sysfsfp; char *temp = malloc(strlen(basedir) + strlen(filename) + 2); - if (temp == NULL) { + if (!temp) { printf("Memory allocation failed"); return -ENOMEM; } @@ -959,7 +959,7 @@ int read_sysfs_string(const char *filename, const char *basedir, char *str) goto error_free; sysfsfp = fopen(temp, "r"); - if (sysfsfp == NULL) { + if (!sysfsfp) { ret = -errno; goto error_free; } diff --git a/tools/iio/lsiio.c b/tools/iio/lsiio.c index 7f432a55a6c4..4f8172fe7881 100644 --- a/tools/iio/lsiio.c +++ b/tools/iio/lsiio.c @@ -46,10 +46,10 @@ static int dump_channels(const char *dev_dir_name) const struct dirent *ent; dp = opendir(dev_dir_name); - if (dp == NULL) + if (!dp) return -errno; - while (ent = readdir(dp), ent != NULL) + while (ent = readdir(dp), ent) if (check_prefix(ent->d_name, "in_") && check_postfix(ent->d_name, "_raw")) printf(" %-10s\n", ent->d_name); @@ -107,12 +107,12 @@ static int dump_devices(void) DIR *dp; dp = opendir(iio_dir); - if (dp == NULL) { + if (!dp) { printf("No industrial I/O devices available\n"); return -ENODEV; } - while (ent = readdir(dp), ent != NULL) { + while (ent = readdir(dp), ent) { if (check_prefix(ent->d_name, type_device)) { char *dev_dir_name; @@ -134,7 +134,7 @@ static int dump_devices(void) } } rewinddir(dp); - while (ent = readdir(dp), ent != NULL) { + while (ent = readdir(dp), ent) { if (check_prefix(ent->d_name, type_trigger)) { char *dev_dir_name; -- cgit v1.2.3-70-g09d2 From d9abc615ea1659b6967a00e95b1b3a7fd4079b80 Mon Sep 17 00:00:00 2001 From: Cristina Opriceana Date: Fri, 17 Jul 2015 18:43:42 +0300 Subject: tools: iio: Send error messages to stderr This patch indends to make some cleanup and send printf error messages to stderr. The changes were performed with coccinelle for failure messages and manual for other cases, such as wrong usage messages. Signed-off-by: Cristina Opriceana Reviewed-by: Hartmut Knaack Signed-off-by: Jonathan Cameron --- tools/iio/generic_buffer.c | 39 ++++++++++++++++++--------------- tools/iio/iio_event_monitor.c | 14 ++++++------ tools/iio/iio_utils.c | 51 +++++++++++++++++++++++++------------------ tools/iio/lsiio.c | 2 +- 4 files changed, 59 insertions(+), 47 deletions(-) (limited to 'tools/iio/generic_buffer.c') diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c index 9535c2dc25af..32f389ebb94d 100644 --- a/tools/iio/generic_buffer.c +++ b/tools/iio/generic_buffer.c @@ -193,15 +193,15 @@ void process_scan(char *data, void print_usage(void) { - printf("Usage: generic_buffer [options]...\n" - "Capture, convert and output data from IIO device buffer\n" - " -c Do n conversions\n" - " -e Disable wait for event (new data)\n" - " -g Use trigger-less mode\n" - " -l Set buffer length to n samples\n" - " -n Set device name (mandatory)\n" - " -t Set trigger name\n" - " -w Set delay between reads in us (event-less mode)\n"); + fprintf(stderr, "Usage: generic_buffer [options]...\n" + "Capture, convert and output data from IIO device buffer\n" + " -c Do n conversions\n" + " -e Disable wait for event (new data)\n" + " -g Use trigger-less mode\n" + " -l Set buffer length to n samples\n" + " -n Set device name (mandatory)\n" + " -t Set trigger name\n" + " -w Set delay between reads in us (event-less mode)\n"); } int main(int argc, char **argv) @@ -271,7 +271,7 @@ int main(int argc, char **argv) } if (!device_name) { - printf("Device name not set\n"); + fprintf(stderr, "Device name not set\n"); print_usage(); return -1; } @@ -279,7 +279,7 @@ int main(int argc, char **argv) /* Find the device requested */ dev_num = find_type_by_name(device_name, "iio:device"); if (dev_num < 0) { - printf("Failed to find the %s\n", device_name); + fprintf(stderr, "Failed to find the %s\n", device_name); return dev_num; } @@ -307,7 +307,8 @@ int main(int argc, char **argv) /* Verify the trigger exists */ trig_num = find_type_by_name(trigger_name, "trigger"); if (trig_num < 0) { - printf("Failed to find the trigger %s\n", trigger_name); + fprintf(stderr, "Failed to find the trigger %s\n", + trigger_name); ret = trig_num; goto error_free_triggername; } @@ -323,8 +324,8 @@ int main(int argc, char **argv) */ ret = build_channel_array(dev_dir_name, &channels, &num_channels); if (ret) { - printf("Problem reading scan element information\n"); - printf("diag %s\n", dev_dir_name); + fprintf(stderr, "Problem reading scan element information\n" + "diag %s\n", dev_dir_name); goto error_free_triggername; } @@ -350,7 +351,8 @@ int main(int argc, char **argv) dev_dir_name, trigger_name); if (ret < 0) { - printf("Failed to write current_trigger file\n"); + fprintf(stderr, + "Failed to write current_trigger file\n"); goto error_free_buf_dir_name; } } @@ -382,7 +384,7 @@ int main(int argc, char **argv) fp = open(buffer_access, O_RDONLY | O_NONBLOCK); if (fp == -1) { /* TODO: If it isn't there make the node */ ret = -errno; - printf("Failed to open %s\n", buffer_access); + fprintf(stderr, "Failed to open %s\n", buffer_access); goto error_free_buffer_access; } @@ -410,7 +412,7 @@ int main(int argc, char **argv) read_size = read(fp, data, toread * scan_size); if (read_size < 0) { if (errno == EAGAIN) { - printf("nothing available\n"); + fprintf(stderr, "nothing available\n"); continue; } else { break; @@ -431,7 +433,8 @@ int main(int argc, char **argv) ret = write_sysfs_string("trigger/current_trigger", dev_dir_name, "NULL"); if (ret < 0) - printf("Failed to write to %s\n", dev_dir_name); + fprintf(stderr, "Failed to write to %s\n", + dev_dir_name); error_close_buffer_access: if (close(fp) == -1) diff --git a/tools/iio/iio_event_monitor.c b/tools/iio/iio_event_monitor.c index 9ee195949a4a..cd3fd41b481d 100644 --- a/tools/iio/iio_event_monitor.c +++ b/tools/iio/iio_event_monitor.c @@ -215,8 +215,8 @@ static void print_event(struct iio_event_data *event) bool diff = IIO_EVENT_CODE_EXTRACT_DIFF(event->id); if (!event_is_known(event)) { - printf("Unknown event: time: %lld, id: %llx\n", - event->timestamp, event->id); + fprintf(stderr, "Unknown event: time: %lld, id: %llx\n", + event->timestamp, event->id); return; } @@ -251,7 +251,7 @@ int main(int argc, char **argv) int fd, event_fd; if (argc <= 1) { - printf("Usage: %s \n", argv[0]); + fprintf(stderr, "Usage: %s \n", argv[0]); return -1; } @@ -277,14 +277,14 @@ int main(int argc, char **argv) fd = open(chrdev_name, 0); if (fd == -1) { ret = -errno; - fprintf(stdout, "Failed to open %s\n", chrdev_name); + fprintf(stderr, "Failed to open %s\n", chrdev_name); goto error_free_chrdev_name; } ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd); if (ret == -1 || event_fd == -1) { ret = -errno; - fprintf(stdout, "Failed to retrieve event fd\n"); + fprintf(stderr, "Failed to retrieve event fd\n"); if (close(fd) == -1) perror("Failed to close character device file"); @@ -300,7 +300,7 @@ int main(int argc, char **argv) ret = read(event_fd, &event, sizeof(event)); if (ret == -1) { if (errno == EAGAIN) { - printf("nothing available\n"); + fprintf(stderr, "nothing available\n"); continue; } else { ret = -errno; @@ -310,7 +310,7 @@ int main(int argc, char **argv) } if (ret != sizeof(event)) { - printf("Reading event failed!\n"); + fprintf(stderr, "Reading event failed!\n"); ret = -EIO; break; } diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c index e177f4022d40..c3f9e37333e7 100644 --- a/tools/iio/iio_utils.c +++ b/tools/iio/iio_utils.c @@ -140,7 +140,8 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used, sysfsfp = fopen(filename, "r"); if (!sysfsfp) { ret = -errno; - printf("failed to open %s\n", filename); + fprintf(stderr, "failed to open %s\n", + filename); goto error_free_filename; } @@ -152,11 +153,13 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used, &padint, shift); if (ret < 0) { ret = -errno; - printf("failed to pass scan type description\n"); + fprintf(stderr, + "failed to pass scan type description\n"); goto error_close_sysfsfp; } else if (ret != 5) { ret = -EIO; - printf("scan type description didn't match\n"); + fprintf(stderr, + "scan type description didn't match\n"); goto error_close_sysfsfp; } @@ -170,7 +173,8 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used, *is_signed = (signchar == 's'); if (fclose(sysfsfp)) { ret = -errno; - printf("Failed to close %s\n", filename); + fprintf(stderr, "Failed to close %s\n", + filename); goto error_free_filename; } @@ -454,7 +458,8 @@ int build_channel_array(const char *device_dir, sysfsfp = fopen(filename, "r"); if (!sysfsfp) { ret = -errno; - printf("failed to open %s\n", filename); + fprintf(stderr, "failed to open %s\n", + filename); free(filename); goto error_cleanup_array; } @@ -568,7 +573,7 @@ int find_type_by_name(const char *name, const char *type) dp = opendir(iio_dir); if (!dp) { - printf("No industrialio devices available\n"); + fprintf(stderr, "No industrialio devices available\n"); return -ENODEV; } @@ -581,11 +586,13 @@ int find_type_by_name(const char *name, const char *type) ret = sscanf(ent->d_name + strlen(type), "%d", &number); if (ret < 0) { ret = -errno; - printf("failed to read element number\n"); + fprintf(stderr, + "failed to read element number\n"); goto error_close_dir; } else if (ret != 1) { ret = -EIO; - printf("failed to match element number\n"); + fprintf(stderr, + "failed to match element number\n"); goto error_close_dir; } @@ -664,7 +671,7 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val, sysfsfp = fopen(temp, "w"); if (!sysfsfp) { ret = -errno; - printf("failed to open %s\n", temp); + fprintf(stderr, "failed to open %s\n", temp); goto error_free; } @@ -685,7 +692,7 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val, sysfsfp = fopen(temp, "r"); if (!sysfsfp) { ret = -errno; - printf("failed to open %s\n", temp); + fprintf(stderr, "failed to open %s\n", temp); goto error_free; } @@ -703,8 +710,9 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val, } if (test != val) { - printf("Possible failure in int write %d to %s/%s\n", - val, basedir, filename); + fprintf(stderr, + "Possible failure in int write %d to %s/%s\n", + val, basedir, filename); ret = -1; } } @@ -750,7 +758,7 @@ static int _write_sysfs_string(const char *filename, const char *basedir, char *temp = malloc(strlen(basedir) + strlen(filename) + 2); if (!temp) { - printf("Memory allocation failed\n"); + fprintf(stderr, "Memory allocation failed\n"); return -ENOMEM; } @@ -761,7 +769,7 @@ static int _write_sysfs_string(const char *filename, const char *basedir, sysfsfp = fopen(temp, "w"); if (!sysfsfp) { ret = -errno; - printf("Could not open %s\n", temp); + fprintf(stderr, "Could not open %s\n", temp); goto error_free; } @@ -782,7 +790,7 @@ static int _write_sysfs_string(const char *filename, const char *basedir, sysfsfp = fopen(temp, "r"); if (!sysfsfp) { ret = -errno; - printf("Could not open file to verify\n"); + fprintf(stderr, "Could not open file to verify\n"); goto error_free; } @@ -800,9 +808,10 @@ static int _write_sysfs_string(const char *filename, const char *basedir, } if (strcmp(temp, val) != 0) { - printf("Possible failure in string write of %s " - "Should be %s written to %s/%s\n", temp, val, - basedir, filename); + fprintf(stderr, + "Possible failure in string write of %s " + "Should be %s written to %s/%s\n", temp, val, + basedir, filename); ret = -1; } } @@ -856,7 +865,7 @@ int read_sysfs_posint(const char *filename, const char *basedir) char *temp = malloc(strlen(basedir) + strlen(filename) + 2); if (!temp) { - printf("Memory allocation failed"); + fprintf(stderr, "Memory allocation failed"); return -ENOMEM; } @@ -903,7 +912,7 @@ int read_sysfs_float(const char *filename, const char *basedir, float *val) char *temp = malloc(strlen(basedir) + strlen(filename) + 2); if (!temp) { - printf("Memory allocation failed"); + fprintf(stderr, "Memory allocation failed"); return -ENOMEM; } @@ -950,7 +959,7 @@ int read_sysfs_string(const char *filename, const char *basedir, char *str) char *temp = malloc(strlen(basedir) + strlen(filename) + 2); if (!temp) { - printf("Memory allocation failed"); + fprintf(stderr, "Memory allocation failed"); return -ENOMEM; } diff --git a/tools/iio/lsiio.c b/tools/iio/lsiio.c index 4f8172fe7881..b271a9a796d2 100644 --- a/tools/iio/lsiio.c +++ b/tools/iio/lsiio.c @@ -108,7 +108,7 @@ static int dump_devices(void) dp = opendir(iio_dir); if (!dp) { - printf("No industrial I/O devices available\n"); + fprintf(stderr, "No industrial I/O devices available\n"); return -ENODEV; } -- cgit v1.2.3-70-g09d2 From e7231491ce6ae2053569166f60835a5594b3c0af Mon Sep 17 00:00:00 2001 From: Irina Tirdea Date: Fri, 24 Jul 2015 16:28:06 +0300 Subject: tools: iio: print error message when buffer enable fails Running generic_buffer without enabling any channel of the sensor will fail without printing any error message. Add an error message that indicates buffer enable failed. Signed-off-by: Irina Tirdea Acked-by: Hartmut Knaack Signed-off-by: Jonathan Cameron --- tools/iio/generic_buffer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tools/iio/generic_buffer.c') diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c index 32f389ebb94d..9f7b85bf6ada 100644 --- a/tools/iio/generic_buffer.c +++ b/tools/iio/generic_buffer.c @@ -364,8 +364,11 @@ int main(int argc, char **argv) /* Enable the buffer */ ret = write_sysfs_int("enable", buf_dir_name, 1); - if (ret < 0) + if (ret < 0) { + fprintf(stderr, + "Failed to enable buffer: %s\n", strerror(-ret)); goto error_free_buf_dir_name; + } scan_size = size_from_channelarray(channels, num_channels); data = malloc(scan_size * buf_len); -- cgit v1.2.3-70-g09d2