diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 5b5cbfadd003..68ebc2759c2e 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -775,7 +775,9 @@ static void bcache_device_free(struct bcache_device *d) bcache_device_detach(d); if (disk) { - if (disk->flags & GENHD_FL_UP) + bool disk_added = (disk->flags & GENHD_FL_UP) != 0; + + if (disk_added) del_gendisk(disk); if (disk->queue) @@ -783,7 +785,8 @@ static void bcache_device_free(struct bcache_device *d) ida_simple_remove(&bcache_device_idx, first_minor_to_idx(disk->first_minor)); - put_disk(disk); + if (disk_added) + put_disk(disk); } bioset_exit(&d->bio_split);