[PATCH v2] fs: remove unnecessary conditional

From: cgel . zte
Date: Thu Apr 07 2022 - 22:12:03 EST


From: Lv Ruyi <lv.ruyi@xxxxxxxxxx>

iput() has already handled null and non-null parameter, so it is no
need to use if().

This patch remove all unnecessary conditional in fs subsystem.
No functional changes.

Reported-by: Zeal Robot <zealci@xxxxxxxxxx>
Signed-off-by: Lv Ruyi <lv.ruyi@xxxxxxxxxx>
---
chang log: v1 -> v2
change subject from "remove redundant judgment" to
"remove unnecessary conditional", and combine into a patch.
---
fs/btrfs/relocation.c | 3 +--
fs/btrfs/tree-log.c | 3 +--
fs/cifs/dir.c | 3 +--
fs/efivarfs/inode.c | 3 +--
fs/ext4/fast_commit.c | 3 +--
fs/ext4/namei.c | 3 +--
fs/gfs2/super.c | 3 +--
fs/namei.c | 3 +--
8 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 50bdd82682fa..edddd93d2118 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3846,8 +3846,7 @@ struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info,
btrfs_end_transaction(trans);
btrfs_btree_balance_dirty(fs_info);
if (err) {
- if (inode)
- iput(inode);
+ iput(inode);
inode = ERR_PTR(err);
}
return inode;
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 273998153fcc..c46696896f03 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -894,8 +894,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
btrfs_update_inode_bytes(BTRFS_I(inode), nbytes, drop_args.bytes_found);
ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
out:
- if (inode)
- iput(inode);
+ iput(inode);
return ret;
}

diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index ce9b22aecfba..f952b50590e2 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -401,8 +401,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
out_err:
if (server->ops->close)
server->ops->close(xid, tcon, fid);
- if (newinode)
- iput(newinode);
+ iput(newinode);
goto out;
}

diff --git a/fs/efivarfs/inode.c b/fs/efivarfs/inode.c
index 939e5e242b98..ad2e5c63062a 100644
--- a/fs/efivarfs/inode.c
+++ b/fs/efivarfs/inode.c
@@ -119,8 +119,7 @@ static int efivarfs_create(struct user_namespace *mnt_userns, struct inode *dir,
out:
if (err) {
kfree(var);
- if (inode)
- iput(inode);
+ iput(inode);
}
return err;
}
diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
index 3d72565ec6e8..e85d351a1a31 100644
--- a/fs/ext4/fast_commit.c
+++ b/fs/ext4/fast_commit.c
@@ -1659,8 +1659,7 @@ static int ext4_fc_replay_create(struct super_block *sb, struct ext4_fc_tl *tl,
set_nlink(inode, 1);
ext4_mark_inode_dirty(NULL, inode);
out:
- if (inode)
- iput(inode);
+ iput(inode);
return ret;
}

diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index e37da8d5cd0c..2fd3b24a21cd 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -3363,8 +3363,7 @@ static int ext4_symlink(struct user_namespace *mnt_userns, struct inode *dir,
err = ext4_add_nondir(handle, dentry, &inode);
if (handle)
ext4_journal_stop(handle);
- if (inode)
- iput(inode);
+ iput(inode);
goto out_free_encrypted_link;

err_drop_inode:
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 90db4a289269..a1d94013b96d 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -1451,8 +1451,7 @@ extern void free_local_statfs_inodes(struct gfs2_sbd *sdp)
list_for_each_entry_safe(lsi, safe, &sdp->sd_sc_inodes_list, si_list) {
if (lsi->si_jid == sdp->sd_jdesc->jd_jid)
sdp->sd_sc_inode = NULL; /* belongs to this node */
- if (lsi->si_sc_inode)
- iput(lsi->si_sc_inode);
+ iput(lsi->si_sc_inode);
list_del(&lsi->si_list);
kfree(lsi);
}
diff --git a/fs/namei.c b/fs/namei.c
index 29414d1867fb..b1d93b2fc3b0 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4214,8 +4214,7 @@ int do_unlinkat(int dfd, struct filename *name)
dput(dentry);
}
inode_unlock(path.dentry->d_inode);
- if (inode)
- iput(inode); /* truncate the inode here */
+ iput(inode); /* truncate the inode here */
inode = NULL;
if (delegated_inode) {
error = break_deleg_wait(&delegated_inode);
--
2.25.1