Skip to content

Commit

Permalink
block: fix leaking minors of hidden disks
Browse files Browse the repository at this point in the history
The major/minor of a hidden gendisk is not propagated to the block
device because it is never registered using bdev_add.  But the lack of
bd_dev also causes the dynamic major minor number not to be freed.
Assign bd_dev manually to ensure the dynamic major minor gets freed.

Based on a patch by Keith Busch.

Fixes: 8ddcd65 ("block: introduce GENHD_FL_HIDDEN")
Reported-by: Daniel Wagner <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
Tested-by: Daniel Wagner <[email protected]>
Reviewed-by: Keith Busch <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Oct 10, 2022
1 parent ca5eebd commit a0a6314
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,13 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
*/
dev_set_uevent_suppress(ddev, 0);
disk_uevent(disk, KOBJ_ADD);
} else {
/*
* Even if the block_device for a hidden gendisk is not
* registered, it needs to have a valid bd_dev so that the
* freeing of the dynamic major works.
*/
disk->part0->bd_dev = MKDEV(disk->major, disk->first_minor);
}

disk_update_readahead(disk);
Expand Down

0 comments on commit a0a6314

Please sign in to comment.