Commit 8cd0f2ba authored by Jan Kara's avatar Jan Kara

ext2: Merge loops in ext2_xattr_set()

There are two very similar loops when searching xattr to set. Just merge
them.
Reviewed-by: default avatarChengguang Xu <cgxu519@zoho.com.cn>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent f4c3fb8c
...@@ -436,28 +436,12 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name, ...@@ -436,28 +436,12 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name,
error = -EIO; error = -EIO;
goto cleanup; goto cleanup;
} }
/* Find the named attribute. */ /*
here = FIRST_ENTRY(bh); * Find the named attribute. If not found, 'here' will point
while (!IS_LAST_ENTRY(here)) { * to entry where the new attribute should be inserted to
struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(here); * maintain sorting.
if ((char *)next >= end) */
goto bad_block; last = FIRST_ENTRY(bh);
if (!here->e_value_block && here->e_value_size) {
size_t offs = le16_to_cpu(here->e_value_offs);
if (offs < min_offs)
min_offs = offs;
}
not_found = name_index - here->e_name_index;
if (!not_found)
not_found = name_len - here->e_name_len;
if (!not_found)
not_found = memcmp(name, here->e_name,name_len);
if (not_found <= 0)
break;
here = next;
}
last = here;
/* We still need to compute min_offs and last. */
while (!IS_LAST_ENTRY(last)) { while (!IS_LAST_ENTRY(last)) {
struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(last); struct ext2_xattr_entry *next = EXT2_XATTR_NEXT(last);
if ((char *)next >= end) if ((char *)next >= end)
...@@ -467,8 +451,21 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name, ...@@ -467,8 +451,21 @@ ext2_xattr_set(struct inode *inode, int name_index, const char *name,
if (offs < min_offs) if (offs < min_offs)
min_offs = offs; min_offs = offs;
} }
if (not_found > 0) {
not_found = name_index - last->e_name_index;
if (!not_found)
not_found = name_len - last->e_name_len;
if (!not_found) {
not_found = memcmp(name, last->e_name,
name_len);
}
if (not_found <= 0)
here = last;
}
last = next; last = next;
} }
if (not_found > 0)
here = last;
/* Check whether we have enough space left. */ /* Check whether we have enough space left. */
free = min_offs - ((char*)last - (char*)header) - sizeof(__u32); free = min_offs - ((char*)last - (char*)header) - sizeof(__u32);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment