summaryrefslogtreecommitdiffstats
path: root/fs/ext2
diff options
context:
space:
mode:
authorWang Sheng-Hui <shhuiw@gmail.com>2011-07-22 15:50:13 +0200
committerJan Kara <jack@suse.cz>2011-07-22 19:41:16 +0200
commit03b5bb342978f99f75fb36d69cd29bab32109fd4 (patch)
tree495099b74e217de7c322a1bf4737901a1efb8a3a /fs/ext2
parentext3: Fix compilation with -DDX_DEBUG (diff)
downloadlinux-03b5bb342978f99f75fb36d69cd29bab32109fd4.tar.xz
linux-03b5bb342978f99f75fb36d69cd29bab32109fd4.zip
ext2: check xattr name_len before acquiring xattr_sem in ext2_xattr_get
In ext2_xattr_get(), the code will acquire xattr_sem first, later checks the length of xattr name_len > 255. It's unnecessarily time consuming and also ext2_xattr_set() checks the length before other checks. So move the check before acquiring xattr_sem to make these two functions consistent. Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/ext2')
-rw-r--r--fs/ext2/xattr.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index 529970617a21..d27b71f1d183 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -161,6 +161,10 @@ ext2_xattr_get(struct inode *inode, int name_index, const char *name,
if (name == NULL)
return -EINVAL;
+ name_len = strlen(name);
+ if (name_len > 255)
+ return -ERANGE;
+
down_read(&EXT2_I(inode)->xattr_sem);
error = -ENODATA;
if (!EXT2_I(inode)->i_file_acl)
@@ -181,12 +185,8 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_get",
error = -EIO;
goto cleanup;
}
- /* find named attribute */
- name_len = strlen(name);
- error = -ERANGE;
- if (name_len > 255)
- goto cleanup;
+ /* find named attribute */
entry = FIRST_ENTRY(bh);
while (!IS_LAST_ENTRY(entry)) {
struct ext2_xattr_entry *next =