mtd: bcm47xxpart: handle malloc failures

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Wed Nov 13 13:59:04 EST 2013


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=99b1d1887fee36ef9ff5d2ee24f0cf3e8c172104
Commit:     99b1d1887fee36ef9ff5d2ee24f0cf3e8c172104
Parent:     7e3019e364f1b6b9ce123e747addcdc96e8d74ae
Author:     Hauke Mehrtens <hauke at hauke-m.de>
AuthorDate: Sun Oct 13 22:53:49 2013 +0200
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Wed Nov 6 23:32:57 2013 -0800

    mtd: bcm47xxpart: handle malloc failures
    
    Handle return NULL in malloc.
    
    Signed-off-by: Hauke Mehrtens <hauke at hauke-m.de>
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 drivers/mtd/bcm47xxpart.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/mtd/bcm47xxpart.c b/drivers/mtd/bcm47xxpart.c
index 9279a91..6d42746 100644
--- a/drivers/mtd/bcm47xxpart.c
+++ b/drivers/mtd/bcm47xxpart.c
@@ -71,7 +71,14 @@ static int bcm47xxpart_parse(struct mtd_info *master,
 	/* Alloc */
 	parts = kzalloc(sizeof(struct mtd_partition) * BCM47XXPART_MAX_PARTS,
 			GFP_KERNEL);
+	if (!parts)
+		return -ENOMEM;
+
 	buf = kzalloc(BCM47XXPART_BYTES_TO_READ, GFP_KERNEL);
+	if (!buf) {
+		kfree(parts);
+		return -ENOMEM;
+	}
 
 	/* Parse block by block looking for magics */
 	for (offset = 0; offset <= master->size - blocksize;



More information about the linux-mtd-cvs mailing list