linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] tools: iio: Fix style issues
@ 2015-07-13 13:13 Cristina Opriceana
  2015-07-13 13:15 ` [PATCH 1/3] tools: iio: Remove explicit NULL comparison Cristina Opriceana
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Cristina Opriceana @ 2015-07-13 13:13 UTC (permalink / raw)
  To: jic23
  Cc: knaack.h, lars, pmeerw, linux-iio, linux-kernel, daniel.baluta,
	octavian.purdila

This patchset fixes some style issues in userspace iio tools
as indicated by checkpatch.pl.

Cristina Opriceana (3):
  tools: iio: Remove explicit NULL comparison
  tools: iio: Remove unnecessary braces
  tools: iio: Add ARRAY_SIZE macro

 tools/iio/generic_buffer.c    |  4 +--
 tools/iio/iio_event_monitor.c |  3 +--
 tools/iio/iio_utils.c         | 58 +++++++++++++++++++++----------------------
 tools/iio/iio_utils.h         |  2 ++
 tools/iio/lsiio.c             | 10 ++++----
 5 files changed, 39 insertions(+), 38 deletions(-)

-- 
1.9.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/3] tools: iio: Remove explicit NULL comparison
  2015-07-13 13:13 [PATCH 0/3] tools: iio: Fix style issues Cristina Opriceana
@ 2015-07-13 13:15 ` Cristina Opriceana
  2015-07-13 18:46   ` Hartmut Knaack
  2015-07-13 13:17 ` [PATCH 2/3] tools: iio: Remove unnecessary braces Cristina Opriceana
  2015-07-13 13:20 ` [PATCH 3/3] tools: iio: Add ARRAY_SIZE macro Cristina Opriceana
  2 siblings, 1 reply; 10+ messages in thread
From: Cristina Opriceana @ 2015-07-13 13:15 UTC (permalink / raw)
  To: jic23
  Cc: knaack.h, lars, pmeerw, linux-iio, linux-kernel, daniel.baluta,
	octavian.purdila

Remove explicit NULL comparison and write it in its simpler form as
recommended by checkpatch.pl.

Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com>
---
 tools/iio/generic_buffer.c |  4 ++--
 tools/iio/iio_utils.c      | 56 +++++++++++++++++++++++-----------------------
 tools/iio/lsiio.c          | 10 ++++-----
 3 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
index 0e73723..9535c2d 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 <device_name>_dev[n] where n matches
diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
index 8fb3214..4a7e480 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 7f432a5..4f8172f 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;
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/3] tools: iio: Remove unnecessary braces
  2015-07-13 13:13 [PATCH 0/3] tools: iio: Fix style issues Cristina Opriceana
  2015-07-13 13:15 ` [PATCH 1/3] tools: iio: Remove explicit NULL comparison Cristina Opriceana
@ 2015-07-13 13:17 ` Cristina Opriceana
  2015-07-13 18:48   ` Hartmut Knaack
  2015-07-13 13:20 ` [PATCH 3/3] tools: iio: Add ARRAY_SIZE macro Cristina Opriceana
  2 siblings, 1 reply; 10+ messages in thread
From: Cristina Opriceana @ 2015-07-13 13:17 UTC (permalink / raw)
  To: jic23
  Cc: knaack.h, lars, pmeerw, linux-iio, linux-kernel, daniel.baluta,
	octavian.purdila

Single statement blocks don’t need braces.
Found with checkpatch.pl.

Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com>
---
 tools/iio/iio_event_monitor.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/iio/iio_event_monitor.c b/tools/iio/iio_event_monitor.c
index 703f4cb..9ee1959 100644
--- a/tools/iio/iio_event_monitor.c
+++ b/tools/iio/iio_event_monitor.c
@@ -262,9 +262,8 @@ int main(int argc, char **argv)
 		printf("Found IIO device with name %s with device number %d\n",
 		       device_name, dev_num);
 		ret = asprintf(&chrdev_name, "/dev/iio:device%d", dev_num);
-		if (ret < 0) {
+		if (ret < 0)
 			return -ENOMEM;
-		}
 	} else {
 		/*
 		 * If we can't find an IIO device by name assume device_name is
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/3] tools: iio: Add ARRAY_SIZE macro
  2015-07-13 13:13 [PATCH 0/3] tools: iio: Fix style issues Cristina Opriceana
  2015-07-13 13:15 ` [PATCH 1/3] tools: iio: Remove explicit NULL comparison Cristina Opriceana
  2015-07-13 13:17 ` [PATCH 2/3] tools: iio: Remove unnecessary braces Cristina Opriceana
@ 2015-07-13 13:20 ` Cristina Opriceana
  2015-07-13 18:49   ` Hartmut Knaack
  2 siblings, 1 reply; 10+ messages in thread
From: Cristina Opriceana @ 2015-07-13 13:20 UTC (permalink / raw)
  To: jic23
  Cc: knaack.h, lars, pmeerw, linux-iio, linux-kernel, daniel.baluta,
	octavian.purdila

Calculation of the length of an array can be done with the ARRAY_SIZE
macro to make code more abstract and remove the associated
checkpatch.pl warning.

Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com>
---
 tools/iio/iio_utils.c | 2 +-
 tools/iio/iio_utils.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
index 4a7e480..e177f40 100644
--- a/tools/iio/iio_utils.c
+++ b/tools/iio/iio_utils.c
@@ -39,7 +39,7 @@ int iioutils_break_up_name(const char *full_name, char **generic_name)
 	char *working, *prefix = "";
 	int i, ret;
 
-	for (i = 0; i < sizeof(iio_direction) / sizeof(iio_direction[0]); i++)
+	for (i = 0; i < ARRAY_SIZE(iio_direction); i++)
 		if (!strncmp(full_name, iio_direction[i],
 			     strlen(iio_direction[i]))) {
 			prefix = iio_direction[i];
diff --git a/tools/iio/iio_utils.h b/tools/iio/iio_utils.h
index 0866101..f30a109 100644
--- a/tools/iio/iio_utils.h
+++ b/tools/iio/iio_utils.h
@@ -18,6 +18,8 @@
 #define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements"
 #define FORMAT_TYPE_FILE "%s_type"
 
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
+
 extern const char *iio_dir;
 
 /**
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] tools: iio: Remove explicit NULL comparison
  2015-07-13 13:15 ` [PATCH 1/3] tools: iio: Remove explicit NULL comparison Cristina Opriceana
@ 2015-07-13 18:46   ` Hartmut Knaack
  2015-07-19 14:01     ` Jonathan Cameron
  0 siblings, 1 reply; 10+ messages in thread
From: Hartmut Knaack @ 2015-07-13 18:46 UTC (permalink / raw)
  To: Cristina Opriceana, jic23
  Cc: lars, pmeerw, linux-iio, linux-kernel, daniel.baluta,
	octavian.purdila

Cristina Opriceana schrieb am 13.07.2015 um 15:15:
> Remove explicit NULL comparison and write it in its simpler form as
> recommended by checkpatch.pl.
> 
> Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com>
Reviewed-by: Hartmut Knaack <knaack.h@gmx.de>
> ---

Every instance covered, consistency improved. Not everyone will mind that,
but good job.

>  tools/iio/generic_buffer.c |  4 ++--
>  tools/iio/iio_utils.c      | 56 +++++++++++++++++++++++-----------------------
>  tools/iio/lsiio.c          | 10 ++++-----
>  3 files changed, 35 insertions(+), 35 deletions(-)
> 
> diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
> index 0e73723..9535c2d 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 <device_name>_dev[n] where n matches
> diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
> index 8fb3214..4a7e480 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 7f432a5..4f8172f 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;
>  
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] tools: iio: Remove unnecessary braces
  2015-07-13 13:17 ` [PATCH 2/3] tools: iio: Remove unnecessary braces Cristina Opriceana
@ 2015-07-13 18:48   ` Hartmut Knaack
  2015-07-19 14:02     ` Jonathan Cameron
  0 siblings, 1 reply; 10+ messages in thread
From: Hartmut Knaack @ 2015-07-13 18:48 UTC (permalink / raw)
  To: Cristina Opriceana, jic23
  Cc: lars, pmeerw, linux-iio, linux-kernel, daniel.baluta,
	octavian.purdila

Cristina Opriceana schrieb am 13.07.2015 um 15:17:
> Single statement blocks don’t need braces.
> Found with checkpatch.pl.
> 
> Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com>
Acked-by: Hartmut Knaack <knaack.h@gmx.de>
> ---

Oops, that slipped through my hands. Thanks for taking care of this.

>  tools/iio/iio_event_monitor.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/tools/iio/iio_event_monitor.c b/tools/iio/iio_event_monitor.c
> index 703f4cb..9ee1959 100644
> --- a/tools/iio/iio_event_monitor.c
> +++ b/tools/iio/iio_event_monitor.c
> @@ -262,9 +262,8 @@ int main(int argc, char **argv)
>  		printf("Found IIO device with name %s with device number %d\n",
>  		       device_name, dev_num);
>  		ret =sprintf(&chrdev_name, "/dev/iio:device%d", dev_num);
> -		if (ret < 0) {
> +		if (ret < 0)
>  			return -ENOMEM;
> -		}
>  	} else {
>  		/*
>  		 * If we can't find an IIO device by name assume device_name is
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] tools: iio: Add ARRAY_SIZE macro
  2015-07-13 13:20 ` [PATCH 3/3] tools: iio: Add ARRAY_SIZE macro Cristina Opriceana
@ 2015-07-13 18:49   ` Hartmut Knaack
  2015-07-19 14:03     ` Jonathan Cameron
  0 siblings, 1 reply; 10+ messages in thread
From: Hartmut Knaack @ 2015-07-13 18:49 UTC (permalink / raw)
  To: Cristina Opriceana, jic23
  Cc: lars, pmeerw, linux-iio, linux-kernel, daniel.baluta,
	octavian.purdila

Cristina Opriceana schrieb am 13.07.2015 um 15:20:
> Calculation of the length of an array can be done with the ARRAY_SIZE
> macro to make code more abstract and remove the associated
> checkpatch.pl warning.
> 
> Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com>
Acked-by: Hartmut Knaack <knaack.h@gmx.de>
> ---
>  tools/iio/iio_utils.c | 2 +-
>  tools/iio/iio_utils.h | 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
> index 4a7e480..e177f40 100644
> --- a/tools/iio/iio_utils.c
> +++ b/tools/iio/iio_utils.c
> @@ -39,7 +39,7 @@ int iioutils_break_up_name(const char *full_name, char **generic_name)
>  	char *working, *prefix = "";
>  	int i, ret;
>  
> -	for (i = 0; i < sizeof(iio_direction) / sizeof(iio_direction[0]); i++)
> +	for (i = 0; i < ARRAY_SIZE(iio_direction); i++)
>  		if (!strncmp(full_name, iio_direction[i],
>  			     strlen(iio_direction[i]))) {
>  			prefix = iio_direction[i];
> diff --git a/tools/iio/iio_utils.h b/tools/iio/iio_utils.h
> index 0866101..f30a109 100644
> --- a/tools/iio/iio_utils.h
> +++ b/tools/iio/iio_utils.h
> @@ -18,6 +18,8 @@
>  #define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements"
>  #define FORMAT_TYPE_FILE "%s_type"
>  
> +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
> +
>  extern const char *iio_dir;
>  
>  /**
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/3] tools: iio: Remove explicit NULL comparison
  2015-07-13 18:46   ` Hartmut Knaack
@ 2015-07-19 14:01     ` Jonathan Cameron
  0 siblings, 0 replies; 10+ messages in thread
From: Jonathan Cameron @ 2015-07-19 14:01 UTC (permalink / raw)
  To: Hartmut Knaack, Cristina Opriceana
  Cc: lars, pmeerw, linux-iio, linux-kernel, daniel.baluta,
	octavian.purdila

On 13/07/15 19:46, Hartmut Knaack wrote:
> Cristina Opriceana schrieb am 13.07.2015 um 15:15:
>> Remove explicit NULL comparison and write it in its simpler form as
>> recommended by checkpatch.pl.
>>
>> Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com>
> Reviewed-by: Hartmut Knaack <knaack.h@gmx.de>
Applied to the togreg branch of iio.git.  Thanks,

Jonathan
>> ---
> 
> Every instance covered, consistency improved. Not everyone will mind that,
> but good job.
> 
>>  tools/iio/generic_buffer.c |  4 ++--
>>  tools/iio/iio_utils.c      | 56 +++++++++++++++++++++++-----------------------
>>  tools/iio/lsiio.c          | 10 ++++-----
>>  3 files changed, 35 insertions(+), 35 deletions(-)
>>
>> diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
>> index 0e73723..9535c2d 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 <device_name>_dev[n] where n matches
>> diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
>> index 8fb3214..4a7e480 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 7f432a5..4f8172f 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;
>>  
>>
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/3] tools: iio: Remove unnecessary braces
  2015-07-13 18:48   ` Hartmut Knaack
@ 2015-07-19 14:02     ` Jonathan Cameron
  0 siblings, 0 replies; 10+ messages in thread
From: Jonathan Cameron @ 2015-07-19 14:02 UTC (permalink / raw)
  To: Hartmut Knaack, Cristina Opriceana
  Cc: lars, pmeerw, linux-iio, linux-kernel, daniel.baluta,
	octavian.purdila

On 13/07/15 19:48, Hartmut Knaack wrote:
> Cristina Opriceana schrieb am 13.07.2015 um 15:17:
>> Single statement blocks don’t need braces.
>> Found with checkpatch.pl.
>>
>> Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com>
> Acked-by: Hartmut Knaack <knaack.h@gmx.de>
Applied to the togreg branch of iio.git.

Thanks,

Jonathan
>> ---
> 
> Oops, that slipped through my hands. Thanks for taking care of this.
> 
>>  tools/iio/iio_event_monitor.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/tools/iio/iio_event_monitor.c b/tools/iio/iio_event_monitor.c
>> index 703f4cb..9ee1959 100644
>> --- a/tools/iio/iio_event_monitor.c
>> +++ b/tools/iio/iio_event_monitor.c
>> @@ -262,9 +262,8 @@ int main(int argc, char **argv)
>>  		printf("Found IIO device with name %s with device number %d\n",
>>  		       device_name, dev_num);
>>  		ret =sprintf(&chrdev_name, "/dev/iio:device%d", dev_num);
>> -		if (ret < 0) {
>> +		if (ret < 0)
>>  			return -ENOMEM;
>> -		}
>>  	} else {
>>  		/*
>>  		 * If we can't find an IIO device by name assume device_name is
>>
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/3] tools: iio: Add ARRAY_SIZE macro
  2015-07-13 18:49   ` Hartmut Knaack
@ 2015-07-19 14:03     ` Jonathan Cameron
  0 siblings, 0 replies; 10+ messages in thread
From: Jonathan Cameron @ 2015-07-19 14:03 UTC (permalink / raw)
  To: Hartmut Knaack, Cristina Opriceana
  Cc: lars, pmeerw, linux-iio, linux-kernel, daniel.baluta,
	octavian.purdila

On 13/07/15 19:49, Hartmut Knaack wrote:
> Cristina Opriceana schrieb am 13.07.2015 um 15:20:
>> Calculation of the length of an array can be done with the ARRAY_SIZE
>> macro to make code more abstract and remove the associated
>> checkpatch.pl warning.
>>
>> Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com>
> Acked-by: Hartmut Knaack <knaack.h@gmx.de>
Applied to the togreg branch of iio.git and initially pushed out as
testing.  Good patch set, thanks!

Jonathan
>> ---
>>  tools/iio/iio_utils.c | 2 +-
>>  tools/iio/iio_utils.h | 2 ++
>>  2 files changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
>> index 4a7e480..e177f40 100644
>> --- a/tools/iio/iio_utils.c
>> +++ b/tools/iio/iio_utils.c
>> @@ -39,7 +39,7 @@ int iioutils_break_up_name(const char *full_name, char **generic_name)
>>  	char *working, *prefix = "";
>>  	int i, ret;
>>  
>> -	for (i = 0; i < sizeof(iio_direction) / sizeof(iio_direction[0]); i++)
>> +	for (i = 0; i < ARRAY_SIZE(iio_direction); i++)
>>  		if (!strncmp(full_name, iio_direction[i],
>>  			     strlen(iio_direction[i]))) {
>>  			prefix = iio_direction[i];
>> diff --git a/tools/iio/iio_utils.h b/tools/iio/iio_utils.h
>> index 0866101..f30a109 100644
>> --- a/tools/iio/iio_utils.h
>> +++ b/tools/iio/iio_utils.h
>> @@ -18,6 +18,8 @@
>>  #define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements"
>>  #define FORMAT_TYPE_FILE "%s_type"
>>  
>> +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
>> +
>>  extern const char *iio_dir;
>>  
>>  /**
>>
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-07-19 14:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-13 13:13 [PATCH 0/3] tools: iio: Fix style issues Cristina Opriceana
2015-07-13 13:15 ` [PATCH 1/3] tools: iio: Remove explicit NULL comparison Cristina Opriceana
2015-07-13 18:46   ` Hartmut Knaack
2015-07-19 14:01     ` Jonathan Cameron
2015-07-13 13:17 ` [PATCH 2/3] tools: iio: Remove unnecessary braces Cristina Opriceana
2015-07-13 18:48   ` Hartmut Knaack
2015-07-19 14:02     ` Jonathan Cameron
2015-07-13 13:20 ` [PATCH 3/3] tools: iio: Add ARRAY_SIZE macro Cristina Opriceana
2015-07-13 18:49   ` Hartmut Knaack
2015-07-19 14:03     ` Jonathan Cameron

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).