--- x/fs/btrfs/super.c +++ y/fs/btrfs/super.c @@ -1644,6 +1644,7 @@ static struct dentry *btrfs_mount_root(s void *new_sec_opts = NULL; fmode_t mode = FMODE_READ; int error = 0; + int closed = 0; if (!(flags & SB_RDONLY)) mode |= FMODE_WRITE; @@ -1712,6 +1713,7 @@ static struct dentry *btrfs_mount_root(s } if (s->s_root) { + closed = 1; btrfs_close_devices(fs_devices); btrfs_free_fs_info(fs_info); if ((flags ^ s->s_flags) & SB_RDONLY) @@ -1727,6 +1729,8 @@ static struct dentry *btrfs_mount_root(s error = security_sb_set_mnt_opts(s, new_sec_opts, 0, NULL); security_free_mnt_opts(&new_sec_opts); if (error) { + if (!closed) + btrfs_close_devices(fs_devices); deactivate_locked_super(s); return ERR_PTR(error); }