From patchwork Thu Oct 11 18:30:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637089 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 78E5369B1 for ; Thu, 11 Oct 2018 18:30:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AB8A2BEA4 for ; Thu, 11 Oct 2018 18:30:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 687B02BEC1; Thu, 11 Oct 2018 18:30:41 +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 D19502BEB6 for ; Thu, 11 Oct 2018 18:30:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729119AbeJLB7E (ORCPT ); Thu, 11 Oct 2018 21:59:04 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44134 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729126AbeJLB7D (ORCPT ); Thu, 11 Oct 2018 21:59:03 -0400 Received: by mail-pg1-f193.google.com with SMTP id g2-v6so4559750pgu.11 for ; Thu, 11 Oct 2018 11:30:39 -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=1XN1LWsZsF9oaS5oMVL5qGAnAmhGwbO2jFh4zUORlt8=; b=0yyXl8ncDZjonmTftnrc9EqthIIZgxHHLZYB7vbXbP/qhb3aZjxmbTH0t1Z8ePOq1B 42IgixrUeDVY+lGVq0wGsJ7L8RtU+hGxJLnAdsrf4oLMDNioIahc5Iob86XsFUQwdmRu dhv3U8Z1Y7BqcWVhUlUBKbm2g3JZB459YsHY4sQIMV6H3OOukZXDbmihDvpCiYlAY/ho r9pphZpXPC/lOXPxSXiHDlDHqbsu7qcFxzn+xHwSqUh8rvMP/bQH+hgg6vnvyIEHNl1G TEwKYlMIQQxbWFHzK7hdCXBAXKR1DThzomAAgqgnjqLqHPCCk7zVzOoti0PkayMXWHSC 89mg== 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=1XN1LWsZsF9oaS5oMVL5qGAnAmhGwbO2jFh4zUORlt8=; b=gUo2h8csfKoAEhNsXzv6dpF2B962Sg9nWO+XaWoCp9cGXwYGz/E5oe7oRjO+md30Tt T8xfwVOuKpxVQRCNc3qP7BeLmgw9jtiY7AFgAml82p8F/HY5Ey+mCbqlC5lQC5ckZh4M x0Abx5yucziO4+dNMPqMGl699fpF10bu451XdBgtWVmomheD1Gfji39mRtK3nGrkVtfW EZDWosORLd2Dqxw73chEMhC3mHTzKzmFg1yQd9fpg5wsxjmIswMmdeTMfVawa2WpEHi8 SQcOKPQH32VrQqziTL/Vxa27NtP2nUdx96dkM0gfjH085Dh0TukTxE9aQJsmYcmr+Kmi 191Q== X-Gm-Message-State: ABuFfohKMCG8i2VhFgTww+1LPW43GiXRs8xypEXfcS5t/MVFfNVxsXdO ThuIArNylB8Pc+26YhB2E8Ba08brrVA= X-Google-Smtp-Source: ACcGV627ttQ/7ietCi0NfdRdvdFzqKjvbvJWRzwfaFG6hVvxdLMj2QbJT5m3YtBTGiX8bmOiyx67oA== X-Received: by 2002:a62:184a:: with SMTP id 71-v6mr2635206pfy.246.1539282639038; Thu, 11 Oct 2018 11:30:39 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:38 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com Subject: [PATCH 03/13] swim3: add real error handling in setup Date: Thu, 11 Oct 2018 11:30:13 -0700 Message-Id: <55fe5524750d283207728b18449a9e2d72e7f68a.1539282366.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 driver doesn't have support for removing a device that has already been configured, but with more careful ordering we can avoid the need for that and make sure that we don't leak generic resources. Signed-off-by: Omar Sandoval --- drivers/block/swim3.c | 60 ++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c index 469541c1e51e..df7ebe016e2c 100644 --- a/drivers/block/swim3.c +++ b/drivers/block/swim3.c @@ -1202,47 +1202,59 @@ static int swim3_add_device(struct macio_dev *mdev, int index) static int swim3_attach(struct macio_dev *mdev, const struct of_device_id *match) { + struct floppy_state *fs; struct gendisk *disk; - int index, rc; + int rc; - index = floppy_count++; - if (index >= MAX_FLOPPIES) + if (floppy_count >= MAX_FLOPPIES) return -ENXIO; - /* Add the drive */ - rc = swim3_add_device(mdev, index); - if (rc) - return rc; - /* Now register that disk. Same comment about failure handling */ - disk = disks[index] = alloc_disk(1); - if (disk == NULL) - return -ENOMEM; + if (floppy_count == 0) { + rc = register_blkdev(FLOPPY_MAJOR, "fd"); + if (rc) + return rc; + } + + fs = &floppy_states[floppy_count]; + + disk = alloc_disk(1); + if (disk == NULL) { + rc = -ENOMEM; + goto out_unregister; + } disk->queue = blk_init_queue(do_fd_request, &swim3_lock); if (disk->queue == NULL) { - put_disk(disk); - return -ENOMEM; + rc = -ENOMEM; + goto out_put_disk; } blk_queue_bounce_limit(disk->queue, BLK_BOUNCE_HIGH); - disk->queue->queuedata = &floppy_states[index]; + disk->queue->queuedata = fs; - if (index == 0) { - /* If we failed, there isn't much we can do as the driver is still - * too dumb to remove the device, just bail out - */ - if (register_blkdev(FLOPPY_MAJOR, "fd")) - return 0; - } + rc = swim3_add_device(mdev, floppy_count); + if (rc) + goto out_cleanup_queue; disk->major = FLOPPY_MAJOR; - disk->first_minor = index; + disk->first_minor = floppy_count; disk->fops = &floppy_fops; - disk->private_data = &floppy_states[index]; + disk->private_data = fs; disk->flags |= GENHD_FL_REMOVABLE; - sprintf(disk->disk_name, "fd%d", index); + sprintf(disk->disk_name, "fd%d", floppy_count); set_capacity(disk, 2880); add_disk(disk); + disks[floppy_count++] = disk; return 0; + +out_cleanup_queue: + blk_cleanup_queue(disk->queue); + disk->queue = NULL; +out_put_disk: + put_disk(disk); +out_unregister: + if (floppy_count == 0) + unregister_blkdev(FLOPPY_MAJOR, "fd"); + return rc; } static const struct of_device_id swim3_match[] =