This moves quite a bit of code which does one thing into a helper. We currently do not check for errors but we may decide that might be desirable later. This also makes the code easier to read. Signed-off-by: Luis Chamberlain <mcgrof@xxxxxxxxxx> --- block/genhd.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 5f7faaf9cc83..091208f5f27b 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -701,13 +701,29 @@ static int exact_lock(dev_t devt, void *data) return 0; } +static void disk_announce(struct gendisk *disk) +{ + struct device *ddev = disk_to_dev(disk); + struct disk_part_iter piter; + struct hd_struct *part; + + /* announce disk after possible partitions are created */ + dev_set_uevent_suppress(ddev, 0); + kobject_uevent(&ddev->kobj, KOBJ_ADD); + + /* announce possible partitions */ + disk_part_iter_init(&piter, disk, 0); + while ((part = disk_part_iter_next(&piter))) + kobject_uevent(&part_to_dev(part)->kobj, KOBJ_ADD); + disk_part_iter_exit(&piter); +} + 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; ddev->parent = parent; @@ -766,15 +782,7 @@ static void register_disk(struct device *parent, struct gendisk *disk, blkdev_put(bdev, FMODE_READ); exit: - /* announce disk after possible partitions are created */ - dev_set_uevent_suppress(ddev, 0); - kobject_uevent(&ddev->kobj, KOBJ_ADD); - - /* announce possible partitions */ - disk_part_iter_init(&piter, disk, 0); - while ((part = disk_part_iter_next(&piter))) - kobject_uevent(&part_to_dev(part)->kobj, KOBJ_ADD); - disk_part_iter_exit(&piter); + disk_announce(disk); if (disk->queue->backing_dev_info->dev) { err = sysfs_create_link(&ddev->kobj, -- 2.25.1