summaryrefslogtreecommitdiff
path: root/block/genhd.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2020-09-21 09:19:46 +0200
committerJens Axboe <axboe@kernel.dk>2020-09-23 10:43:19 -0600
commit9301fe734384990ef9a2463cb7aeb3b00bf5dad5 (patch)
tree2cfaa7c9ad519b65e74e6cf2a02a995b0b24c498 /block/genhd.c
parent38430f0876fa8b9549ec434f569dce03e057c076 (diff)
downloadlwn-9301fe734384990ef9a2463cb7aeb3b00bf5dad5.tar.gz
lwn-9301fe734384990ef9a2463cb7aeb3b00bf5dad5.zip
block: cleanup partition scanning in register_disk
Use blkdev_get_by_dev instead of open coding it using bdget_disk + blkdev_get, and split the code to read the partition table into a separate helper to make it a little more obvious. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/genhd.c')
-rw-r--r--block/genhd.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/block/genhd.c b/block/genhd.c
index 7b56203c90a3..05fb27cbb667 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -673,11 +673,23 @@ static int exact_lock(dev_t devt, void *data)
return 0;
}
+static void disk_scan_partitions(struct gendisk *disk)
+{
+ struct block_device *bdev;
+
+ if (!get_capacity(disk) || !disk_part_scan_enabled(disk))
+ return;
+
+ set_bit(GD_NEED_PART_SCAN, &disk->state);
+ bdev = blkdev_get_by_dev(disk_devt(disk), FMODE_READ, NULL);
+ if (!IS_ERR(bdev))
+ blkdev_put(bdev, FMODE_READ);
+}
+
static void register_disk(struct device *parent, struct gendisk *disk,
const struct attribute_group **groups)
{
struct device *ddev = disk_to_dev(disk);
- struct block_device *bdev;
struct disk_part_iter piter;
struct hd_struct *part;
int err;
@@ -719,25 +731,8 @@ static void register_disk(struct device *parent, struct gendisk *disk,
return;
}
- /* No minors to use for partitions */
- if (!disk_part_scan_enabled(disk))
- goto exit;
-
- /* No such device (e.g., media were just removed) */
- if (!get_capacity(disk))
- goto exit;
-
- bdev = bdget_disk(disk, 0);
- if (!bdev)
- goto exit;
-
- set_bit(GD_NEED_PART_SCAN, &disk->state);
- err = blkdev_get(bdev, FMODE_READ, NULL);
- if (err < 0)
- goto exit;
- blkdev_put(bdev, FMODE_READ);
+ disk_scan_partitions(disk);
-exit:
/* announce disk after possible partitions are created */
dev_set_uevent_suppress(ddev, 0);
kobject_uevent(&ddev->kobj, KOBJ_ADD);