Skip to content

Commit e5dd68e

Browse files
rhvgoyalbwhacks
authored andcommitted
floppy: Cleanup disk->queue before caling put_disk() if add_disk() was never called
commit 3f9a5aa upstream. add_disk() takes gendisk reference on request queue. If driver failed during initialization and never called add_disk() then that extra reference is not taken. That reference is put in put_disk(). floppy driver allocates the disk, allocates queue, sets disk->queue and then relizes that floppy controller is not present. It tries to tear down everything and tries to put a reference down in put_disk() which was never taken. In such error cases cleanup disk->queue before calling put_disk() so that we never try to put down a reference which was never taken in first place. Reported-and-tested-by: Suresh Jayaraman <sjayaraman@suse.com> 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> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
1 parent b75bfc4 commit e5dd68e

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎drivers/block/floppy.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4369,8 +4369,14 @@ static int __init floppy_init(void)
43694369
out_put_disk:
43704370
while (dr--) {
43714371
del_timer_sync(&motor_off_timer[dr]);
4372-
if (disks[dr]->queue)
4372+
if (disks[dr]->queue) {
43734373
blk_cleanup_queue(disks[dr]->queue);
4374+
/*
4375+
* put_disk() is not paired with add_disk() and
4376+
* will put queue reference one extra time. fix it.
4377+
*/
4378+
disks[dr]->queue = NULL;
4379+
}
43744380
put_disk(disks[dr]);
43754381
}
43764382
return err;

0 commit comments

Comments
 (0)