* [PATCH 2/3] ext4: remove unnecessary assignments in xattr.c
2011-11-07 13:32 [PATCH 0/3] ext4: cleanup xattr stuff Zheng Liu
2011-11-07 13:32 ` [PATCH 1/3] ext4: remove 'error' variable in ext4_xattr_check_block() Zheng Liu
@ 2011-11-07 13:32 ` Zheng Liu
2012-02-13 23:21 ` Ted Ts'o
2011-11-07 13:32 ` [PATCH 3/3] ext4: initialize 'error' variable in ext4_xattr_block_find() Zheng Liu
2 siblings, 1 reply; 6+ messages in thread
From: Zheng Liu @ 2011-11-07 13:32 UTC (permalink / raw)
To: linux-ext4; +Cc: Zheng Liu
From: Zheng Liu <wenqing.lz@taobao.com>
In some functions, 'error' variable is assigned but not used when the result
of if statement is false.
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
---
fs/ext4/xattr.c | 64 +++++++++++++++++++++++++++++++++---------------------
1 files changed, 39 insertions(+), 25 deletions(-)
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 1bff752..e985864 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -214,13 +214,16 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
ea_idebug(inode, "name=%d.%s, buffer=%p, buffer_size=%ld",
name_index, name, buffer, (long)buffer_size);
- error = -ENODATA;
- if (!EXT4_I(inode)->i_file_acl)
+ if (!EXT4_I(inode)->i_file_acl) {
+ error = -ENODATA;
goto cleanup;
+ }
ea_idebug(inode, "reading block %u", EXT4_I(inode)->i_file_acl);
bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
- if (!bh)
+ if (!bh) {
+ error = -ENODATA;
goto cleanup;
+ }
ea_bdebug(bh, "b_count=%d, refcount=%d",
atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
if (ext4_xattr_check_block(bh)) {
@@ -239,9 +242,10 @@ bad_block:
goto cleanup;
size = le32_to_cpu(entry->e_value_size);
if (buffer) {
- error = -ERANGE;
- if (size > buffer_size)
+ if (size > buffer_size) {
+ error = -ERANGE;
goto cleanup;
+ }
memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
size);
}
@@ -282,9 +286,10 @@ ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
goto cleanup;
size = le32_to_cpu(entry->e_value_size);
if (buffer) {
- error = -ERANGE;
- if (size > buffer_size)
+ if (size > buffer_size) {
+ error = -ERANGE;
goto cleanup;
+ }
memcpy(buffer, (void *)IFIRST(header) +
le16_to_cpu(entry->e_value_offs), size);
}
@@ -357,14 +362,16 @@ ext4_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size)
ea_idebug(inode, "buffer=%p, buffer_size=%ld",
buffer, (long)buffer_size);
- error = 0;
- if (!EXT4_I(inode)->i_file_acl)
+ if (!EXT4_I(inode)->i_file_acl) {
+ error = 0;
goto cleanup;
+ }
ea_idebug(inode, "reading block %u", EXT4_I(inode)->i_file_acl);
bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
- error = -EIO;
- if (!bh)
+ if (!bh) {
+ error = -EIO;
goto cleanup;
+ }
ea_bdebug(bh, "b_count=%d, refcount=%d",
atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
if (ext4_xattr_check_block(bh)) {
@@ -653,9 +660,10 @@ ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
if (EXT4_I(inode)->i_file_acl) {
/* The inode already has an extended attribute block. */
bs->bh = sb_bread(sb, EXT4_I(inode)->i_file_acl);
- error = -EIO;
- if (!bs->bh)
+ if (!bs->bh) {
+ error = -EIO;
goto cleanup;
+ }
ea_bdebug(bs->bh, "b_count=%d, refcount=%d",
atomic_read(&(bs->bh->b_count)),
le32_to_cpu(BHDR(bs->bh)->h_refcount));
@@ -739,9 +747,10 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
}
ea_bdebug(bs->bh, "cloning");
s->base = kmalloc(bs->bh->b_size, GFP_NOFS);
- error = -ENOMEM;
- if (s->base == NULL)
+ if (s->base == NULL) {
+ error = -ENOMEM;
goto cleanup;
+ }
memcpy(s->base, BHDR(bs->bh), bs->bh->b_size);
s->first = ENTRY(header(s->base)+1);
header(s->base)->h_refcount = cpu_to_le32(1);
@@ -752,9 +761,10 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
/* Allocate a buffer where we construct the new block. */
s->base = kzalloc(sb->s_blocksize, GFP_NOFS);
/* assert(header == s->base) */
- error = -ENOMEM;
- if (s->base == NULL)
+ if (s->base == NULL) {
+ error = -ENOMEM;
goto cleanup;
+ }
header(s->base)->h_magic = cpu_to_le32(EXT4_XATTR_MAGIC);
header(s->base)->h_blocks = cpu_to_le32(1);
header(s->base)->h_refcount = cpu_to_le32(1);
@@ -1006,16 +1016,19 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
if (error)
goto cleanup;
if (is.s.not_found && bs.s.not_found) {
- error = -ENODATA;
- if (flags & XATTR_REPLACE)
+ if (flags & XATTR_REPLACE) {
+ error = -ENODATA;
goto cleanup;
- error = 0;
- if (!value)
+ }
+ if (!value) {
+ error = 0;
goto cleanup;
+ }
} else {
- error = -EEXIST;
- if (flags & XATTR_CREATE)
+ if (flags & XATTR_CREATE) {
+ error = -EEXIST;
goto cleanup;
+ }
}
if (!value) {
if (!is.s.not_found)
@@ -1186,9 +1199,10 @@ retry:
*/
if (EXT4_I(inode)->i_file_acl) {
bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
- error = -EIO;
- if (!bh)
+ if (!bh) {
+ error = -EIO;
goto cleanup;
+ }
if (ext4_xattr_check_block(bh)) {
EXT4_ERROR_INODE(inode, "bad block %llu",
EXT4_I(inode)->i_file_acl);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/3] ext4: initialize 'error' variable in ext4_xattr_block_find()
2011-11-07 13:32 [PATCH 0/3] ext4: cleanup xattr stuff Zheng Liu
2011-11-07 13:32 ` [PATCH 1/3] ext4: remove 'error' variable in ext4_xattr_check_block() Zheng Liu
2011-11-07 13:32 ` [PATCH 2/3] ext4: remove unnecessary assignments in xattr.c Zheng Liu
@ 2011-11-07 13:32 ` Zheng Liu
2 siblings, 0 replies; 6+ messages in thread
From: Zheng Liu @ 2011-11-07 13:32 UTC (permalink / raw)
To: linux-ext4; +Cc: Zheng Liu
From: Zheng Liu <wenqing.lz@taobao.com>
'error' variable is initialized to 0 to avoid a assignment in
ext4_xattr_block_find().
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
---
fs/ext4/xattr.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index e985864..bd67d0a 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -652,7 +652,7 @@ ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
struct ext4_xattr_block_find *bs)
{
struct super_block *sb = inode->i_sb;
- int error;
+ int error = 0;
ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
i->name_index, i->name, i->value, (long)i->value_len);
@@ -684,7 +684,6 @@ ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
goto cleanup;
bs->s.not_found = error;
}
- error = 0;
cleanup:
return error;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 6+ messages in thread