[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200415114623.14972-9-sashal@kernel.org>
Date: Wed, 15 Apr 2020 07:45:52 -0400
From: Sasha Levin <sashal@...nel.org>
To: linux-kernel@...r.kernel.org, stable@...r.kernel.org
Cc: Josef Bacik <josef@...icpanda.com>,
Nikolay Borisov <nborisov@...e.com>,
David Sterba <dsterba@...e.com>,
Sasha Levin <sashal@...nel.org>, linux-btrfs@...r.kernel.org
Subject: [PATCH AUTOSEL 4.19 09/40] btrfs: handle NULL roots in btrfs_put/btrfs_grab_fs_root
From: Josef Bacik <josef@...icpanda.com>
[ Upstream commit 4cdfd93002cb84471ed85b4999cd38077a317873 ]
We want to use this for dropping all roots, and in some error cases we
may not have a root, so handle this to make the cleanup code easier.
Make btrfs_grab_fs_root the same so we can use it in cases where the
root may not exist (like the quota root).
Reviewed-by: Nikolay Borisov <nborisov@...e.com>
Signed-off-by: Josef Bacik <josef@...icpanda.com>
Reviewed-by: David Sterba <dsterba@...e.com>
Signed-off-by: David Sterba <dsterba@...e.com>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---
fs/btrfs/disk-io.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index 7a4a60f26dbf9..4f2d99fdf1e0c 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -100,6 +100,8 @@ struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info);
*/
static inline struct btrfs_root *btrfs_grab_fs_root(struct btrfs_root *root)
{
+ if (!root)
+ return NULL;
if (refcount_inc_not_zero(&root->refs))
return root;
return NULL;
@@ -107,6 +109,8 @@ static inline struct btrfs_root *btrfs_grab_fs_root(struct btrfs_root *root)
static inline void btrfs_put_fs_root(struct btrfs_root *root)
{
+ if (!root)
+ return;
if (refcount_dec_and_test(&root->refs))
kfree(root);
}
--
2.20.1
Powered by blists - more mailing lists