]> www.infradead.org Git - users/hch/block.git/commitdiff
pf: cleanup initialization blk_cleanup_disk
authorChristoph Hellwig <hch@lst.de>
Tue, 15 Jun 2021 09:39:56 +0000 (11:39 +0200)
committerChristoph Hellwig <hch@lst.de>
Sun, 8 Aug 2021 07:32:54 +0000 (09:32 +0200)
Refactor the pf initialization to have a dedicated helper to initialize
a single disk.

Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/block/paride/pf.c

index d5b9c88ba76faed23a2267df68573aab60379b50..9b85ab73782fcf4b6d902cd9a27a03f6e238c59c 100644 (file)
@@ -285,45 +285,6 @@ static const struct blk_mq_ops pf_mq_ops = {
        .queue_rq       = pf_queue_rq,
 };
 
-static void __init pf_init_units(void)
-{
-       struct pf_unit *pf;
-       int unit;
-
-       pf_drive_count = 0;
-       for (unit = 0, pf = units; unit < PF_UNITS; unit++, pf++) {
-               struct gendisk *disk;
-
-               if (blk_mq_alloc_sq_tag_set(&pf->tag_set, &pf_mq_ops, 1,
-                               BLK_MQ_F_SHOULD_MERGE))
-                       continue;
-
-               disk = blk_mq_alloc_disk(&pf->tag_set, pf);
-               if (IS_ERR(disk)) {
-                       blk_mq_free_tag_set(&pf->tag_set);
-                       continue;
-               }
-
-               INIT_LIST_HEAD(&pf->rq_list);
-               blk_queue_max_segments(disk->queue, cluster);
-               blk_queue_bounce_limit(disk->queue, BLK_BOUNCE_HIGH);
-               pf->disk = disk;
-               pf->pi = &pf->pia;
-               pf->media_status = PF_NM;
-               pf->drive = (*drives[unit])[D_SLV];
-               pf->lun = (*drives[unit])[D_LUN];
-               snprintf(pf->name, PF_NAMELEN, "%s%d", name, unit);
-               disk->major = major;
-               disk->first_minor = unit;
-               disk->minors = 1;
-               strcpy(disk->disk_name, pf->name);
-               disk->fops = &pf_fops;
-               disk->events = DISK_EVENT_MEDIA_CHANGE;
-               if (!(*drives[unit])[D_PRT])
-                       pf_drive_count++;
-       }
-}
-
 static int pf_open(struct block_device *bdev, fmode_t mode)
 {
        struct pf_unit *pf = bdev->bd_disk->private_data;
@@ -1014,6 +975,46 @@ static void do_pf_write_done(void)
        next_request(0);
 }
 
+static int __init pf_init_unit(struct pf_unit *pf)
+{
+       struct gendisk *disk;
+       int unit = pf - units;
+       int ret;
+
+       ret = blk_mq_alloc_sq_tag_set(&pf->tag_set, &pf_mq_ops, 1,
+                                     BLK_MQ_F_SHOULD_MERGE);
+       if (ret)
+               return ret;
+
+       disk = blk_mq_alloc_disk(&pf->tag_set, pf);
+       if (IS_ERR(disk)) {
+               ret = PTR_ERR(disk);
+               goto out_free_tag_set;
+       }
+       INIT_LIST_HEAD(&pf->rq_list);
+       blk_queue_max_segments(disk->queue, cluster);
+       blk_queue_bounce_limit(disk->queue, BLK_BOUNCE_HIGH);
+       pf->disk = disk;
+       pf->pi = &pf->pia;
+       pf->media_status = PF_NM;
+       pf->drive = (*drives[unit])[D_SLV];
+       pf->lun = (*drives[unit])[D_LUN];
+       snprintf(pf->name, PF_NAMELEN, "%s%d", name, unit);
+       disk->major = major;
+       disk->first_minor = unit;
+       disk->minors = 1;
+       strcpy(disk->disk_name, pf->name);
+       disk->fops = &pf_fops;
+       disk->events = DISK_EVENT_MEDIA_CHANGE;
+       if (!(*drives[unit])[D_PRT])
+               pf_drive_count++;
+       return 0;
+
+out_free_tag_set:
+       blk_mq_free_tag_set(&pf->tag_set);
+       return ret;
+}
+
 static int __init pf_init(void)
 {                              /* preliminary initialisation */
        struct pf_unit *pf;
@@ -1022,23 +1023,16 @@ static int __init pf_init(void)
        if (disable)
                return -EINVAL;
 
-       pf_init_units();
+       if (register_blkdev(major, name))
+               return -EBUSY;
+
+       for (unit = 0, pf = units; unit < PF_UNITS; unit++, pf++)
+               pf_init_unit(&units[unit]);
 
        if (pf_detect())
-               return -ENODEV;
+               goto out_unregister_blkdev;
        pf_busy = 0;
 
-       if (register_blkdev(major, name)) {
-               for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) {
-                       if (!pf->disk)
-                               continue;
-                       blk_cleanup_queue(pf->disk->queue);
-                       blk_mq_free_tag_set(&pf->tag_set);
-                       put_disk(pf->disk);
-               }
-               return -EBUSY;
-       }
-
        for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) {
                struct gendisk *disk = pf->disk;
 
@@ -1048,13 +1042,17 @@ static int __init pf_init(void)
                add_disk(disk);
        }
        return 0;
+
+out_unregister_blkdev:
+       unregister_blkdev(major, name);
+       return -ENODEV;
 }
 
 static void __exit pf_exit(void)
 {
        struct pf_unit *pf;
        int unit;
-       unregister_blkdev(major, name);
+
        for (pf = units, unit = 0; unit < PF_UNITS; pf++, unit++) {
                if (!pf->disk)
                        continue;
@@ -1069,6 +1067,8 @@ static void __exit pf_exit(void)
                if (pf->present)
                        pi_release(pf->pi);
        }
+
+       unregister_blkdev(major, name);
 }
 
 MODULE_LICENSE("GPL");