mtd: spi-nor: fix a memory leak bug
diff mbox series

Message ID 1566149993-2748-1-git-send-email-wenwen@cs.uga.edu
State Changes Requested
Delegated to: Ambarus Tudor
Headers show
Series
  • mtd: spi-nor: fix a memory leak bug
Related show

Commit Message

Wenwen Wang Aug. 18, 2019, 5:39 p.m. UTC
In spi_nor_parse_4bait(), 'dwords' is allocated through kmalloc(). However,
it is not deallocated in the following execution if spi_nor_read_sfdp()
fails, leading to a memory leak. To fix this issue, free 'dwords' before
returning the error.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
---
 drivers/mtd/spi-nor/spi-nor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ambarus Tudor Aug. 19, 2019, 6:03 a.m. UTC | #1
On 08/18/2019 08:39 PM, Wenwen Wang wrote:
> In spi_nor_parse_4bait(), 'dwords' is allocated through kmalloc(). However,
> it is not deallocated in the following execution if spi_nor_read_sfdp()
> fails, leading to a memory leak. To fix this issue, free 'dwords' before
> returning the error.

Looks good. Would you add a Fixes tag?
> 
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
> ---
>  drivers/mtd/spi-nor/spi-nor.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 03cc788..a41a466 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -3453,7 +3453,7 @@ static int spi_nor_parse_4bait(struct spi_nor *nor,
>  	addr = SFDP_PARAM_HEADER_PTP(param_header);
>  	ret = spi_nor_read_sfdp(nor, addr, len, dwords);
>  	if (ret)
> -		return ret;
> +		goto out;
>  
>  	/* Fix endianness of the 4BAIT DWORDs. */
>  	for (i = 0; i < SFDP_4BAIT_DWORD_MAX; i++)
>
Wenwen Wang Aug. 19, 2019, 5:03 p.m. UTC | #2
On Mon, Aug 19, 2019 at 2:03 AM <Tudor.Ambarus@microchip.com> wrote:
>
>
>
> On 08/18/2019 08:39 PM, Wenwen Wang wrote:
> > In spi_nor_parse_4bait(), 'dwords' is allocated through kmalloc(). However,
> > it is not deallocated in the following execution if spi_nor_read_sfdp()
> > fails, leading to a memory leak. To fix this issue, free 'dwords' before
> > returning the error.
>
> Looks good. Would you add a Fixes tag?

Sure, I will add the Fixes tag and resubmit the patch. Thanks!

Wenwen

> >
> > Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
> > ---
> >  drivers/mtd/spi-nor/spi-nor.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> > index 03cc788..a41a466 100644
> > --- a/drivers/mtd/spi-nor/spi-nor.c
> > +++ b/drivers/mtd/spi-nor/spi-nor.c
> > @@ -3453,7 +3453,7 @@ static int spi_nor_parse_4bait(struct spi_nor *nor,
> >       addr = SFDP_PARAM_HEADER_PTP(param_header);
> >       ret = spi_nor_read_sfdp(nor, addr, len, dwords);
> >       if (ret)
> > -             return ret;
> > +             goto out;
> >
> >       /* Fix endianness of the 4BAIT DWORDs. */
> >       for (i = 0; i < SFDP_4BAIT_DWORD_MAX; i++)
> >

Patch
diff mbox series

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 03cc788..a41a466 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -3453,7 +3453,7 @@  static int spi_nor_parse_4bait(struct spi_nor *nor,
 	addr = SFDP_PARAM_HEADER_PTP(param_header);
 	ret = spi_nor_read_sfdp(nor, addr, len, dwords);
 	if (ret)
-		return ret;
+		goto out;
 
 	/* Fix endianness of the 4BAIT DWORDs. */
 	for (i = 0; i < SFDP_4BAIT_DWORD_MAX; i++)