diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c
index 9522a8b79d22..e613420cb079 100644
--- a/fs/btrfs/ref-verify.c
+++ b/fs/btrfs/ref-verify.c
@@ -1002,6 +1002,9 @@ int btrfs_build_ref_tree(struct btrfs_fs_info *fs_info)
  return -ENOMEM;
  extent_root = btrfs_extent_root(fs_info, 0);
+ if (!extent_root)
+ return -EBADF;
+
  eb = btrfs_read_lock_root_node(extent_root);
  level = btrfs_header_level(eb);
  path->nodes[level] = eb;