diff options
author | Jérémy Lefaure <jeremy.lefaure@lse.epita.fr> | 2017-10-01 15:30:48 -0400 |
---|---|---|
committer | Mike Marshall <hubcap@omnibond.com> | 2017-11-13 15:09:58 -0500 |
commit | 296200d3bb649f9646f60abe6e8ebb9fd8d20f4b (patch) | |
tree | d47aaf3f3608f15a4d2f747e3bf13d82b7d5454d | |
parent | 933f7ac1a1df37ab6b25b50a85c13fcc5ea8cd03 (diff) |
orangefs: use ARRAY_SIZE
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>
-rw-r--r-- | fs/orangefs/orangefs-debug.h | 4 | ||||
-rw-r--r-- | fs/orangefs/orangefs-utils.c | 3 |
2 files changed, 5 insertions, 2 deletions
diff --git a/fs/orangefs/orangefs-debug.h b/fs/orangefs/orangefs-debug.h index b6001bb28f5a..c7db56a31b92 100644 --- a/fs/orangefs/orangefs-debug.h +++ b/fs/orangefs/orangefs-debug.h | |||
@@ -15,8 +15,10 @@ | |||
15 | 15 | ||
16 | #ifdef __KERNEL__ | 16 | #ifdef __KERNEL__ |
17 | #include <linux/types.h> | 17 | #include <linux/types.h> |
18 | #include <linux/kernel.h> | ||
18 | #else | 19 | #else |
19 | #include <stdint.h> | 20 | #include <stdint.h> |
21 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) | ||
20 | #endif | 22 | #endif |
21 | 23 | ||
22 | #define GOSSIP_NO_DEBUG (__u64)0 | 24 | #define GOSSIP_NO_DEBUG (__u64)0 |
@@ -88,6 +90,6 @@ static struct __keyword_mask_s s_kmod_keyword_mask_map[] = { | |||
88 | }; | 90 | }; |
89 | 91 | ||
90 | static const int num_kmod_keyword_mask_map = (int) | 92 | static const int num_kmod_keyword_mask_map = (int) |
91 | (sizeof(s_kmod_keyword_mask_map) / sizeof(struct __keyword_mask_s)); | 93 | (ARRAY_SIZE(s_kmod_keyword_mask_map)); |
92 | 94 | ||
93 | #endif /* __ORANGEFS_DEBUG_H */ | 95 | #endif /* __ORANGEFS_DEBUG_H */ |
diff --git a/fs/orangefs/orangefs-utils.c b/fs/orangefs/orangefs-utils.c index f82336496311..994a0604145a 100644 --- a/fs/orangefs/orangefs-utils.c +++ b/fs/orangefs/orangefs-utils.c | |||
@@ -4,6 +4,7 @@ | |||
4 | * | 4 | * |
5 | * See COPYING in top-level directory. | 5 | * See COPYING in top-level directory. |
6 | */ | 6 | */ |
7 | #include <linux/kernel.h> | ||
7 | #include "protocol.h" | 8 | #include "protocol.h" |
8 | #include "orangefs-kernel.h" | 9 | #include "orangefs-kernel.h" |
9 | #include "orangefs-dev-proto.h" | 10 | #include "orangefs-dev-proto.h" |
@@ -606,7 +607,7 @@ int orangefs_normalize_to_errno(__s32 error_code) | |||
606 | /* Convert ORANGEFS encoded errno values into regular errno values. */ | 607 | /* Convert ORANGEFS encoded errno values into regular errno values. */ |
607 | } else if ((-error_code) & ORANGEFS_ERROR_BIT) { | 608 | } else if ((-error_code) & ORANGEFS_ERROR_BIT) { |
608 | i = (-error_code) & ~(ORANGEFS_ERROR_BIT|ORANGEFS_ERROR_CLASS_BITS); | 609 | i = (-error_code) & ~(ORANGEFS_ERROR_BIT|ORANGEFS_ERROR_CLASS_BITS); |
609 | if (i < sizeof(PINT_errno_mapping)/sizeof(*PINT_errno_mapping)) | 610 | if (i < ARRAY_SIZE(PINT_errno_mapping)) |
610 | error_code = -PINT_errno_mapping[i]; | 611 | error_code = -PINT_errno_mapping[i]; |
611 | else | 612 | else |
612 | error_code = -EINVAL; | 613 | error_code = -EINVAL; |