From patchwork Thu Oct 11 19:20:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637223 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 EC8E8157A for ; Thu, 11 Oct 2018 19:21:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCEE02C037 for ; Thu, 11 Oct 2018 19:21:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA50D2BF63; Thu, 11 Oct 2018 19:21:02 +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 716782C003 for ; Thu, 11 Oct 2018 19:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729694AbeJLCtg (ORCPT ); Thu, 11 Oct 2018 22:49:36 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:46898 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729593AbeJLCtf (ORCPT ); Thu, 11 Oct 2018 22:49:35 -0400 Received: by mail-pg1-f194.google.com with SMTP id a5-v6so4613513pgv.13 for ; Thu, 11 Oct 2018 12:21:00 -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=VDfIWNI7gV+lbnGbyYpcWNaC8DVTomorme6+4CedWMHDy+XS0LtWv9V5rb4M2yYTCx pxbI9G6Bj6yoUzTrQnISeCk+tB7kgDtGZowk26cO5jPv0dr2Tga//my6jssE6P3EwNil kafWX8HwjJkMznHcfdWZL0vP3oCBRjfz3bW1xSaeJuzeoicS8ZhsxoX7m5ml6uHPtrIQ KTrg+YEsEJVdAaGbc8MXBxoYKRtLZON7T8Uzldff1Qj75AT4FPJHovwMX8GtmWt0mNj9 eN1LBNsj3xyYoqFIddltmyb9VY42cEIgWcn2oQgfq1RWEXjFmsrVtmKN+3Wr3nWb3/53 HI6w== 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=azHyoVmQg0detwr/Qp1ZTy53qPyoSVv+WBEk0/NIzYDTgy220v+AiI6Oveh5FMiw3S /Rvi/ED7u9CAjo/phDFDFDjXWcr/t84PbaDQu7Xkb/Y17BB1s8boPZtw9xxNIk44jVJ6 4VS7o/ZxxzTMR++NbIPpUMWsGkmq0DcaRpVWukjyHpuTDsyJj3IrjHs4+t1bAkhD4Wai VSK6xOw8gLFQ6yBsfZAkTkZdPHu+u4HDrHJRtGOdu4DNKpcbs76VugkKfPjhfREJLvuf mTBv8V3nKDICUewi6bR/UwLDSpi+WZ9YUmgUxLpwka75PIPuHwlxL6xqjMFm8tNUaqp4 G3BQ== X-Gm-Message-State: ABuFfohJUyOi1YHvtKuTzb5ztSecWhMxzW2n3DPGXkfYmouw2Zl+CFq+ rnTJW8PENNg7xAgA5j2iBo8SP4Z4r6M= X-Google-Smtp-Source: ACcGV60oiznYFzYDBkOjoPEUBtqayNp8kWzB7XQp5NSoiZACoNPBJiu0s/TrAWcq3chTKMPqcOqd8A== X-Received: by 2002:a65:6458:: with SMTP id s24-v6mr2547441pgv.29.1539285659975; Thu, 11 Oct 2018 12:20:59 -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.20.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 12:20:59 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com Subject: [PATCH v2 03/11] swim3: add real error handling in setup Date: Thu, 11 Oct 2018 12:20:43 -0700 Message-Id: <1a5a67d3d1b59bcecdabd99ea23e2bbbe1a5b28d.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 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[] =