Skip to content

Commit

Permalink
mtd: spi-nor: fix a memory leak bug
Browse files Browse the repository at this point in the history
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: 816873e ("mtd: spi-nor: parse SFDP 4-byte Address Instruction Table")
Signed-off-by: Wenwen Wang <[email protected]>
Signed-off-by: Tudor Ambarus <[email protected]>
  • Loading branch information
wenwenwang1 authored and ambarus committed Aug 21, 2019
1 parent 3e9e38d commit 313aca5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/mtd/spi-nor/spi-nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -3957,7 +3957,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++)
Expand Down

0 comments on commit 313aca5

Please sign in to comment.