summaryrefslogtreecommitdiffstats
path: root/tools/iio
diff options
context:
space:
mode:
authorHartmut Knaack <knaack.h@gmx.de>2015-05-31 08:39:48 -0400
committerJonathan Cameron <jic23@kernel.org>2015-05-31 12:32:44 -0400
commit2b6a6e67af6f8f644a48f75efc1f44544c0d74f6 (patch)
treeffff341e8cdb92e06abd46628219495c5c2e7066 /tools/iio
parentf96d055e4b38c64123f211f0521f834d649cd01c (diff)
tools:iio: save errno first
The man-page of errno states, that errno should be saved before doing any library call, as that call may have changed the value of errno. So, when encountering any error, save errno first. This patch affects generic_buffer.c, iio_event_monitor.c and iio_utils.c. Signed-off-by: Hartmut Knaack <knaack.h@gmx.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'tools/iio')
-rw-r--r--tools/iio/generic_buffer.c2
-rw-r--r--tools/iio/iio_event_monitor.c6
-rw-r--r--tools/iio/iio_utils.c14
3 files changed, 11 insertions, 11 deletions
diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
index 0410948e23c2..7635aeb93dc8 100644
--- a/tools/iio/generic_buffer.c
+++ b/tools/iio/generic_buffer.c
@@ -296,8 +296,8 @@ int main(int argc, char **argv)
296 /* Attempt to open non blocking the access dev */ 296 /* Attempt to open non blocking the access dev */
297 fp = open(buffer_access, O_RDONLY | O_NONBLOCK); 297 fp = open(buffer_access, O_RDONLY | O_NONBLOCK);
298 if (fp == -1) { /* If it isn't there make the node */ 298 if (fp == -1) { /* If it isn't there make the node */
299 printf("Failed to open %s\n", buffer_access);
300 ret = -errno; 299 ret = -errno;
300 printf("Failed to open %s\n", buffer_access);
301 goto error_free_buffer_access; 301 goto error_free_buffer_access;
302 } 302 }
303 303
diff --git a/tools/iio/iio_event_monitor.c b/tools/iio/iio_event_monitor.c
index 427c271ac0d6..f6fdab48d340 100644
--- a/tools/iio/iio_event_monitor.c
+++ b/tools/iio/iio_event_monitor.c
@@ -269,8 +269,8 @@ int main(int argc, char **argv)
269 269
270 fd = open(chrdev_name, 0); 270 fd = open(chrdev_name, 0);
271 if (fd == -1) { 271 if (fd == -1) {
272 fprintf(stdout, "Failed to open %s\n", chrdev_name);
273 ret = -errno; 272 ret = -errno;
273 fprintf(stdout, "Failed to open %s\n", chrdev_name);
274 goto error_free_chrdev_name; 274 goto error_free_chrdev_name;
275 } 275 }
276 276
@@ -279,8 +279,8 @@ int main(int argc, char **argv)
279 close(fd); 279 close(fd);
280 280
281 if (ret == -1 || event_fd == -1) { 281 if (ret == -1 || event_fd == -1) {
282 fprintf(stdout, "Failed to retrieve event fd\n");
283 ret = -errno; 282 ret = -errno;
283 fprintf(stdout, "Failed to retrieve event fd\n");
284 goto error_free_chrdev_name; 284 goto error_free_chrdev_name;
285 } 285 }
286 286
@@ -291,8 +291,8 @@ int main(int argc, char **argv)
291 printf("nothing available\n"); 291 printf("nothing available\n");
292 continue; 292 continue;
293 } else { 293 } else {
294 perror("Failed to read event from device");
295 ret = -errno; 294 ret = -errno;
295 perror("Failed to read event from device");
296 break; 296 break;
297 } 297 }
298 } 298 }
diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
index 1c0ca2f89e18..f12bc2e81c80 100644
--- a/tools/iio/iio_utils.c
+++ b/tools/iio/iio_utils.c
@@ -129,8 +129,8 @@ int iioutils_get_type(unsigned *is_signed,
129 } 129 }
130 sysfsfp = fopen(filename, "r"); 130 sysfsfp = fopen(filename, "r");
131 if (sysfsfp == NULL) { 131 if (sysfsfp == NULL) {
132 printf("failed to open %s\n", filename);
133 ret = -errno; 132 ret = -errno;
133 printf("failed to open %s\n", filename);
134 goto error_free_filename; 134 goto error_free_filename;
135 } 135 }
136 136
@@ -141,8 +141,8 @@ int iioutils_get_type(unsigned *is_signed,
141 bits_used, 141 bits_used,
142 &padint, shift); 142 &padint, shift);
143 if (ret < 0) { 143 if (ret < 0) {
144 printf("failed to pass scan type description\n");
145 ret = -errno; 144 ret = -errno;
145 printf("failed to pass scan type description\n");
146 goto error_close_sysfsfp; 146 goto error_close_sysfsfp;
147 } 147 }
148 *be = (endianchar == 'b'); 148 *be = (endianchar == 'b');
@@ -332,8 +332,8 @@ int build_channel_array(const char *device_dir,
332 } 332 }
333 sysfsfp = fopen(filename, "r"); 333 sysfsfp = fopen(filename, "r");
334 if (sysfsfp == NULL) { 334 if (sysfsfp == NULL) {
335 free(filename);
336 ret = -errno; 335 ret = -errno;
336 free(filename);
337 count--; 337 count--;
338 goto error_cleanup_array; 338 goto error_cleanup_array;
339 } 339 }
@@ -505,8 +505,8 @@ int _write_sysfs_int(char *filename, char *basedir, int val, int verify)
505 sprintf(temp, "%s/%s", basedir, filename); 505 sprintf(temp, "%s/%s", basedir, filename);
506 sysfsfp = fopen(temp, "w"); 506 sysfsfp = fopen(temp, "w");
507 if (sysfsfp == NULL) { 507 if (sysfsfp == NULL) {
508 printf("failed to open %s\n", temp);
509 ret = -errno; 508 ret = -errno;
509 printf("failed to open %s\n", temp);
510 goto error_free; 510 goto error_free;
511 } 511 }
512 fprintf(sysfsfp, "%d", val); 512 fprintf(sysfsfp, "%d", val);
@@ -514,8 +514,8 @@ int _write_sysfs_int(char *filename, char *basedir, int val, int verify)
514 if (verify) { 514 if (verify) {
515 sysfsfp = fopen(temp, "r"); 515 sysfsfp = fopen(temp, "r");
516 if (sysfsfp == NULL) { 516 if (sysfsfp == NULL) {
517 printf("failed to open %s\n", temp);
518 ret = -errno; 517 ret = -errno;
518 printf("failed to open %s\n", temp);
519 goto error_free; 519 goto error_free;
520 } 520 }
521 fscanf(sysfsfp, "%d", &test); 521 fscanf(sysfsfp, "%d", &test);
@@ -556,8 +556,8 @@ int _write_sysfs_string(char *filename, char *basedir, char *val, int verify)
556 sprintf(temp, "%s/%s", basedir, filename); 556 sprintf(temp, "%s/%s", basedir, filename);
557 sysfsfp = fopen(temp, "w"); 557 sysfsfp = fopen(temp, "w");
558 if (sysfsfp == NULL) { 558 if (sysfsfp == NULL) {
559 printf("Could not open %s\n", temp);
560 ret = -errno; 559 ret = -errno;
560 printf("Could not open %s\n", temp);
561 goto error_free; 561 goto error_free;
562 } 562 }
563 fprintf(sysfsfp, "%s", val); 563 fprintf(sysfsfp, "%s", val);
@@ -565,8 +565,8 @@ int _write_sysfs_string(char *filename, char *basedir, char *val, int verify)
565 if (verify) { 565 if (verify) {
566 sysfsfp = fopen(temp, "r"); 566 sysfsfp = fopen(temp, "r");
567 if (sysfsfp == NULL) { 567 if (sysfsfp == NULL) {
568 printf("could not open file to verify\n");
569 ret = -errno; 568 ret = -errno;
569 printf("could not open file to verify\n");
570 goto error_free; 570 goto error_free;
571 } 571 }
572 fscanf(sysfsfp, "%s", temp); 572 fscanf(sysfsfp, "%s", temp);