diff mbox series

[1/2] btrfs: fix double iput() on inode after an error during orphan cleanup

Message ID e20676cb8b120f12892f1e6ed80d91ec551ed533.1688403622.git.fdmanana@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: fix error paths of btrfs_orphan_cleanup() | expand

Commit Message

Filipe Manana July 3, 2023, 5:15 p.m. UTC
From: Filipe Manana <fdmanana@suse.com>

At btrfs_orphan_cleanup(), if we were able to find the inode, we do an
iput() on the inode, then if btrfs_drop_verity_items() succeeds and then
either btrfs_start_transaction() or btrfs_del_orphan_item() fail, we do
another iput() in the respective error paths, resulting in an extra iput()
on the inode.

Fix this by setting inode to NULL after the first iput(), as iput()
ignores a NULL inode pointer argument.

Fixes: a13bb2c03848 ("btrfs: add missing iputs on orphan cleanup failure")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/inode.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Boris Burkov July 7, 2023, 8:26 p.m. UTC | #1
On Mon, Jul 03, 2023 at 06:15:30PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> At btrfs_orphan_cleanup(), if we were able to find the inode, we do an
> iput() on the inode, then if btrfs_drop_verity_items() succeeds and then
> either btrfs_start_transaction() or btrfs_del_orphan_item() fail, we do
> another iput() in the respective error paths, resulting in an extra iput()
> on the inode.
> 
> Fix this by setting inode to NULL after the first iput(), as iput()
> ignores a NULL inode pointer argument.
> 
> Fixes: a13bb2c03848 ("btrfs: add missing iputs on orphan cleanup failure")
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Boris Burkov <boris@bur.io>
> ---
>  fs/btrfs/inode.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index dbbb67293e34..d919318d2498 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -3728,6 +3728,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
>  			if (!ret) {
>  				ret = btrfs_drop_verity_items(BTRFS_I(inode));
>  				iput(inode);
> +				inode = NULL;
>  				if (ret)
>  					goto out;
>  			}
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index dbbb67293e34..d919318d2498 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3728,6 +3728,7 @@  int btrfs_orphan_cleanup(struct btrfs_root *root)
 			if (!ret) {
 				ret = btrfs_drop_verity_items(BTRFS_I(inode));
 				iput(inode);
+				inode = NULL;
 				if (ret)
 					goto out;
 			}