ataflop: fix error handling during setup
authorOmar Sandoval <osandov@fb.com>
Thu, 11 Oct 2018 19:20:49 +0000 (12:20 -0700)
committerJens Axboe <axboe@kernel.dk>
Tue, 16 Oct 2018 15:50:03 +0000 (09:50 -0600)
Move queue allocation next to disk allocation to fix a couple of issues:

- If add_disk() hasn't been called, we should clear disk->queue before
  calling put_disk().
- If we fail to allocate a request queue, we still need to put all of
  the disks, not just the ones that we allocated queues for.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/ataflop.c

index 17df631c5d8591e26528f2f309bef15e6d55a845..0144d598ac4786952a9ad7ddf03bab263b8e7393 100644 (file)
@@ -2014,6 +2014,11 @@ static int __init atari_floppy_init (void)
                unit[i].disk = alloc_disk(1);
                if (!unit[i].disk)
                        goto Enomem;
+
+               unit[i].disk->queue = blk_init_queue(do_fd_request,
+                                                    &ataflop_lock);
+               if (!unit[i].disk->queue)
+                       goto Enomem;
        }
 
        if (UseTrackbuffer < 0)
@@ -2045,10 +2050,6 @@ static int __init atari_floppy_init (void)
                sprintf(unit[i].disk->disk_name, "fd%d", i);
                unit[i].disk->fops = &floppy_fops;
                unit[i].disk->private_data = &unit[i];
-               unit[i].disk->queue = blk_init_queue(do_fd_request,
-                                       &ataflop_lock);
-               if (!unit[i].disk->queue)
-                       goto Enomem;
                set_capacity(unit[i].disk, MAX_DISK_SIZE * 2);
                add_disk(unit[i].disk);
        }
@@ -2063,13 +2064,17 @@ static int __init atari_floppy_init (void)
 
        return 0;
 Enomem:
-       while (i--) {
-               struct request_queue *q = unit[i].disk->queue;
+       do {
+               struct gendisk *disk = unit[i].disk;
 
-               put_disk(unit[i].disk);
-               if (q)
-                       blk_cleanup_queue(q);
-       }
+               if (disk) {
+                       if (disk->queue) {
+                               blk_cleanup_queue(disk->queue);
+                               disk->queue = NULL;
+                       }
+                       put_disk(unit[i].disk);
+               }
+       } while (i--);
 
        unregister_blkdev(FLOPPY_MAJOR, "fd");
        return -ENOMEM;