]> git.hungrycats.org Git - linux/commitdiff
btrfs: handle NULL roots in btrfs_put/btrfs_grab_fs_root
authorJosef Bacik <josef@toxicpanda.com>
Thu, 21 Nov 2019 16:21:25 +0000 (08:21 -0800)
committerJosef Bacik <josef@toxicpanda.com>
Fri, 6 Dec 2019 16:34:48 +0000 (08:34 -0800)
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).

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
fs/btrfs/disk-io.h

index 5b38558e164de99b79ae08432d123a3f35dc0203..7e53da3747152aab28e1aa01624500366f22c0e7 100644 (file)
@@ -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);
 }