From: Jérémy Lefaure Date: Sun, 1 Oct 2017 19:30:46 +0000 (-0400) Subject: ecryptfs: use ARRAY_SIZE X-Git-Tag: v4.15-rc1~61^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=02f9876ebb5e9cd31013c62b8839508b2dc152f0;p=thirdparty%2Fkernel%2Flinux.git 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 Signed-off-by: Tyler Hicks --- diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 1cd0902bc936d..846ca150d52e9 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "ecryptfs_kernel.h" #define DECRYPT 0 @@ -884,8 +885,7 @@ static int ecryptfs_process_flags(struct ecryptfs_crypt_stat *crypt_stat, u32 flags; flags = get_unaligned_be32(page_virt); - for (i = 0; i < ((sizeof(ecryptfs_flag_map) - / sizeof(struct ecryptfs_flag_map_elem))); i++) + for (i = 0; i < ARRAY_SIZE(ecryptfs_flag_map); i++) if (flags & ecryptfs_flag_map[i].file_flag) { crypt_stat->flags |= ecryptfs_flag_map[i].local_flag; } else @@ -922,8 +922,7 @@ void ecryptfs_write_crypt_stat_flags(char *page_virt, u32 flags = 0; int i; - for (i = 0; i < ((sizeof(ecryptfs_flag_map) - / sizeof(struct ecryptfs_flag_map_elem))); i++) + for (i = 0; i < ARRAY_SIZE(ecryptfs_flag_map); i++) if (crypt_stat->flags & ecryptfs_flag_map[i].local_flag) flags |= ecryptfs_flag_map[i].file_flag; /* Version is in top 8 bits of the 32-bit flag vector */