From: Herton Ronaldo Krzesinski Date: Mon, 27 Aug 2012 23:56:54 +0000 (-0300) Subject: floppy: properly handle failure on add_disk loop X-Git-Tag: next-20120910~57^2~1^2^2~3 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=6932babe88ca5beec02b40db68100fc5ccb5d321;p=karo-tx-linux.git floppy: properly handle failure on add_disk loop On floppy initialization, if something failed inside the loop we call add_disk, there was no cleanup of previous iterations in the error handling. Cc: stable@vger.kernel.org Signed-off-by: Herton Ronaldo Krzesinski Signed-off-by: Jiri Kosina --- diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 32551f254054..2197c88b3cce 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -4293,7 +4293,7 @@ static int __init do_floppy_init(void) err = platform_device_register(&floppy_device[drive]); if (err) - goto out_release_dma; + goto out_remove_drives; err = device_create_file(&floppy_device[drive].dev, &dev_attr_cmos); @@ -4311,6 +4311,15 @@ static int __init do_floppy_init(void) out_unreg_platform_dev: platform_device_unregister(&floppy_device[drive]); +out_remove_drives: + while (drive--) { + if ((allowed_drive_mask & (1 << drive)) && + fdc_state[FDC(drive)].version != FDC_NONE) { + del_gendisk(disks[drive]); + device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos); + platform_device_unregister(&floppy_device[drive]); + } + } out_release_dma: if (atomic_read(&usage_count)) floppy_release_irq_and_dma();