From patchwork Thu Oct 11 19:20:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637227 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE0BB112B for ; Thu, 11 Oct 2018 19:21:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF6862C05A for ; Thu, 11 Oct 2018 19:21:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD94B2C04E; Thu, 11 Oct 2018 19:21:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 500312C042 for ; Thu, 11 Oct 2018 19:21:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729564AbeJLCti (ORCPT ); Thu, 11 Oct 2018 22:49:38 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37412 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729706AbeJLCth (ORCPT ); Thu, 11 Oct 2018 22:49:37 -0400 Received: by mail-pl1-f194.google.com with SMTP id u6-v6so1951686plz.4 for ; Thu, 11 Oct 2018 12:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2Ie2tq/bgvbAoAevW4WXu14HcjbWRpIkuaJskCC0HTc=; b=ThuqMQJfP7J8IdWA89bVU1hxaBA03OkdiyKjUoTKLnTfPScKuGo0dRq5xR2ZutHHd5 +/ggxr2RMisU0ht1cqnXOtwstXblXlxKHp/8EGinHokVdnTVVH5F9mHbT26Sep6rWoFQ PxQmPjRa4J9rkSf4Qju27C9cN6Mftd0Gh3m8XhPKPTzdRxNKuA8GjPePT8GhoLtooqTK LJw5+lt4nupZfvvXV4IhJ4ivO6AzKsrY1hu6K9FmxmhK4ooTFBP0PzFyTgJnyiiY3NzN /AMtvzvsojsz5NHaTDzRtpzK+BX/QXqRJLm4cnY8iAcCxDGSAQNkcXcbqIGQ94XSwqfJ Cj9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2Ie2tq/bgvbAoAevW4WXu14HcjbWRpIkuaJskCC0HTc=; b=Llhdbxv2Xg4RJaI80Xq52hVde8fn4m3SmTShwgq1QY9jkOgKQj9ma0fz5+Kun8DZb+ 1k08p3mlTgaU4dvINqNQG6oa0+peFfKHmj7A/7FRA8CMenweRPOcD2vMfsW3erkQbXc8 JSE8b1LtarlOPmbkiQFpWWCXuomNGOOUPr/9zMVpYpBzLy7dUiNe+ZA+q5ySyNCI3l4S Jm+B/SOBTMOt8kjiQHe7/R4ToenHS5HUIx5NRewTIHvDe/arHNp1dwhqPOAWtD14Z/8L mD0zxU24kJmjVOcozQynxK32nGI7G8CvnaSIs+hpeqb2nMZdxgL49qBg2xiGMoYfJZ8Y BmVw== X-Gm-Message-State: ABuFfoidEFykfTlAbjArH/bOdYSRO4pETVzWSrjBmK5vlGoQNmmHzPfh EMRbAhrZFRyOFC1T/6OnlXwhjBLuEao= X-Google-Smtp-Source: ACcGV60KnqpQu8dOkna8ii4Aayz/ifzeF5pMsedb76ZzLgtBy4OWNOvBr1SadylmOjNd7iBfU/9tDg== X-Received: by 2002:a17:902:8c84:: with SMTP id t4-v6mr2810655plo.188.1539285662470; Thu, 11 Oct 2018 12:21:02 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id y24-v6sm44378838pfi.24.2018.10.11.12.21.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 12:21:02 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com Subject: [PATCH v2 06/11] amiflop: clean up on errors during setup Date: Thu, 11 Oct 2018 12:20:46 -0700 Message-Id: <431426cd663967c30423b104d79b2915d1a9dc3e.1539284959.git.osandov@fb.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval The error handling in fd_probe_drives() doesn't clean up at all. Fix it up in preparation for converting to blk-mq. While we're here, get rid of the commented out amiga_floppy_remove(). Signed-off-by: Omar Sandoval --- drivers/block/amiflop.c | 84 ++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 44 deletions(-) diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c index a7d6e6a9b12f..eef3b085e70a 100644 --- a/drivers/block/amiflop.c +++ b/drivers/block/amiflop.c @@ -1818,11 +1818,41 @@ static const struct block_device_operations floppy_fops = { .check_events = amiga_check_events, }; +static struct gendisk *fd_alloc_disk(int drive) +{ + struct gendisk *disk; + + disk = alloc_disk(1); + if (!disk) + goto out; + + disk->queue = blk_init_queue(do_fd_request, &amiflop_lock); + if (IS_ERR(disk->queue)) { + disk->queue = NULL; + goto out_put_disk; + } + + unit[drive].trackbuf = kmalloc(FLOPPY_MAX_SECTORS * 512, GFP_KERNEL); + if (!unit[drive].trackbuf) + goto out_cleanup_queue; + + return disk; + +out_cleanup_queue: + blk_cleanup_queue(disk->queue); + disk->queue = NULL; +out_put_disk: + put_disk(disk); +out: + unit[drive].type->code = FD_NODRIVE; + return NULL; +} + static int __init fd_probe_drives(void) { int drive,drives,nomem; - printk(KERN_INFO "FD: probing units\nfound "); + pr_info("FD: probing units\nfound"); drives=0; nomem=0; for(drive=0;drivecode == FD_NODRIVE) continue; - disk = alloc_disk(1); + + disk = fd_alloc_disk(drive); if (!disk) { - unit[drive].type->code = FD_NODRIVE; + pr_cont(" no mem for fd%d", drive); + nomem = 1; continue; } unit[drive].gendisk = disk; - - disk->queue = blk_init_queue(do_fd_request, &amiflop_lock); - if (!disk->queue) { - unit[drive].type->code = FD_NODRIVE; - continue; - } - drives++; - if ((unit[drive].trackbuf = kmalloc(FLOPPY_MAX_SECTORS * 512, GFP_KERNEL)) == NULL) { - printk("no mem for "); - unit[drive].type = &drive_types[num_dr_types - 1]; /* FD_NODRIVE */ - drives--; - nomem = 1; - } - printk("fd%d ",drive); + + pr_cont(" fd%d",drive); disk->major = FLOPPY_MAJOR; disk->first_minor = drive; disk->fops = &floppy_fops; @@ -1861,11 +1881,11 @@ static int __init fd_probe_drives(void) } if ((drives > 0) || (nomem == 0)) { if (drives == 0) - printk("no drives"); - printk("\n"); + pr_cont(" no drives"); + pr_cont("\n"); return drives; } - printk("\n"); + pr_cont("\n"); return -ENOMEM; } @@ -1948,30 +1968,6 @@ static int __init amiga_floppy_probe(struct platform_device *pdev) return ret; } -#if 0 /* not safe to unload */ -static int __exit amiga_floppy_remove(struct platform_device *pdev) -{ - int i; - - for( i = 0; i < FD_MAX_UNITS; i++) { - if (unit[i].type->code != FD_NODRIVE) { - struct request_queue *q = unit[i].gendisk->queue; - del_gendisk(unit[i].gendisk); - put_disk(unit[i].gendisk); - kfree(unit[i].trackbuf); - if (q) - blk_cleanup_queue(q); - } - } - blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); - free_irq(IRQ_AMIGA_CIAA_TB, NULL); - free_irq(IRQ_AMIGA_DSKBLK, NULL); - custom.dmacon = DMAF_DISK; /* disable DMA */ - amiga_chip_free(raw_buf); - unregister_blkdev(FLOPPY_MAJOR, "fd"); -} -#endif - static struct platform_driver amiga_floppy_driver = { .driver = { .name = "amiga-floppy",