2022-04-06 15:38:06

by CGEL

[permalink] [raw]
Subject: [PATCH] Btrfs: remove redundant judgment

From: Lv Ruyi <[email protected]>

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

Reported-by: Zeal Robot <[email protected]>
Signed-off-by: Lv Ruyi <[email protected]>
---
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


2022-04-06 16:38:58

by David Sterba

[permalink] [raw]
Subject: Re: [PATCH] Btrfs: remove redundant judgment

On Wed, Apr 06, 2022 at 09:04:04AM +0000, [email protected] wrote:
> From: Lv Ruyi <[email protected]>
>
> 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?

2022-04-07 15:27:51

by CGEL

[permalink] [raw]
Subject: Re: [PATCH] Btrfs: remove redundant judgment

< 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

2022-04-07 17:04:40

by David Sterba

[permalink] [raw]
Subject: Re: [PATCH] Btrfs: remove redundant judgment

On Thu, Apr 07, 2022 at 01:57:00AM +0000, [email protected] 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.