floppy: Fix a crash during rmmod
authorVivek Goyal <vgoyal@redhat.com>
Wed, 8 Feb 2012 19:03:39 +0000 (20:03 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 8 Feb 2012 19:03:39 +0000 (20:03 +0100)
floppy driver does not call add_disk() on all the drives hence we don't take
gendisk reference on request queue for these drives. Don't call put_disk()
with disk->queue set, otherwise we try to put the reference we never took.

Reported-and-tested-by: Dirk Gouders <gouders@et.bocholt.fh-gelsenkirchen.de>
Signed-off-by: Vivek Goyal<vgoyal@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/floppy.c

index 401ba7833212cd031b3138ebc2a7f68d4e6cd053..9baf11e8636205c413bd5c00498baab628657b44 100644 (file)
@@ -4585,6 +4585,15 @@ static void __exit floppy_module_exit(void)
                        platform_device_unregister(&floppy_device[drive]);
                }
                blk_cleanup_queue(disks[drive]->queue);
+
+               /*
+                * These disks have not called add_disk().  Don't put down
+                * queue reference in put_disk().
+                */
+               if (!(allowed_drive_mask & (1 << drive)) ||
+                   fdc_state[FDC(drive)].version == FDC_NONE)
+                       disks[drive]->queue = NULL;
+
                put_disk(disks[drive]);
        }