Commit 5891a8d1 authored by shengyong's avatar shengyong Committed by Brian Norris

mtd: nandsim: fix double free

Do not call free_device() in init_nandsim, the caller - ns_init_module -
will take care of that if something goes wrong.
Signed-off-by: default avatarSheng Yong <shengyong1@huawei.com>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
parent ec7478fa
...@@ -730,8 +730,7 @@ static int init_nandsim(struct mtd_info *mtd) ...@@ -730,8 +730,7 @@ static int init_nandsim(struct mtd_info *mtd)
/* Fill the partition_info structure */ /* Fill the partition_info structure */
if (parts_num > ARRAY_SIZE(ns->partitions)) { if (parts_num > ARRAY_SIZE(ns->partitions)) {
NS_ERR("too many partitions.\n"); NS_ERR("too many partitions.\n");
ret = -EINVAL; return -EINVAL;
goto error;
} }
remains = ns->geom.totsz; remains = ns->geom.totsz;
next_offset = 0; next_offset = 0;
...@@ -740,14 +739,12 @@ static int init_nandsim(struct mtd_info *mtd) ...@@ -740,14 +739,12 @@ static int init_nandsim(struct mtd_info *mtd)
if (!part_sz || part_sz > remains) { if (!part_sz || part_sz > remains) {
NS_ERR("bad partition size.\n"); NS_ERR("bad partition size.\n");
ret = -EINVAL; return -EINVAL;
goto error;
} }
ns->partitions[i].name = get_partition_name(i); ns->partitions[i].name = get_partition_name(i);
if (!ns->partitions[i].name) { if (!ns->partitions[i].name) {
NS_ERR("unable to allocate memory.\n"); NS_ERR("unable to allocate memory.\n");
ret = -ENOMEM; return -ENOMEM;
goto error;
} }
ns->partitions[i].offset = next_offset; ns->partitions[i].offset = next_offset;
ns->partitions[i].size = part_sz; ns->partitions[i].size = part_sz;
...@@ -758,14 +755,12 @@ static int init_nandsim(struct mtd_info *mtd) ...@@ -758,14 +755,12 @@ static int init_nandsim(struct mtd_info *mtd)
if (remains) { if (remains) {
if (parts_num + 1 > ARRAY_SIZE(ns->partitions)) { if (parts_num + 1 > ARRAY_SIZE(ns->partitions)) {
NS_ERR("too many partitions.\n"); NS_ERR("too many partitions.\n");
ret = -EINVAL; return -EINVAL;
goto error;
} }
ns->partitions[i].name = get_partition_name(i); ns->partitions[i].name = get_partition_name(i);
if (!ns->partitions[i].name) { if (!ns->partitions[i].name) {
NS_ERR("unable to allocate memory.\n"); NS_ERR("unable to allocate memory.\n");
ret = -ENOMEM; return -ENOMEM;
goto error;
} }
ns->partitions[i].offset = next_offset; ns->partitions[i].offset = next_offset;
ns->partitions[i].size = remains; ns->partitions[i].size = remains;
...@@ -793,24 +788,18 @@ static int init_nandsim(struct mtd_info *mtd) ...@@ -793,24 +788,18 @@ static int init_nandsim(struct mtd_info *mtd)
printk("options: %#x\n", ns->options); printk("options: %#x\n", ns->options);
if ((ret = alloc_device(ns)) != 0) if ((ret = alloc_device(ns)) != 0)
goto error; return ret;
/* Allocate / initialize the internal buffer */ /* Allocate / initialize the internal buffer */
ns->buf.byte = kmalloc(ns->geom.pgszoob, GFP_KERNEL); ns->buf.byte = kmalloc(ns->geom.pgszoob, GFP_KERNEL);
if (!ns->buf.byte) { if (!ns->buf.byte) {
NS_ERR("init_nandsim: unable to allocate %u bytes for the internal buffer\n", NS_ERR("init_nandsim: unable to allocate %u bytes for the internal buffer\n",
ns->geom.pgszoob); ns->geom.pgszoob);
ret = -ENOMEM; return -ENOMEM;
goto error;
} }
memset(ns->buf.byte, 0xFF, ns->geom.pgszoob); memset(ns->buf.byte, 0xFF, ns->geom.pgszoob);
return 0; return 0;
error:
free_device(ns);
return ret;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment