From: Zhang Yi Refactor the error handling in ext4_setattr() for better clarity: - Return directly on ext4_break_layouts() failure. - Propagate ext4_truncate() errors using the existing error variable and jump to the common 'err_out' label. - Propagate posix_acl_chmod() errors also through the error variable, as it theoretically does not return a non-fatal error. With these changes, every error path either returns immediately or jumps to err_out. Consequently, the "if (!error)" condition guarding setattr_copy() and mark_inode_dirty() becomes unreachable for error cases. Remove this redundant check and the unused rc variable can be removed as well. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 35e958f89bd5..b1ef706987c3 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5989,7 +5989,7 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr) { struct inode *inode = d_inode(dentry); - int error, rc = 0; + int error; int orphan = 0; const unsigned int ia_valid = attr->ia_valid; bool inc_ivers = true; @@ -6102,10 +6102,10 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry, filemap_invalidate_lock(inode->i_mapping); - rc = ext4_break_layouts(inode); - if (rc) { + error = ext4_break_layouts(inode); + if (error) { filemap_invalidate_unlock(inode->i_mapping); - goto err_out; + return error; } if (attr->ia_size > oldsize) @@ -6117,15 +6117,19 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry, } filemap_invalidate_unlock(inode->i_mapping); + if (error) + goto err_out; } - if (!error) { - if (inc_ivers) - inode_inc_iversion(inode); - setattr_copy(idmap, inode, attr); - mark_inode_dirty(inode); - } + if (inc_ivers) + inode_inc_iversion(inode); + setattr_copy(idmap, inode, attr); + mark_inode_dirty(inode); + if (ia_valid & ATTR_MODE) + error = posix_acl_chmod(idmap, dentry, inode->i_mode); + +err_out: /* * If the call to ext4_truncate failed to get a transaction handle at * all, we need to clean up the in-core orphan list manually. @@ -6133,14 +6137,8 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry, if (orphan && inode->i_nlink) ext4_orphan_del(NULL, inode); - if (!error && (ia_valid & ATTR_MODE)) - rc = posix_acl_chmod(idmap, dentry, inode->i_mode); - -err_out: - if (error) + if (error) ext4_std_error(inode->i_sb, error); - if (!error) - error = rc; return error; } -- 2.52.0