diff mbox

mtd: bcm47xxpart: handle malloc failures

Message ID 1381697629-31272-1-git-send-email-hauke@hauke-m.de
State Accepted
Commit 99b1d1887fee36ef9ff5d2ee24f0cf3e8c172104
Headers show

Commit Message

Hauke Mehrtens Oct. 13, 2013, 8:53 p.m. UTC
Handle return NULL in malloc.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 drivers/mtd/bcm47xxpart.c |    7 +++++++
 1 file changed, 7 insertions(+)

Comments

Brian Norris Oct. 22, 2013, 10:05 p.m. UTC | #1
On Sun, Oct 13, 2013 at 10:53:49PM +0200, Hauke Mehrtens wrote:
> Handle return NULL in malloc.
> 
> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>

Pushed to l2-mtd.git. Thanks!

Brian
diff mbox

Patch

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;