mtd: nandsim: Fix kasprintf() usage
authorRichard Weinberger <richard@nod.at>
Mon, 1 Jun 2015 21:10:50 +0000 (23:10 +0200)
committerBrian Norris <computersforpeace@gmail.com>
Wed, 17 Jun 2015 01:58:47 +0000 (18:58 -0700)
kasprintf() used in get_partition_name() does a dynamic
memory allocation and can fail. We have to handle that case.

Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
drivers/mtd/nand/nandsim.c

index f232427..52c0c1a 100644 (file)
@@ -743,6 +743,11 @@ static int init_nandsim(struct mtd_info *mtd)
                        goto error;
                }
                ns->partitions[i].name   = get_partition_name(i);
+               if (!ns->partitions[i].name) {
+                       NS_ERR("unable to allocate memory.\n");
+                       ret = -ENOMEM;
+                       goto error;
+               }
                ns->partitions[i].offset = next_offset;
                ns->partitions[i].size   = part_sz;
                next_offset += ns->partitions[i].size;
@@ -756,6 +761,11 @@ static int init_nandsim(struct mtd_info *mtd)
                        goto error;
                }
                ns->partitions[i].name   = get_partition_name(i);
+               if (!ns->partitions[i].name) {
+                       NS_ERR("unable to allocate memory.\n");
+                       ret = -ENOMEM;
+                       goto error;
+               }
                ns->partitions[i].offset = next_offset;
                ns->partitions[i].size   = remains;
                ns->nbparts += 1;