summaryrefslogtreecommitdiff
path: root/tools/iio/iio_utils.c
diff options
context:
space:
mode:
authorHartmut Knaack <knaack.h@gmx.de>2015-05-31 15:39:48 +0300
committerJonathan Cameron <jic23@kernel.org>2015-05-31 19:32:44 +0300
commit2b6a6e67af6f8f644a48f75efc1f44544c0d74f6 (patch)
treeffff341e8cdb92e06abd46628219495c5c2e7066 /tools/iio/iio_utils.c
parentf96d055e4b38c64123f211f0521f834d649cd01c (diff)
downloadlinux-2b6a6e67af6f8f644a48f75efc1f44544c0d74f6.tar.xz
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/iio_utils.c')
-rw-r--r--tools/iio/iio_utils.c14
1 files changed, 7 insertions, 7 deletions
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,
}
sysfsfp = fopen(filename, "r");
if (sysfsfp == NULL) {
- printf("failed to open %s\n", filename);
ret = -errno;
+ printf("failed to open %s\n", filename);
goto error_free_filename;
}
@@ -141,8 +141,8 @@ int iioutils_get_type(unsigned *is_signed,
bits_used,
&padint, shift);
if (ret < 0) {
- printf("failed to pass scan type description\n");
ret = -errno;
+ printf("failed to pass scan type description\n");
goto error_close_sysfsfp;
}
*be = (endianchar == 'b');
@@ -332,8 +332,8 @@ int build_channel_array(const char *device_dir,
}
sysfsfp = fopen(filename, "r");
if (sysfsfp == NULL) {
- free(filename);
ret = -errno;
+ free(filename);
count--;
goto error_cleanup_array;
}
@@ -505,8 +505,8 @@ int _write_sysfs_int(char *filename, char *basedir, int val, int verify)
sprintf(temp, "%s/%s", basedir, filename);
sysfsfp = fopen(temp, "w");
if (sysfsfp == NULL) {
- printf("failed to open %s\n", temp);
ret = -errno;
+ printf("failed to open %s\n", temp);
goto error_free;
}
fprintf(sysfsfp, "%d", val);
@@ -514,8 +514,8 @@ int _write_sysfs_int(char *filename, char *basedir, int val, int verify)
if (verify) {
sysfsfp = fopen(temp, "r");
if (sysfsfp == NULL) {
- printf("failed to open %s\n", temp);
ret = -errno;
+ printf("failed to open %s\n", temp);
goto error_free;
}
fscanf(sysfsfp, "%d", &test);
@@ -556,8 +556,8 @@ int _write_sysfs_string(char *filename, char *basedir, char *val, int verify)
sprintf(temp, "%s/%s", basedir, filename);
sysfsfp = fopen(temp, "w");
if (sysfsfp == NULL) {
- printf("Could not open %s\n", temp);
ret = -errno;
+ printf("Could not open %s\n", temp);
goto error_free;
}
fprintf(sysfsfp, "%s", val);
@@ -565,8 +565,8 @@ int _write_sysfs_string(char *filename, char *basedir, char *val, int verify)
if (verify) {
sysfsfp = fopen(temp, "r");
if (sysfsfp == NULL) {
- printf("could not open file to verify\n");
ret = -errno;
+ printf("could not open file to verify\n");
goto error_free;
}
fscanf(sysfsfp, "%s", temp);