Skip to content

Commit 02f9876

Browse files
Jérémy Lefauretyhicks
authored andcommitted
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>
1 parent 5032f36 commit 02f9876

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

‎fs/ecryptfs/crypto.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/scatterlist.h>
3737
#include <linux/slab.h>
3838
#include <asm/unaligned.h>
39+
#include <linux/kernel.h>
3940
#include "ecryptfs_kernel.h"
4041

4142
#define DECRYPT 0
@@ -884,8 +885,7 @@ static int ecryptfs_process_flags(struct ecryptfs_crypt_stat *crypt_stat,
884885
u32 flags;
885886

886887
flags = get_unaligned_be32(page_virt);
887-
for (i = 0; i < ((sizeof(ecryptfs_flag_map)
888-
/ sizeof(struct ecryptfs_flag_map_elem))); i++)
888+
for (i = 0; i < ARRAY_SIZE(ecryptfs_flag_map); i++)
889889
if (flags & ecryptfs_flag_map[i].file_flag) {
890890
crypt_stat->flags |= ecryptfs_flag_map[i].local_flag;
891891
} else
@@ -922,8 +922,7 @@ void ecryptfs_write_crypt_stat_flags(char *page_virt,
922922
u32 flags = 0;
923923
int i;
924924

925-
for (i = 0; i < ((sizeof(ecryptfs_flag_map)
926-
/ sizeof(struct ecryptfs_flag_map_elem))); i++)
925+
for (i = 0; i < ARRAY_SIZE(ecryptfs_flag_map); i++)
927926
if (crypt_stat->flags & ecryptfs_flag_map[i].local_flag)
928927
flags |= ecryptfs_flag_map[i].file_flag;
929928
/* Version is in top 8 bits of the 32-bit flag vector */

0 commit comments

Comments
 (0)