public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
From: Colin King <colin.king@canonical.com>
To: Boris Brezillon <boris.brezillon@free-electrons.com>,
	Richard Weinberger <richard@nod.at>,
	David Woodhouse <dwmw2@infradead.org>,
	Brian Norris <computersforpeace@gmail.com>,
	Marek Vasut <marek.vasut@gmail.com>,
	Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>,
	linux-mtd@lists.infradead.org
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mtd: nand: fix memory leak on ep on error exit returns
Date: Wed, 13 Dec 2017 20:49:09 +0000	[thread overview]
Message-ID: <20171213204909.28287-1-colin.king@canonical.com> (raw)

From: Colin Ian King <colin.king@canonical.com>

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 <colin.king@canonical.com>
---
 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)
-- 
2.14.1


             reply	other threads:[~2017-12-13 20:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-13 20:49 Colin King [this message]
2017-12-13 21:02 ` [PATCH] mtd: nand: fix memory leak on ep on error exit returns Boris Brezillon
2017-12-13 21:09   ` Colin Ian King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171213204909.28287-1-colin.king@canonical.com \
    --to=colin.king@canonical.com \
    --cc=boris.brezillon@free-electrons.com \
    --cc=computersforpeace@gmail.com \
    --cc=cyrille.pitchen@wedev4u.fr \
    --cc=dwmw2@infradead.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=richard@nod.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox