linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Hartmut Knaack <knaack.h@gmx.de>, linux-iio@vger.kernel.org
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald <pmeerw@pmeerw.net>,
	Roberta Dobrescu <roberta.dobrescu@gmail.com>,
	Daniel Baluta <daniel.baluta@intel.com>,
	Irina Tirdea <irina.tirdea@intel.com>
Subject: Re: [PATCH 08/32] tools:iio: save errno first
Date: Sun, 31 May 2015 17:33:14 +0100	[thread overview]
Message-ID: <556B37CA.70708@kernel.org> (raw)
In-Reply-To: <0d987c62b698f3c187a7d8b528d9e0475e9b97f4.1433072539.git.knaack.h@gmx.de>

On 31/05/15 13:39, Hartmut Knaack wrote:
> 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>
Applied,

Not one I ever thought about, but can easily see why the way it was done
here is a bad idea.  Thanks Hartmut!
> ---
>  tools/iio/generic_buffer.c    |  2 +-
>  tools/iio/iio_event_monitor.c |  6 +++---
>  tools/iio/iio_utils.c         | 14 +++++++-------
>  3 files changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
> index 51ae3df..d52a55a 100644
> --- a/tools/iio/generic_buffer.c
> +++ b/tools/iio/generic_buffer.c
> @@ -296,8 +296,8 @@ 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 */
> -		printf("Failed to open %s\n", buffer_access);
>  		ret = -errno;
> +		printf("Failed to open %s\n", buffer_access);
>  		goto error_free_buffer_access;
>  	}
>  
> diff --git a/tools/iio/iio_event_monitor.c b/tools/iio/iio_event_monitor.c
> index 427c271..f6fdab4 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)
>  
>  	fd = open(chrdev_name, 0);
>  	if (fd == -1) {
> -		fprintf(stdout, "Failed to open %s\n", chrdev_name);
>  		ret = -errno;
> +		fprintf(stdout, "Failed to open %s\n", chrdev_name);
>  		goto error_free_chrdev_name;
>  	}
>  
> @@ -279,8 +279,8 @@ int main(int argc, char **argv)
>  	close(fd);
>  
>  	if (ret == -1 || event_fd == -1) {
> -		fprintf(stdout, "Failed to retrieve event fd\n");
>  		ret = -errno;
> +		fprintf(stdout, "Failed to retrieve event fd\n");
>  		goto error_free_chrdev_name;
>  	}
>  
> @@ -291,8 +291,8 @@ int main(int argc, char **argv)
>  				printf("nothing available\n");
>  				continue;
>  			} else {
> -				perror("Failed to read event from device");
>  				ret = -errno;
> +				perror("Failed to read event from device");
>  				break;
>  			}
>  		}
> diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
> index 1c0ca2f..f12bc2e 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);
> 


  reply	other threads:[~2015-06-01 21:16 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-31 12:39 [PATCH 00/32] iio-tools out-of-staging cleanup Hartmut Knaack
2015-05-31 12:39 ` [PATCH 01/32] tools:iio:generic_buffer: fix order of freeing data Hartmut Knaack
2015-05-31 16:13   ` Jonathan Cameron
2015-05-31 12:39 ` [PATCH 02/32] tools:iio:generic_buffer: free dev_dir_name on exit Hartmut Knaack
2015-05-31 16:17   ` Jonathan Cameron
2015-05-31 12:39 ` [PATCH 03/32] tools:iio:iio_utils: free scan_el_dir " Hartmut Knaack
2015-05-31 16:19   ` Jonathan Cameron
2015-05-31 12:39 ` [PATCH 04/32] tools:iio: free channel-array completely Hartmut Knaack
2015-05-31 16:20   ` Jonathan Cameron
2015-05-31 12:39 ` [PATCH 05/32] tools:iio:iio_utils: fix allocation handling Hartmut Knaack
2015-05-31 16:23   ` Jonathan Cameron
2015-05-31 12:39 ` [PATCH 06/32] tools:iio:generic_buffer: add check before free Hartmut Knaack
2015-05-31 16:29   ` Jonathan Cameron
2015-05-31 12:39 ` [PATCH 07/32] tools:iio:lsiio: add closedir before exit Hartmut Knaack
2015-05-31 16:30   ` Jonathan Cameron
2015-05-31 12:39 ` [PATCH 08/32] tools:iio: save errno first Hartmut Knaack
2015-05-31 16:33   ` Jonathan Cameron [this message]
2015-05-31 12:39 ` [PATCH 09/32] tools:iio:iio_event_monitor: save right errno Hartmut Knaack
2015-05-31 16:34   ` Jonathan Cameron
2015-05-31 12:39 ` [PATCH 10/32] tools:iio:generic_buffer: fix check of errno Hartmut Knaack
2015-05-31 16:35   ` Jonathan Cameron
2015-05-31 12:39 ` [PATCH 11/32] tools:iio:generic_buffer: pass up right error code Hartmut Knaack
2015-05-31 16:36   ` Jonathan Cameron
2015-05-31 12:39 ` [PATCH 12/32] tools:iio:generic_buffer: sign-extend and shift data Hartmut Knaack
2015-05-31 16:41   ` Jonathan Cameron
2015-05-31 12:39 ` [PATCH 13/32] tools:iio:iio_utils: check amount of matches Hartmut Knaack
2015-05-31 16:41   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 14/32] tools:iio:iio_utils: implement digit calculation Hartmut Knaack
2015-05-31 18:19   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 15/32] tools:iio:iio_utils: mark private function static Hartmut Knaack
2015-05-31 12:40 ` [PATCH 16/32] tools:iio: catch errors in string allocation Hartmut Knaack
2015-05-31 18:21   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 17/32] tools:iio:generic_buffer: catch errors for arguments conversion Hartmut Knaack
2015-05-31 12:40 ` [PATCH 18/32] tools:iio:generic_buffer: add error handling Hartmut Knaack
2015-05-31 12:40 ` [PATCH 19/32] tools:iio:iio_event_monitor: " Hartmut Knaack
2015-05-31 18:25   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 20/32] tools:iio:iio_event_monitor: check if event is fully read Hartmut Knaack
2015-05-31 18:36   ` Jonathan Cameron
2015-06-01 22:00     ` Hartmut Knaack
2015-05-31 12:40 ` [PATCH 21/32] tools:iio:iio_utils: add error handling Hartmut Knaack
2015-05-31 18:44   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 22/32] tools:iio:lsiio: " Hartmut Knaack
2015-05-31 18:45   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 23/32] tools:iio:iio_utils: add missing documentation Hartmut Knaack
2015-06-01  7:33   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 24/32] tools:iio: return values directly Hartmut Knaack
2015-06-01  7:34   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 25/32] tools:iio:iio_event_monitor: refactor events output Hartmut Knaack
2015-06-01  7:34   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 26/32] tools:iio:iio_utils: refactor assignment of is_signed Hartmut Knaack
2015-06-01  7:35   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 27/32] tools:iio:iio_utils: move up reset of sysfsfp Hartmut Knaack
2015-06-01  7:37   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 28/32] tools:iio:iio_utils: initialize count during declaration Hartmut Knaack
2015-06-01  7:38   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 29/32] tools:iio: rework program parameters Hartmut Knaack
2015-06-01  7:40   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 30/32] tools:iio:iio_utils: pass strings as const Hartmut Knaack
2015-06-01  7:40   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 31/32] tools:iio: adjust coding style Hartmut Knaack
2015-06-01  7:46   ` Jonathan Cameron
2015-05-31 12:40 ` [PATCH 32/32] tools:iio: rename variables Hartmut Knaack

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=556B37CA.70708@kernel.org \
    --to=jic23@kernel.org \
    --cc=daniel.baluta@intel.com \
    --cc=irina.tirdea@intel.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=roberta.dobrescu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).