summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiquel Raynal <miquel.raynal@bootlin.com>2020-05-25 10:58:42 +0200
committerMiquel Raynal <miquel.raynal@bootlin.com>2020-05-31 10:53:38 +0200
commit52bc51c54ef8d8e9358f12666e9f107d9a44f394 (patch)
tree0e2d2e235321b565d789873614d585b71f9ee90c
parent058018eb0202d144ae266e0497082366bfd6afff (diff)
downloadlinux-stable-52bc51c54ef8d8e9358f12666e9f107d9a44f394.tar.gz
linux-stable-52bc51c54ef8d8e9358f12666e9f107d9a44f394.tar.bz2
linux-stable-52bc51c54ef8d8e9358f12666e9f107d9a44f394.zip
mtd: rawnand: nandsim: Free partition names on error in ns_init()
The ns_init() function shall free the partition names allocated by ns_get_partition_name() on error. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20200525085851.17682-9-miquel.raynal@bootlin.com
-rw-r--r--drivers/mtd/nand/raw/nandsim.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/drivers/mtd/nand/raw/nandsim.c b/drivers/mtd/nand/raw/nandsim.c
index da6d919ed185..53889bce81f1 100644
--- a/drivers/mtd/nand/raw/nandsim.c
+++ b/drivers/mtd/nand/raw/nandsim.c
@@ -722,12 +722,14 @@ static int __init ns_init(struct mtd_info *mtd)
if (remains) {
if (parts_num + 1 > ARRAY_SIZE(ns->partitions)) {
NS_ERR("too many partitions.\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto free_partition_names;
}
ns->partitions[i].name = ns_get_partition_name(i);
if (!ns->partitions[i].name) {
NS_ERR("unable to allocate memory.\n");
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto free_partition_names;
}
ns->partitions[i].offset = next_offset;
ns->partitions[i].size = remains;
@@ -756,18 +758,25 @@ static int __init ns_init(struct mtd_info *mtd)
ret = ns_alloc_device(ns);
if (ret)
- return ret;
+ goto free_partition_names;
/* Allocate / initialize the internal buffer */
ns->buf.byte = kmalloc(ns->geom.pgszoob, GFP_KERNEL);
if (!ns->buf.byte) {
NS_ERR("init_nandsim: unable to allocate %u bytes for the internal buffer\n",
ns->geom.pgszoob);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto free_partition_names;
}
memset(ns->buf.byte, 0xFF, ns->geom.pgszoob);
return 0;
+
+free_partition_names:
+ for (i = 0; i < ARRAY_SIZE(ns->partitions); ++i)
+ kfree(ns->partitions[i].name);
+
+ return ret;
}
/*