From: Christoph Hellwig hch@lst.de
mainline inclusion from mainline-v5.10-rc1 commit 9301fe734384990ef9a2463cb7aeb3b00bf5dad5 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I6MRB5 CVE: NA
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
--------------------------------
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
Conflict: - this patch just factor out a helper, bdget_disk + blkdev_get is still used because 'bdev->bd_invalidated' need to be set. Signed-off-by: Yu Kuai yukuai3@huawei.com Reviewed-by: Hou Tao houtao1@huawei.com Signed-off-by: Yongqiang Liu liuyongqiang13@huawei.com --- block/genhd.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c index 4a748603c881..daf7211429c1 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -639,31 +639,30 @@ static void register_disk(struct device *parent, struct gendisk *disk) } }
-static void disk_init_partition(struct gendisk *disk) +static void disk_scan_partitions(struct gendisk *disk) { - struct device *ddev = disk_to_dev(disk); struct block_device *bdev; - struct disk_part_iter piter; - struct hd_struct *part;
- /* 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; + if (!get_capacity(disk) || !disk_part_scan_enabled(disk)) + return;
bdev = bdget_disk(disk, 0); if (!bdev) - goto exit; + return;
bdev->bd_invalidated = 1; - if (blkdev_get(bdev, FMODE_READ, NULL)) - goto exit; - blkdev_put(bdev, FMODE_READ); + if (!blkdev_get(bdev, FMODE_READ, NULL)) + blkdev_put(bdev, FMODE_READ); +} + +static void disk_init_partition(struct gendisk *disk) +{ + struct device *ddev = disk_to_dev(disk); + struct disk_part_iter piter; + struct hd_struct *part; + + disk_scan_partitions(disk);
-exit: /* announce disk after possible partitions are created */ dev_set_uevent_suppress(ddev, 0); kobject_uevent(&ddev->kobj, KOBJ_ADD);