lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20230908082456.25983-1-work@onurozkan.dev>
Date:   Fri,  8 Sep 2023 11:24:56 +0300
From:   onur-ozkan <work@...rozkan.dev>
To:     tytso@....edu
Cc:     linux-ext4@...r.kernel.org, linux-kernel@...r.kernel.org,
        onur-ozkan <work@...rozkan.dev>
Subject: [PATCH] fs: micro optimizations in ext4/xattr

Improve the `ext4_xattr_inode_read` function slightly by using the
constant literal(from `MAX_BHS_SIZE`) for the `bhs_inline` initialization
and in the size checking condition as a replacement for `ARRAY_SIZE`.

Additionally, in the `ext4_xattr_cmp function, remove the `if` block to
improve code readability and clarity.

Signed-off-by: onur-ozkan <work@...rozkan.dev>
---
 fs/ext4/xattr.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 92ba28cebac6..e749aab8a152 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -376,6 +376,8 @@ static void ext4_xattr_inode_set_hash(struct inode *ea_inode, u32 hash)
 	ea_inode->i_atime.tv_sec = hash;
 }
 
+#define MAX_BHS_SIZE 8
+
 /*
  * Read the EA value from an inode.
  */
@@ -384,11 +386,11 @@ static int ext4_xattr_inode_read(struct inode *ea_inode, void *buf, size_t size)
 	int blocksize = 1 << ea_inode->i_blkbits;
 	int bh_count = (size + blocksize - 1) >> ea_inode->i_blkbits;
 	int tail_size = (size % blocksize) ?: blocksize;
-	struct buffer_head *bhs_inline[8];
+	struct buffer_head *bhs_inline[MAX_BHS_SIZE];
 	struct buffer_head **bhs = bhs_inline;
 	int i, ret;
 
-	if (bh_count > ARRAY_SIZE(bhs_inline)) {
+	if (bh_count > MAX_BHS_SIZE) {
 		bhs = kmalloc_array(bh_count, sizeof(*bhs), GFP_NOFS);
 		if (!bhs)
 			return -ENOMEM;
@@ -3093,9 +3095,8 @@ ext4_xattr_cmp(struct ext4_xattr_header *header1,
 		entry1 = EXT4_XATTR_NEXT(entry1);
 		entry2 = EXT4_XATTR_NEXT(entry2);
 	}
-	if (!IS_LAST_ENTRY(entry2))
-		return 1;
-	return 0;
+
+	return (IS_LAST_ENTRY(entry2)) ? 0 : 1;
 }
 
 /*
-- 
2.42.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ