swim: fix cleanup on setup error
authorOmar Sandoval <osandov@fb.com>
Thu, 11 Oct 2018 19:20:41 +0000 (12:20 -0700)
committerJens Axboe <axboe@kernel.dk>
Tue, 16 Oct 2018 15:49:08 +0000 (09:49 -0600)
If we fail to allocate the request queue for a disk, we still need to
free that disk, not just the previous ones. Additionally, we need to
cleanup the previous request queues.

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

index 0e31884a9519614398c1f1f6b048934a09ac5906..cbe909c51847db4fb6732980624b209855e6442e 100644 (file)
@@ -887,8 +887,17 @@ static int swim_floppy_init(struct swim_priv *swd)
 
 exit_put_disks:
        unregister_blkdev(FLOPPY_MAJOR, "fd");
-       while (drive--)
-               put_disk(swd->unit[drive].disk);
+       do {
+               struct gendisk *disk = swd->unit[drive].disk;
+
+               if (disk) {
+                       if (disk->queue) {
+                               blk_cleanup_queue(disk->queue);
+                               disk->queue = NULL;
+                       }
+                       put_disk(disk);
+               }
+       } while (drive--);
        return err;
 }