tools: iio: Add ARRAY_SIZE macro
authorCristina Opriceana <cristina.opriceana@gmail.com>
Mon, 13 Jul 2015 13:20:11 +0000 (16:20 +0300)
committerJonathan Cameron <jic23@kernel.org>
Mon, 20 Jul 2015 17:41:23 +0000 (18:41 +0100)
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>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
tools/iio/iio_utils.c
tools/iio/iio_utils.h

index 4a7e4801cebfa2977c207b10e28d43b63085bfeb..e177f4022d400f59af67eb3ac35c24b920fb3d4a 100644 (file)
@@ -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];
index 086610139ade32b6ec8b0dfe8572e2bcd14d9b34..f30a1091b53e681e1b2e1a158146f0ca350cbba5 100644 (file)
@@ -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;
 
 /**