From: Richard Weinberger Date: Mon, 1 Jun 2015 21:10:50 +0000 (+0200) Subject: mtd: nandsim: Fix kasprintf() usage X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=641c7925b6ec78466358b654c731050b4179e5f4;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git 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 Signed-off-by: Brian Norris --- diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c index f2324271b94e..52c0c1a3899c 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;