Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753922AbdLMVJO (ORCPT ); Wed, 13 Dec 2017 16:09:14 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:47220 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753360AbdLMVJM (ORCPT ); Wed, 13 Dec 2017 16:09:12 -0500 Subject: Re: [PATCH] mtd: nand: fix memory leak on ep on error exit returns To: Boris Brezillon Cc: Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Cyrille Pitchen , linux-mtd@lists.infradead.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org References: <20171213204909.28287-1-colin.king@canonical.com> <20171213220241.29bbe131@bbrezillon> From: Colin Ian King Message-ID: Date: Wed, 13 Dec 2017 21:09:10 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171213220241.29bbe131@bbrezillon> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1806 Lines: 59 On 13/12/17 21:02, Boris Brezillon wrote: > Hi Colin, > > On Wed, 13 Dec 2017 20:49:09 +0000 > Colin King wrote: > >> 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. > > Well, given that no one implements the ->exec_op() hook yet, the > xxxx_op() functions always return 0 right now, but I agree, we > should fix the generic case. > >> >> 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 > > If you don't mind, I'd like to squash these changes in the original > commit. Yep, no problem with squashing it. Colin > > Thanks, > > Boris > >> --- >> 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) >