From patchwork Tue May 2 00:04:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 757359 X-Patchwork-Delegate: computersforpeace@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wH1mG29M2z9sNF for ; Tue, 2 May 2017 10:06:22 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cSg647wd"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FyxA4MEM"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=TMVGjBIuNWcHoO0BrVRP69zlqgtGSeET/dOkuqXPSFE=; b=cSg647wdH1PaPzGYuO1sKiwO+K hwQUoMuiUGEFBsqIn83afuSAIUWbyg2ozaEYjGgV8YIIQD7dlLbec18pl2VEMrsIABNOZ/6pSOLTM 7GTaAsrTnpKu6cU+KofmO1oHoh+UjPUFeZKnb25vX15U5esridGGfHnFlYdiCtv7JTPXm+3DTSp5D O+dB0Kxw2ozCnI7M2oad5K4GTmy7AJ68rnb0CSW/IIfYsbEKvK4gcfrwPnNdgBbHckxJpmLucvMdF D0KtX2tl6C0dNDfUe2hRqp+wT+ZN40mlZIg7vLsoDu05UgKM/zdW1gtfRrWBuK1B01cNuTY1Qb0f2 gV/Vt8UA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d5LKY-0002uF-Ac; Tue, 02 May 2017 00:06:14 +0000 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d5LJo-0001uG-QE for linux-mtd@lists.infradead.org; Tue, 02 May 2017 00:05:31 +0000 Received: by mail-pf0-x241.google.com with SMTP id o68so10653546pfj.2 for ; Mon, 01 May 2017 17:05:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HQTPVoy7/lxMnR6tMCe9Gfcs3pWWGGfX7tHWmK+zujg=; b=FyxA4MEMka1cmoc9hnwMBWVCsvjad0G7zJdFTQ5HQC4pr1EduTtNk+VS0ejuxyUsDz B6L5wnkgH1Q96XcPYbTWDLxcanp5rt7hwriZTJqQYuk6EkNJpOPwg8aDfRI2GUOVMaQs 8WYgNhXQMRVtaChzGWk0zL9zJ21aTediNft5fPG98cHqqVpzmFTbHEDcAvLYbbn98qfC XlRSLbxzKBVSaEMb7d8WYcJ6XdKxfgdYg6dr/VWaqLCfQsJfwogFjL27sLKilX3NXk9v i/kOF2K6flNrI8uhiWHk+Hw+hDjFtruItgt1yLak+h0K+San1CLU8fp+mHbEmaRb8LVb fFvQ== 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; bh=HQTPVoy7/lxMnR6tMCe9Gfcs3pWWGGfX7tHWmK+zujg=; b=V8gZQQoMMT6w0SiVNav9H8HqCl0WlL7ulgVMwY9oyvdRVncoU3ZCFGwmuWcuko8Y7D oyQg5jcPXKDSd11kLBHcXhw3ReGr8J+MDVsOjMvbgS9g6ct+s0/Y6pT7U47TYQfrtAko Y16j1N9tNaN3dUU5kLGf56NGmGSTArltU1pRa5yrlfiKq8Tfv2m7xRDNzlpIP4U72BKZ 7GHxNGurI+O+ZzFewb9mmwQAsofgJ2427lAGnMgd83q79KEOpeizsgx2g0Uxpx96Z9wO zD01fz27h9Tk2QlBTnpaAa5jrpvbGt8MZudgMGa1u/TjWId1wqgBDTecyejvoFHrBhA6 O6xA== X-Gm-Message-State: AN3rC/54G3bhC8NBjeSZSqj8kheHLnanLzbweY1NlgRG6GWHczFH8Jim t9A8x3nD0UrA1A== X-Received: by 10.84.238.198 with SMTP id l6mr37533561pln.95.1493683507837; Mon, 01 May 2017 17:05:07 -0700 (PDT) Received: from ban.mtv.corp.google.com ([172.22.64.120]) by smtp.gmail.com with ESMTPSA id g22sm26756413pfd.22.2017.05.01.17.05.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 May 2017 17:05:07 -0700 (PDT) From: Brian Norris To: , Boris Brezillon Subject: [PATCH] mtd: nand: free vendor-specific resources in init failure paths Date: Mon, 1 May 2017 17:04:53 -0700 Message-Id: <20170502000455.13240-4-computersforpeace@gmail.com> X-Mailer: git-send-email 2.13.0.rc1.294.g07d810a77f-goog In-Reply-To: <20170502000455.13240-1-computersforpeace@gmail.com> References: <20170502000455.13240-1-computersforpeace@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170501_170528_991158_6E8E6700 X-CRM114-Status: GOOD ( 15.07 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:400e:c00:0:0:0:241 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (computersforpeace[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cyrille Pitchen , Richard Weinberger , Brian Norris , Marek Vasut MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org If we fail any time after calling nand_detect(), then we don't call the vendor-specific ->cleanup() callback, and we'll leak any resources the vendor-specific code might have allocated. Mark the "fix" against the first commit that started allocating anything in ->init(). Cc: Boris Brezillon Fixes: 626994e07480 ("mtd: nand: hynix: Add read-retry support for 1x nm MLC NANDs") Signed-off-by: Brian Norris Acked-by: Boris Brezillon --- Compile tested only drivers/mtd/nand/nand_base.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 2adcc8cdedf1..978242b1213f 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -4300,7 +4300,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips, /* Initialize the ->data_interface field. */ ret = nand_init_data_interface(chip); if (ret) - return ret; + goto err_nand_init; /* * Setup the data interface correctly on the chip and controller side. @@ -4312,7 +4312,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips, */ ret = nand_setup_data_interface(chip); if (ret) - return ret; + goto err_nand_init; nand_maf_id = chip->id.data[0]; nand_dev_id = chip->id.data[1]; @@ -4343,6 +4343,12 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips, mtd->size = i * chip->chipsize; return 0; + +err_nand_init: + /* Free manufacturer priv data. */ + nand_manufacturer_cleanup(chip); + + return ret; } EXPORT_SYMBOL(nand_scan_ident); @@ -4513,18 +4519,23 @@ int nand_scan_tail(struct mtd_info *mtd) /* New bad blocks should be marked in OOB, flash-based BBT, or both */ if (WARN_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) && - !(chip->bbt_options & NAND_BBT_USE_FLASH))) - return -EINVAL; + !(chip->bbt_options & NAND_BBT_USE_FLASH))) { + ret = -EINVAL; + goto err_ident; + } if (invalid_ecc_page_accessors(chip)) { pr_err("Invalid ECC page accessors setup\n"); - return -EINVAL; + ret = -EINVAL; + goto err_ident; } if (!(chip->options & NAND_OWN_BUFFERS)) { nbuf = kzalloc(sizeof(*nbuf), GFP_KERNEL); - if (!nbuf) - return -ENOMEM; + if (!nbuf) { + ret = -ENOMEM; + goto err_ident; + } nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL); if (!nbuf->ecccalc) { @@ -4547,8 +4558,10 @@ int nand_scan_tail(struct mtd_info *mtd) chip->buffers = nbuf; } else { - if (!chip->buffers) - return -ENOMEM; + if (!chip->buffers) { + ret = -ENOMEM; + goto err_ident; + } } /* Set the internal oob buffer location, just after the page data */ @@ -4789,6 +4802,13 @@ int nand_scan_tail(struct mtd_info *mtd) kfree(nbuf->ecccalc); kfree(nbuf); } + +err_ident: + /* Clean up nand_scan_ident(). */ + + /* Free manufacturer priv data. */ + nand_manufacturer_cleanup(chip); + return ret; } EXPORT_SYMBOL(nand_scan_tail);