diff mbox series

[RFC,07/18] loop: use init disk helper

Message ID 20221005050027.39591-8-kch@nvidia.com (mailing list archive)
State New, archived
Headers show
Series block: add and use init disk helper | expand

Commit Message

Chaitanya Kulkarni Oct. 5, 2022, 5 a.m. UTC
Add and use the helper to initialize the common fields of struct gendisk
such as major, first_minor, minors, disk_name, private_data, and ops.
This initialization is spread all over the block drivers. This avoids
code repetation of inialization code of gendisk in current block drivers
and any future ones.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/loop.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index ad92192c7d61..82cdb57ecd18 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -2023,15 +2023,12 @@  static int loop_add(int i)
 	spin_lock_init(&lo->lo_work_lock);
 	INIT_WORK(&lo->rootcg_work, loop_rootcg_workfn);
 	INIT_LIST_HEAD(&lo->rootcg_cmd_list);
-	disk->major		= LOOP_MAJOR;
-	disk->first_minor	= i << part_shift;
-	disk->minors		= 1 << part_shift;
-	disk->fops		= &lo_fops;
-	disk->private_data	= lo;
 	disk->queue		= lo->lo_queue;
 	disk->events		= DISK_EVENT_MEDIA_CHANGE;
 	disk->event_flags	= DISK_EVENT_FLAG_UEVENT;
 	sprintf(disk->disk_name, "loop%d", i);
+	init_disk(disk, LOOP_MAJOR, i << part_shift, 1 << part_shift, 0, lo,
+			&lo_fops);
 	/* Make this loop device reachable from pathname. */
 	err = add_disk(disk);
 	if (err)