mtd: nandsim: Fix kasprintf() usage
Linux-MTD Mailing List
linux-mtd at lists.infradead.org
Tue Jun 23 10:59:08 PDT 2015
Gitweb: http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=641c7925b6ec78466358b654c731050b4179e5f4
Commit: 641c7925b6ec78466358b654c731050b4179e5f4
Parent: bc349da0a6b3c6cf795b6a51e3f448d9d16a1686
Author: Richard Weinberger <richard at nod.at>
AuthorDate: Mon Jun 1 23:10:50 2015 +0200
Committer: Brian Norris <computersforpeace at gmail.com>
CommitDate: Tue Jun 16 18:58:47 2015 -0700
mtd: nandsim: Fix kasprintf() usage
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 at nod.at>
Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
drivers/mtd/nand/nandsim.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index f232427..52c0c1a 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -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;
More information about the linux-mtd-cvs
mailing list