ret = PTR_ERR(local_root);
                goto err;
        }
+       if (!btrfs_grab_fs_root(local_root)) {
+               ret = -ENOENT;
+               goto err;
+       }
 
        /*
         * this makes the path point to (inum INODE_ITEM ioff)
 
        ret = btrfs_search_slot(NULL, local_root, &key, swarn->path, 0, 0);
        if (ret) {
+               btrfs_put_fs_root(local_root);
                btrfs_release_path(swarn->path);
                goto err;
        }
        ipath = init_ipath(4096, local_root, swarn->path);
        memalloc_nofs_restore(nofs_flag);
        if (IS_ERR(ipath)) {
+               btrfs_put_fs_root(local_root);
                ret = PTR_ERR(ipath);
                ipath = NULL;
                goto err;
                                  min(isize - offset, (u64)PAGE_SIZE), nlink,
                                  (char *)(unsigned long)ipath->fspath->val[i]);
 
+       btrfs_put_fs_root(local_root);
        free_ipath(ipath);
        return 0;