[PATCH] btrfs: remove unnecessary conditional

cgel.zte@gmail.com posted 1 patch 4 years, 1 month ago
fs/btrfs/relocation.c | 3 +--
fs/btrfs/tree-log.c   | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
[PATCH] btrfs: remove unnecessary conditional
Posted by cgel.zte@gmail.com 4 years, 1 month ago
From: Lv Ruyi <lv.ruyi@zte.com.cn>

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

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
---
 fs/btrfs/relocation.c | 3 +--
 fs/btrfs/tree-log.c   | 3 +--
 2 files changed, 2 insertions(+), 4 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;
 }
 
-- 
2.25.1
Re: [PATCH] btrfs: remove unnecessary conditional
Posted by David Sterba 4 years ago
On Mon, Apr 11, 2022 at 03:22:52AM +0000, cgel.zte@gmail.com wrote:
> From: Lv Ruyi <lv.ruyi@zte.com.cn>
> 
> iput() has already handled null and non-null parameter, so it is no
> need to use if().
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>

Thanks, I've applied this version.
Re: [PATCH] btrfs: remove unnecessary conditional
Posted by Joe Perches 4 years, 1 month ago
On Mon, 2022-04-11 at 03:22 +0000, cgel.zte@gmail.com wrote:
> iput() has already handled null and non-null parameter, so it is no
> need to use if().
[]
> diff --git 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;

I think a direct return would be easier to understand.

	if (err) {
		iput(inode);
		return ERR_PTR(err);
	}

	return inode;