summaryrefslogtreecommitdiff
path: root/fs/btrfs/disk-io.h
diff options
context:
space:
mode:
authorJosef Bacik <josef@toxicpanda.com>2020-01-24 17:32:26 +0300
committerDavid Sterba <dsterba@suse.com>2020-03-23 19:01:26 +0300
commit4cdfd93002cb84471ed85b4999cd38077a317873 (patch)
treec06cbe900b8e96ef07774238244e15d8550f6bb6 /fs/btrfs/disk-io.h
parenta98db0f304670dfd65375e6d0ea08793c174bf44 (diff)
downloadlinux-4cdfd93002cb84471ed85b4999cd38077a317873.tar.xz
btrfs: handle NULL roots in btrfs_put/btrfs_grab_fs_root
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>
Diffstat (limited to 'fs/btrfs/disk-io.h')
-rw-r--r--fs/btrfs/disk-io.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index 7aa1c7a3a115..8add2e14aab1 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -88,6 +88,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;
@@ -95,6 +97,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);
}