From patchwork Thu Dec 13 13:56:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [020/241] floppy: properly handle failure on add_disk loop Date: Thu, 13 Dec 2012 03:56:25 -0000 From: Herton Ronaldo Krzesinski X-Patchwork-Id: 205870 Message-Id: <1355407206-17100-21-git-send-email-herton.krzesinski@canonical.com> To: linux-kernel@vger.kernel.org, stable@vger.kernel.org, kernel-team@lists.ubuntu.com Cc: Jens Axboe , Jiri Kosina 3.5.7.2 -stable review patch. If anyone has any objections, please let me know. ------------------ From: Herton Ronaldo Krzesinski commit d60e7ec18c3fb2cbf90969ccd42889eb2d03aef9 upstream. On floppy initialization, if something failed inside the loop we call add_disk, there was no cleanup of previous iterations in the error handling. Signed-off-by: Jiri Kosina Signed-off-by: Jens Axboe Signed-off-by: Herton Ronaldo Krzesinski --- drivers/block/floppy.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 889f47e..7ad2489 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -4293,7 +4293,7 @@ static int __init 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 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();