staging: mt29f: fix unchecked malloc()
authorManuel Pégourié-Gonnard <mpg@elzevir.fr>
Tue, 29 Dec 2015 11:32:20 +0000 (12:32 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 8 Feb 2016 04:11:51 +0000 (20:11 -0800)
The pointer is unconditionally dereferenced a few lines later, we need to make
sure it isn't NULL.

Signed-off-by: Manuel Pégourié-Gonnard <mpg@elzevir.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/mt29f_spinand/mt29f_spinand.c

index 197d1124733dee3295ce85567ec363238f1dc0d4..983371b52ed4222d4af825823d290bba3d1ee1bb 100644 (file)
@@ -483,8 +483,11 @@ static int spinand_program_page(struct spi_device *spi_nand,
 #ifdef CONFIG_MTD_SPINAND_ONDIEECC
        unsigned int i, j;
 
-       enable_read_hw_ecc = 0;
        wbuf = devm_kzalloc(&spi_nand->dev, CACHE_BUF, GFP_KERNEL);
+       if (!wbuf)
+               return -ENOMEM;
+
+       enable_read_hw_ecc = 0;
        spinand_read_page(spi_nand, page_id, 0, CACHE_BUF, wbuf);
 
        for (i = offset, j = 0; i < len; i++, j++)