diff mbox series

[v2] mtd: spi-nor: fix a memory leak bug

Message ID 1566234960-3226-1-git-send-email-wenwen@cs.uga.edu
State Accepted
Delegated to: Ambarus Tudor
Headers show
Series [v2] mtd: spi-nor: fix a memory leak bug | expand

Commit Message

Wenwen Wang Aug. 19, 2019, 5:16 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.

Fixes: 816873eaeec6 ("mtd: spi-nor: parse SFDP 4-byte Address Instruction
Table")

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

Tudor Ambarus Aug. 20, 2019, 2:54 p.m. UTC | #1
On 08/19/2019 08:16 PM, Wenwen Wang wrote:
> External E-Mail
> 
> 
> 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.
> 
> Fixes: 816873eaeec6 ("mtd: spi-nor: parse SFDP 4-byte Address Instruction
> Table")
> 

^ Miquel, maybe you can drop this new line when applying.

> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>

This is a good candidate for mtd/fixes, so:

Reviewed-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Tudor Ambarus Aug. 21, 2019, 8:23 a.m. UTC | #2
On 08/19/2019 08:16 PM, Wenwen Wang wrote:
> External E-Mail
> 
> 
> 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.
> 
> Fixes: 816873eaeec6 ("mtd: spi-nor: parse SFDP 4-byte Address Instruction
> Table")
> 
> Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
> ---
>  drivers/mtd/spi-nor/spi-nor.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 


Since the bug was not introduced in the previous release and we are quite late
for mtd/fixes,

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git,
spi-nor/next branch.

Thanks,
ta
diff mbox series

Patch

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++)