Skip to content

Commit 707d1a2

Browse files
committed
ext4: optimize __ext4_check_dir_entry()
Make __ext4_check_dir_entry() a bit easier to understand, and reduce the object size of the function by over 11%. Signed-off-by: Theodore Ts'o <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 109ba77 commit 707d1a2

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

fs/ext4/dir.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,19 @@ int __ext4_check_dir_entry(const char *function, unsigned int line,
7272
const char *error_msg = NULL;
7373
const int rlen = ext4_rec_len_from_disk(de->rec_len,
7474
dir->i_sb->s_blocksize);
75+
const int next_offset = ((char *) de - buf) + rlen;
7576

7677
if (unlikely(rlen < EXT4_DIR_REC_LEN(1)))
7778
error_msg = "rec_len is smaller than minimal";
7879
else if (unlikely(rlen % 4 != 0))
7980
error_msg = "rec_len % 4 != 0";
8081
else if (unlikely(rlen < EXT4_DIR_REC_LEN(de->name_len)))
8182
error_msg = "rec_len is too small for name_len";
82-
else if (unlikely(((char *) de - buf) + rlen > size))
83+
else if (unlikely(next_offset > size))
8384
error_msg = "directory entry overrun";
84-
else if (unlikely(((char *) de - buf) + rlen >
85-
size - EXT4_DIR_REC_LEN(1) &&
86-
((char *) de - buf) + rlen != size)) {
85+
else if (unlikely(next_offset > size - EXT4_DIR_REC_LEN(1) &&
86+
next_offset != size))
8787
error_msg = "directory entry too close to block end";
88-
}
8988
else if (unlikely(le32_to_cpu(de->inode) >
9089
le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count)))
9190
error_msg = "inode out of bounds";

0 commit comments

Comments
 (0)