From patchwork Wed Dec 13 20:49:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 848240 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="klYW1Q8e"; dkim-atps=neutral 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 3yxpj96lGZz9s81 for ; Thu, 14 Dec 2017 07:49:49 +1100 (AEDT) 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References: List-Owner; bh=Zcafm+Sa0iTu9bqblnQnfks1Ij8A9acRb23gB5zvHlI=; b=klYW1Q8eiNR/oB Aj/R9Kq7yZ6cBCHDTYmVWxP9RjSyyJKyXyjdaJ1A/Gei2N1jawAHsT0iQMoiGH3ae3PGa8a98r/y6 0ZJR7Vw+QQ+Bi2Xxwi8kpkTByERYtgYsKjqWqjOiMVVL1v7ezMONAZzNelKESCXytSOboj9P55+PZ tHMINTpAgeh0GS7udsDvFqo/1YHsA/qGJHUdBy9kNHfqzOmi9Z+vsh9tSjbHMXzXmoOUhIpmHlBb2 7H3isiZJWbQ5suq5Uw2hEx8pJYTIMr3cCPKv+YqrlU/+5F5lvH39ohc5+A6Bp70LzIuViCJmvceBZ 0Di9O7FKvCDKRcD0R+yw==; 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 1ePDyJ-0006C3-RP; Wed, 13 Dec 2017 20:49:43 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ePDyG-0005TQ-SB for linux-mtd@lists.infradead.org; Wed, 13 Dec 2017 20:49:42 +0000 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1ePDxm-0005nc-7y; Wed, 13 Dec 2017 20:49:10 +0000 From: Colin King To: Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Cyrille Pitchen , linux-mtd@lists.infradead.org Subject: [PATCH] mtd: nand: fix memory leak on ep on error exit returns Date: Wed, 13 Dec 2017 20:49:09 +0000 Message-Id: <20171213204909.28287-1-colin.king@canonical.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171213_124941_065402_4C46E40E X-CRM114-Status: UNSURE ( 9.75 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -6.9 (------) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-6.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [91.189.89.112 listed in list.dnswl.org] -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [91.189.89.112 listed in wl.mailspike.net] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 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: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Colin Ian King There are two error return paths that are not kfree'ing ep that lead to memory leaks. Fix this by exiting on error via the ext_out exit path that performs the necessary kfree. Detected by CoverityScan, CID#1462747 ("Resource Leak") Fixes: b83ea87958c5 ("mtd: nand: provide several helpers to do common NAND operations") Signed-off-by: Colin Ian King --- drivers/mtd/nand/nand_base.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index eb810d5d44e7..1c5126d1db8c 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -5046,14 +5046,14 @@ static int nand_flash_detect_ext_param_page(struct nand_chip *chip, /* Send our own NAND_CMD_PARAM. */ ret = nand_read_param_page_op(chip, 0, NULL, 0); if (ret) - return ret; + goto ext_out; /* Use the Change Read Column command to skip the ONFI param pages. */ ret = nand_change_read_column_op(chip, sizeof(*p) * p->num_of_param_pages, ep, len, true); if (ret) - return ret; + goto ext_out; ret = -EINVAL; if ((onfi_crc16(ONFI_CRC_BASE, ((uint8_t *)ep) + 2, len - 2)