* [PATCH AUTOSEL 4.14 09/30] btrfs: handle NULL roots in btrfs_put/btrfs_grab_fs_root
[not found] <20200415114711.15381-1-sashal@kernel.org>
@ 2020-04-15 11:46 ` Sasha Levin
0 siblings, 0 replies; only message in thread
From: Sasha Levin @ 2020-04-15 11:46 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Josef Bacik, Nikolay Borisov, David Sterba, Sasha Levin,
linux-btrfs
From: Josef Bacik <josef@toxicpanda.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@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.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 7f7c35d6347a3..4066220a980b2 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -109,6 +109,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;
@@ -116,6 +118,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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2020-04-15 11:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20200415114711.15381-1-sashal@kernel.org>
2020-04-15 11:46 ` [PATCH AUTOSEL 4.14 09/30] btrfs: handle NULL roots in btrfs_put/btrfs_grab_fs_root Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).