Re: [PATCH] btrfs: remove unnecessary conditional

From: Joe Perches
Date: Sun Apr 10 2022 - 23:27:57 EST


On Mon, 2022-04-11 at 03:22 +0000, cgel.zte@xxxxxxxxx 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;