[PATCH v3 03/22] ext4: simplify error handling in ext4_setattr()
From: Zhang Yi
Date: Tue Apr 21 2026 - 22:19:01 EST
From: Zhang Yi <yi.zhang@xxxxxxxxxx>
Remove the redundant rc variable and consolidate error handling.
Signed-off-by: Zhang Yi <yi.zhang@xxxxxxxxxx>
---
fs/ext4/inode.c | 37 ++++++++++++++++---------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 5e913aca6499..59405a95ecfc 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5960,7 +5960,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;
@@ -6073,8 +6073,8 @@ 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;
}
@@ -6096,22 +6096,23 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
* Call ext4_truncate() even if i_size didn't change to
* truncate possible preallocated blocks.
*/
- if (attr->ia_size <= oldsize) {
- rc = ext4_truncate(inode);
- if (rc)
- error = rc;
- }
+ if (attr->ia_size <= oldsize)
+ error = ext4_truncate(inode);
out_mmap_sem:
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.
@@ -6119,14 +6120,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