]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
orangefs: use ARRAY_SIZE
authorJérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Sun, 1 Oct 2017 19:30:48 +0000 (15:30 -0400)
committerMike Marshall <hubcap@omnibond.com>
Mon, 13 Nov 2017 20:09:58 +0000 (15:09 -0500)
Using the ARRAY_SIZE macro improves the readability of the code.

Found with Coccinelle with the following semantic patch:
@r depends on (org || report)@
type T;
T[] E;
position p;
@@
(
 (sizeof(E)@p /sizeof(*E))
|
 (sizeof(E)@p /sizeof(E[...]))
|
 (sizeof(E)@p /sizeof(T))
)

Signed-off-by: Jérémy Lefaure <jeremy.lefaure@lse.epita.fr>
Signed-off-by: Mike Marshall <hubcap@omnibond.com>
fs/orangefs/orangefs-debug.h
fs/orangefs/orangefs-utils.c

index b6001bb28f5a94f6d86a17a76b3245525748be9c..c7db56a31b9209076975f6380aad69761cccfde9 100644 (file)
 
 #ifdef __KERNEL__
 #include <linux/types.h>
+#include <linux/kernel.h>
 #else
 #include <stdint.h>
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 #endif
 
 #define        GOSSIP_NO_DEBUG                 (__u64)0
@@ -88,6 +90,6 @@ static struct __keyword_mask_s s_kmod_keyword_mask_map[] = {
 };
 
 static const int num_kmod_keyword_mask_map = (int)
-       (sizeof(s_kmod_keyword_mask_map) / sizeof(struct __keyword_mask_s));
+       (ARRAY_SIZE(s_kmod_keyword_mask_map));
 
 #endif /* __ORANGEFS_DEBUG_H */
index f82336496311c532c3150f1e85b1caf59de03abb..994a0604145afc681d3998b68bcf331b0e71690a 100644 (file)
@@ -4,6 +4,7 @@
  *
  * See COPYING in top-level directory.
  */
+#include <linux/kernel.h>
 #include "protocol.h"
 #include "orangefs-kernel.h"
 #include "orangefs-dev-proto.h"
@@ -606,7 +607,7 @@ int orangefs_normalize_to_errno(__s32 error_code)
        /* Convert ORANGEFS encoded errno values into regular errno values. */
        } else if ((-error_code) & ORANGEFS_ERROR_BIT) {
                i = (-error_code) & ~(ORANGEFS_ERROR_BIT|ORANGEFS_ERROR_CLASS_BITS);
-               if (i < sizeof(PINT_errno_mapping)/sizeof(*PINT_errno_mapping))
+               if (i < ARRAY_SIZE(PINT_errno_mapping))
                        error_code = -PINT_errno_mapping[i];
                else
                        error_code = -EINVAL;