diff options
author | Jérémy Lefaure <jeremy.lefaure@lse.epita.fr> | 2017-10-01 15:30:46 -0400 |
---|---|---|
committer | Tyler Hicks <tyhicks@canonical.com> | 2017-11-06 13:23:59 -0500 |
commit | 02f9876ebb5e9cd31013c62b8839508b2dc152f0 (patch) | |
tree | daba01fc309974a4da5457b2b5d382861a3a9594 | |
parent | 5032f360dd31e6cf59aadad0478df1244bfd30f8 (diff) |
ecryptfs: 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: Tyler Hicks <tyhicks@canonical.com>
-rw-r--r-- | fs/ecryptfs/crypto.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 1cd0902bc936..846ca150d52e 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/scatterlist.h> | 36 | #include <linux/scatterlist.h> |
37 | #include <linux/slab.h> | 37 | #include <linux/slab.h> |
38 | #include <asm/unaligned.h> | 38 | #include <asm/unaligned.h> |
39 | #include <linux/kernel.h> | ||
39 | #include "ecryptfs_kernel.h" | 40 | #include "ecryptfs_kernel.h" |
40 | 41 | ||
41 | #define DECRYPT 0 | 42 | #define DECRYPT 0 |
@@ -884,8 +885,7 @@ static int ecryptfs_process_flags(struct ecryptfs_crypt_stat *crypt_stat, | |||
884 | u32 flags; | 885 | u32 flags; |
885 | 886 | ||
886 | flags = get_unaligned_be32(page_virt); | 887 | flags = get_unaligned_be32(page_virt); |
887 | for (i = 0; i < ((sizeof(ecryptfs_flag_map) | 888 | for (i = 0; i < ARRAY_SIZE(ecryptfs_flag_map); i++) |
888 | / sizeof(struct ecryptfs_flag_map_elem))); i++) | ||
889 | if (flags & ecryptfs_flag_map[i].file_flag) { | 889 | if (flags & ecryptfs_flag_map[i].file_flag) { |
890 | crypt_stat->flags |= ecryptfs_flag_map[i].local_flag; | 890 | crypt_stat->flags |= ecryptfs_flag_map[i].local_flag; |
891 | } else | 891 | } else |
@@ -922,8 +922,7 @@ void ecryptfs_write_crypt_stat_flags(char *page_virt, | |||
922 | u32 flags = 0; | 922 | u32 flags = 0; |
923 | int i; | 923 | int i; |
924 | 924 | ||
925 | for (i = 0; i < ((sizeof(ecryptfs_flag_map) | 925 | for (i = 0; i < ARRAY_SIZE(ecryptfs_flag_map); i++) |
926 | / sizeof(struct ecryptfs_flag_map_elem))); i++) | ||
927 | if (crypt_stat->flags & ecryptfs_flag_map[i].local_flag) | 926 | if (crypt_stat->flags & ecryptfs_flag_map[i].local_flag) |
928 | flags |= ecryptfs_flag_map[i].file_flag; | 927 | flags |= ecryptfs_flag_map[i].file_flag; |
929 | /* Version is in top 8 bits of the 32-bit flag vector */ | 928 | /* Version is in top 8 bits of the 32-bit flag vector */ |