public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] mtd: nand: fix memory leak on ep on error exit returns
@ 2017-12-13 20:49 Colin King
  2017-12-13 21:02 ` Boris Brezillon
  0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2017-12-13 20:49 UTC (permalink / raw)
  To: Boris Brezillon, Richard Weinberger, David Woodhouse,
	Brian Norris, Marek Vasut, Cyrille Pitchen, linux-mtd
  Cc: kernel-janitors, linux-kernel

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mtd: nand: fix memory leak on ep on error exit returns
  2017-12-13 20:49 [PATCH] mtd: nand: fix memory leak on ep on error exit returns Colin King
@ 2017-12-13 21:02 ` Boris Brezillon
  2017-12-13 21:09   ` Colin Ian King
  0 siblings, 1 reply; 3+ messages in thread
From: Boris Brezillon @ 2017-12-13 21:02 UTC (permalink / raw)
  To: Colin King
  Cc: Richard Weinberger, David Woodhouse, Brian Norris, Marek Vasut,
	Cyrille Pitchen, linux-mtd, kernel-janitors, linux-kernel

Hi Colin,

On Wed, 13 Dec 2017 20:49:09 +0000
Colin King <colin.king@canonical.com> wrote:

> 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.

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

If you don't mind, I'd like to squash these changes in the original
commit.

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)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mtd: nand: fix memory leak on ep on error exit returns
  2017-12-13 21:02 ` Boris Brezillon
@ 2017-12-13 21:09   ` Colin Ian King
  0 siblings, 0 replies; 3+ messages in thread
From: Colin Ian King @ 2017-12-13 21:09 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Richard Weinberger, David Woodhouse, Brian Norris, Marek Vasut,
	Cyrille Pitchen, linux-mtd, kernel-janitors, linux-kernel

On 13/12/17 21:02, Boris Brezillon wrote:
> Hi Colin,
> 
> On Wed, 13 Dec 2017 20:49:09 +0000
> Colin King <colin.king@canonical.com> wrote:
> 
>> 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.
> 
> 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 <colin.king@canonical.com>
> 
> 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)
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-12-13 21:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-13 20:49 [PATCH] mtd: nand: fix memory leak on ep on error exit returns Colin King
2017-12-13 21:02 ` Boris Brezillon
2017-12-13 21:09   ` Colin Ian King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox