block: only bdi_unregister() in del_gendisk() if !GENHD_FL_HIDDEN
authorMike Snitzer <snitzer@redhat.com>
Wed, 10 Jan 2018 01:46:49 +0000 (20:46 -0500)
committerJens Axboe <axboe@kernel.dk>
Mon, 15 Jan 2018 15:41:38 +0000 (08:41 -0700)
device_add_disk() will only call bdi_register_owner() if
!GENHD_FL_HIDDEN, so it follows that del_gendisk() should only call
bdi_unregister() if !GENHD_FL_HIDDEN.

Found with code inspection.  bdi_unregister() won't do any harm if
bdi_register_owner() wasn't used but best to avoid the unnecessary
call to bdi_unregister().

Fixes: 8ddcd65325 ("block: introduce GENHD_FL_HIDDEN")
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/genhd.c

index 96a66f67172045d571be9fe18248dbefc99766ef..00620e01e043a0d19ad5672dea40e9831eaf8ec6 100644 (file)
@@ -725,7 +725,8 @@ void del_gendisk(struct gendisk *disk)
                 * Unregister bdi before releasing device numbers (as they can
                 * get reused and we'd get clashes in sysfs).
                 */
-               bdi_unregister(disk->queue->backing_dev_info);
+               if (!(disk->flags & GENHD_FL_HIDDEN))
+                       bdi_unregister(disk->queue->backing_dev_info);
                blk_unregister_queue(disk);
        } else {
                WARN_ON(1);