summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristina Opriceana <cristina.opriceana@gmail.com>2015-07-13 09:15:56 -0400
committerJonathan Cameron <jic23@kernel.org>2015-07-20 13:41:22 -0400
commitff1ac639b395d58bbd99ff4a36b10eebb81544a3 (patch)
tree2668b619972abfcc7025c2f56fda8fba60ef508a
parent8ab6abfca09c1800dccb753775f6ce8ee82f50dd (diff)
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 <cristina.opriceana@gmail.com> Reviewed-by: Hartmut Knaack <knaack.h@gmx.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--tools/iio/generic_buffer.c4
-rw-r--r--tools/iio/iio_utils.c56
-rw-r--r--tools/iio/lsiio.c10
3 files changed, 35 insertions, 35 deletions
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)
270 } 270 }
271 } 271 }
272 272
273 if (device_name == NULL) { 273 if (!device_name) {
274 printf("Device name not set\n"); 274 printf("Device name not set\n");
275 print_usage(); 275 print_usage();
276 return -1; 276 return -1;
@@ -290,7 +290,7 @@ int main(int argc, char **argv)
290 return -ENOMEM; 290 return -ENOMEM;
291 291
292 if (!notrigger) { 292 if (!notrigger) {
293 if (trigger_name == NULL) { 293 if (!trigger_name) {
294 /* 294 /*
295 * Build the trigger name. If it is device associated 295 * Build the trigger name. If it is device associated
296 * its name is <device_name>_dev[n] where n matches 296 * 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 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,
117 } 117 }
118 118
119 dp = opendir(scan_el_dir); 119 dp = opendir(scan_el_dir);
120 if (dp == NULL) { 120 if (!dp) {
121 ret = -errno; 121 ret = -errno;
122 goto error_free_builtname_generic; 122 goto error_free_builtname_generic;
123 } 123 }
124 124
125 ret = -ENOENT; 125 ret = -ENOENT;
126 while (ent = readdir(dp), ent != NULL) 126 while (ent = readdir(dp), ent)
127 /* 127 /*
128 * Do we allow devices to override a generic name with 128 * Do we allow devices to override a generic name with
129 * a specific one? 129 * a specific one?
@@ -138,7 +138,7 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
138 } 138 }
139 139
140 sysfsfp = fopen(filename, "r"); 140 sysfsfp = fopen(filename, "r");
141 if (sysfsfp == NULL) { 141 if (!sysfsfp) {
142 ret = -errno; 142 ret = -errno;
143 printf("failed to open %s\n", filename); 143 printf("failed to open %s\n", filename);
144 goto error_free_filename; 144 goto error_free_filename;
@@ -235,13 +235,13 @@ int iioutils_get_param_float(float *output, const char *param_name,
235 } 235 }
236 236
237 dp = opendir(device_dir); 237 dp = opendir(device_dir);
238 if (dp == NULL) { 238 if (!dp) {
239 ret = -errno; 239 ret = -errno;
240 goto error_free_builtname_generic; 240 goto error_free_builtname_generic;
241 } 241 }
242 242
243 ret = -ENOENT; 243 ret = -ENOENT;
244 while (ent = readdir(dp), ent != NULL) 244 while (ent = readdir(dp), ent)
245 if ((strcmp(builtname, ent->d_name) == 0) || 245 if ((strcmp(builtname, ent->d_name) == 0) ||
246 (strcmp(builtname_generic, ent->d_name) == 0)) { 246 (strcmp(builtname_generic, ent->d_name) == 0)) {
247 ret = asprintf(&filename, 247 ret = asprintf(&filename,
@@ -325,12 +325,12 @@ int build_channel_array(const char *device_dir,
325 return -ENOMEM; 325 return -ENOMEM;
326 326
327 dp = opendir(scan_el_dir); 327 dp = opendir(scan_el_dir);
328 if (dp == NULL) { 328 if (!dp) {
329 ret = -errno; 329 ret = -errno;
330 goto error_free_name; 330 goto error_free_name;
331 } 331 }
332 332
333 while (ent = readdir(dp), ent != NULL) 333 while (ent = readdir(dp), ent)
334 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), 334 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"),
335 "_en") == 0) { 335 "_en") == 0) {
336 ret = asprintf(&filename, 336 ret = asprintf(&filename,
@@ -341,7 +341,7 @@ int build_channel_array(const char *device_dir,
341 } 341 }
342 342
343 sysfsfp = fopen(filename, "r"); 343 sysfsfp = fopen(filename, "r");
344 if (sysfsfp == NULL) { 344 if (!sysfsfp) {
345 ret = -errno; 345 ret = -errno;
346 free(filename); 346 free(filename);
347 goto error_close_dir; 347 goto error_close_dir;
@@ -369,13 +369,13 @@ int build_channel_array(const char *device_dir,
369 } 369 }
370 370
371 *ci_array = malloc(sizeof(**ci_array) * (*counter)); 371 *ci_array = malloc(sizeof(**ci_array) * (*counter));
372 if (*ci_array == NULL) { 372 if (!*ci_array) {
373 ret = -ENOMEM; 373 ret = -ENOMEM;
374 goto error_close_dir; 374 goto error_close_dir;
375 } 375 }
376 376
377 seekdir(dp, 0); 377 seekdir(dp, 0);
378 while (ent = readdir(dp), ent != NULL) { 378 while (ent = readdir(dp), ent) {
379 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), 379 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"),
380 "_en") == 0) { 380 "_en") == 0) {
381 int current_enabled = 0; 381 int current_enabled = 0;
@@ -391,7 +391,7 @@ int build_channel_array(const char *device_dir,
391 } 391 }
392 392
393 sysfsfp = fopen(filename, "r"); 393 sysfsfp = fopen(filename, "r");
394 if (sysfsfp == NULL) { 394 if (!sysfsfp) {
395 ret = -errno; 395 ret = -errno;
396 free(filename); 396 free(filename);
397 count--; 397 count--;
@@ -424,7 +424,7 @@ int build_channel_array(const char *device_dir,
424 current->name = strndup(ent->d_name, 424 current->name = strndup(ent->d_name,
425 strlen(ent->d_name) - 425 strlen(ent->d_name) -
426 strlen("_en")); 426 strlen("_en"));
427 if (current->name == NULL) { 427 if (!current->name) {
428 free(filename); 428 free(filename);
429 ret = -ENOMEM; 429 ret = -ENOMEM;
430 count--; 430 count--;
@@ -452,7 +452,7 @@ int build_channel_array(const char *device_dir,
452 } 452 }
453 453
454 sysfsfp = fopen(filename, "r"); 454 sysfsfp = fopen(filename, "r");
455 if (sysfsfp == NULL) { 455 if (!sysfsfp) {
456 ret = -errno; 456 ret = -errno;
457 printf("failed to open %s\n", filename); 457 printf("failed to open %s\n", filename);
458 free(filename); 458 free(filename);
@@ -567,12 +567,12 @@ int find_type_by_name(const char *name, const char *type)
567 char *filename; 567 char *filename;
568 568
569 dp = opendir(iio_dir); 569 dp = opendir(iio_dir);
570 if (dp == NULL) { 570 if (!dp) {
571 printf("No industrialio devices available\n"); 571 printf("No industrialio devices available\n");
572 return -ENODEV; 572 return -ENODEV;
573 } 573 }
574 574
575 while (ent = readdir(dp), ent != NULL) { 575 while (ent = readdir(dp), ent) {
576 if (strcmp(ent->d_name, ".") != 0 && 576 if (strcmp(ent->d_name, ".") != 0 &&
577 strcmp(ent->d_name, "..") != 0 && 577 strcmp(ent->d_name, "..") != 0 &&
578 strlen(ent->d_name) > strlen(type) && 578 strlen(ent->d_name) > strlen(type) &&
@@ -595,7 +595,7 @@ int find_type_by_name(const char *name, const char *type)
595 ":", 1) != 0) { 595 ":", 1) != 0) {
596 filename = malloc(strlen(iio_dir) + strlen(type) 596 filename = malloc(strlen(iio_dir) + strlen(type)
597 + numstrlen + 6); 597 + numstrlen + 6);
598 if (filename == NULL) { 598 if (!filename) {
599 ret = -ENOMEM; 599 ret = -ENOMEM;
600 goto error_close_dir; 600 goto error_close_dir;
601 } 601 }
@@ -654,7 +654,7 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val,
654 int test; 654 int test;
655 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 655 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
656 656
657 if (temp == NULL) 657 if (!temp)
658 return -ENOMEM; 658 return -ENOMEM;
659 659
660 ret = sprintf(temp, "%s/%s", basedir, filename); 660 ret = sprintf(temp, "%s/%s", basedir, filename);
@@ -662,7 +662,7 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val,
662 goto error_free; 662 goto error_free;
663 663
664 sysfsfp = fopen(temp, "w"); 664 sysfsfp = fopen(temp, "w");
665 if (sysfsfp == NULL) { 665 if (!sysfsfp) {
666 ret = -errno; 666 ret = -errno;
667 printf("failed to open %s\n", temp); 667 printf("failed to open %s\n", temp);
668 goto error_free; 668 goto error_free;
@@ -683,7 +683,7 @@ static int _write_sysfs_int(const char *filename, const char *basedir, int val,
683 683
684 if (verify) { 684 if (verify) {
685 sysfsfp = fopen(temp, "r"); 685 sysfsfp = fopen(temp, "r");
686 if (sysfsfp == NULL) { 686 if (!sysfsfp) {
687 ret = -errno; 687 ret = -errno;
688 printf("failed to open %s\n", temp); 688 printf("failed to open %s\n", temp);
689 goto error_free; 689 goto error_free;
@@ -749,7 +749,7 @@ static int _write_sysfs_string(const char *filename, const char *basedir,
749 FILE *sysfsfp; 749 FILE *sysfsfp;
750 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 750 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
751 751
752 if (temp == NULL) { 752 if (!temp) {
753 printf("Memory allocation failed\n"); 753 printf("Memory allocation failed\n");
754 return -ENOMEM; 754 return -ENOMEM;
755 } 755 }
@@ -759,7 +759,7 @@ static int _write_sysfs_string(const char *filename, const char *basedir,
759 goto error_free; 759 goto error_free;
760 760
761 sysfsfp = fopen(temp, "w"); 761 sysfsfp = fopen(temp, "w");
762 if (sysfsfp == NULL) { 762 if (!sysfsfp) {
763 ret = -errno; 763 ret = -errno;
764 printf("Could not open %s\n", temp); 764 printf("Could not open %s\n", temp);
765 goto error_free; 765 goto error_free;
@@ -780,7 +780,7 @@ static int _write_sysfs_string(const char *filename, const char *basedir,
780 780
781 if (verify) { 781 if (verify) {
782 sysfsfp = fopen(temp, "r"); 782 sysfsfp = fopen(temp, "r");
783 if (sysfsfp == NULL) { 783 if (!sysfsfp) {
784 ret = -errno; 784 ret = -errno;
785 printf("Could not open file to verify\n"); 785 printf("Could not open file to verify\n");
786 goto error_free; 786 goto error_free;
@@ -855,7 +855,7 @@ int read_sysfs_posint(const char *filename, const char *basedir)
855 FILE *sysfsfp; 855 FILE *sysfsfp;
856 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 856 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
857 857
858 if (temp == NULL) { 858 if (!temp) {
859 printf("Memory allocation failed"); 859 printf("Memory allocation failed");
860 return -ENOMEM; 860 return -ENOMEM;
861 } 861 }
@@ -865,7 +865,7 @@ int read_sysfs_posint(const char *filename, const char *basedir)
865 goto error_free; 865 goto error_free;
866 866
867 sysfsfp = fopen(temp, "r"); 867 sysfsfp = fopen(temp, "r");
868 if (sysfsfp == NULL) { 868 if (!sysfsfp) {
869 ret = -errno; 869 ret = -errno;
870 goto error_free; 870 goto error_free;
871 } 871 }
@@ -902,7 +902,7 @@ int read_sysfs_float(const char *filename, const char *basedir, float *val)
902 FILE *sysfsfp; 902 FILE *sysfsfp;
903 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 903 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
904 904
905 if (temp == NULL) { 905 if (!temp) {
906 printf("Memory allocation failed"); 906 printf("Memory allocation failed");
907 return -ENOMEM; 907 return -ENOMEM;
908 } 908 }
@@ -912,7 +912,7 @@ int read_sysfs_float(const char *filename, const char *basedir, float *val)
912 goto error_free; 912 goto error_free;
913 913
914 sysfsfp = fopen(temp, "r"); 914 sysfsfp = fopen(temp, "r");
915 if (sysfsfp == NULL) { 915 if (!sysfsfp) {
916 ret = -errno; 916 ret = -errno;
917 goto error_free; 917 goto error_free;
918 } 918 }
@@ -949,7 +949,7 @@ int read_sysfs_string(const char *filename, const char *basedir, char *str)
949 FILE *sysfsfp; 949 FILE *sysfsfp;
950 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 950 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
951 951
952 if (temp == NULL) { 952 if (!temp) {
953 printf("Memory allocation failed"); 953 printf("Memory allocation failed");
954 return -ENOMEM; 954 return -ENOMEM;
955 } 955 }
@@ -959,7 +959,7 @@ int read_sysfs_string(const char *filename, const char *basedir, char *str)
959 goto error_free; 959 goto error_free;
960 960
961 sysfsfp = fopen(temp, "r"); 961 sysfsfp = fopen(temp, "r");
962 if (sysfsfp == NULL) { 962 if (!sysfsfp) {
963 ret = -errno; 963 ret = -errno;
964 goto error_free; 964 goto error_free;
965 } 965 }
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)
46 const struct dirent *ent; 46 const struct dirent *ent;
47 47
48 dp = opendir(dev_dir_name); 48 dp = opendir(dev_dir_name);
49 if (dp == NULL) 49 if (!dp)
50 return -errno; 50 return -errno;
51 51
52 while (ent = readdir(dp), ent != NULL) 52 while (ent = readdir(dp), ent)
53 if (check_prefix(ent->d_name, "in_") && 53 if (check_prefix(ent->d_name, "in_") &&
54 check_postfix(ent->d_name, "_raw")) 54 check_postfix(ent->d_name, "_raw"))
55 printf(" %-10s\n", ent->d_name); 55 printf(" %-10s\n", ent->d_name);
@@ -107,12 +107,12 @@ static int dump_devices(void)
107 DIR *dp; 107 DIR *dp;
108 108
109 dp = opendir(iio_dir); 109 dp = opendir(iio_dir);
110 if (dp == NULL) { 110 if (!dp) {
111 printf("No industrial I/O devices available\n"); 111 printf("No industrial I/O devices available\n");
112 return -ENODEV; 112 return -ENODEV;
113 } 113 }
114 114
115 while (ent = readdir(dp), ent != NULL) { 115 while (ent = readdir(dp), ent) {
116 if (check_prefix(ent->d_name, type_device)) { 116 if (check_prefix(ent->d_name, type_device)) {
117 char *dev_dir_name; 117 char *dev_dir_name;
118 118
@@ -134,7 +134,7 @@ static int dump_devices(void)
134 } 134 }
135 } 135 }
136 rewinddir(dp); 136 rewinddir(dp);
137 while (ent = readdir(dp), ent != NULL) { 137 while (ent = readdir(dp), ent) {
138 if (check_prefix(ent->d_name, type_trigger)) { 138 if (check_prefix(ent->d_name, type_trigger)) {
139 char *dev_dir_name; 139 char *dev_dir_name;
140 140