[PATCH] Btrfs: remove redundant judgment

cgel.zte@gmail.com posted 1 patch 4 years, 2 months ago
fs/btrfs/tree-log.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH] Btrfs: remove redundant judgment
Posted by cgel.zte@gmail.com 4 years, 2 months ago
From: Lv Ruyi <lv.ruyi@zte.com.cn>

iput() has already handled null and non-null parameter. so there 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/tree-log.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

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 redundant judgment
Posted by David Sterba 4 years, 2 months ago
On Wed, Apr 06, 2022 at 09:04:04AM +0000, cgel.zte@gmail.com wrote:
> From: Lv Ruyi <lv.ruyi@zte.com.cn>
> 
> iput() has already handled null and non-null parameter. so there is no
> need to use if().

Ok, we can drop the check, have you looked if there are more similar
places to update?
Re: [PATCH] Btrfs: remove redundant judgment
Posted by cgel.zte@gmail.com 4 years, 2 months ago
< Ok, we can drop the check, have you looked if there are more similar
< places to update?
I found six by coccinelle, but they are in different paths.Should I
send one patch or six?

Thanks
Lv Ruyi
Re: [PATCH] Btrfs: remove redundant judgment
Posted by David Sterba 4 years, 2 months ago
On Thu, Apr 07, 2022 at 01:57:00AM +0000, cgel.zte@gmail.com wrote:
> < Ok, we can drop the check, have you looked if there are more similar
> < places to update?
> I found six by coccinelle, but they are in different paths.Should I
> send one patch or six?

As this is a simple change it can be in one patch, provided that it's
the same logic (dropping inode check before iput).

I've found only 2 instances with this coccinelle script:

@@
expression E;
@@

* if (E)
*       iput(E);
--

not sure where you found 6.