mtd: spi-nor: fix a memory leak bug
authorWenwen Wang <wenwen@cs.uga.edu>
Mon, 19 Aug 2019 17:16:00 +0000 (12:16 -0500)
committerTudor Ambarus <tudor.ambarus@microchip.com>
Wed, 21 Aug 2019 08:08:01 +0000 (11:08 +0300)
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>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
drivers/mtd/spi-nor/spi-nor.c

index ba99d90..fdf776c 100644 (file)
@@ -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++)