Commit 52bc51c5 authored by Miquel Raynal's avatar Miquel Raynal
Browse files

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: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20200525085851.17682-9-miquel.raynal@bootlin.com
parent 058018eb
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -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;
}

/*