Commit 058018eb authored by Miquel Raynal's avatar Miquel Raynal

mtd: rawnand: nandsim: Fix the two ns_alloc_device() error paths

The ns_alloc_device() helper has actually two distinct path. Handle
errors in both of them.
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20200525085851.17682-8-miquel.raynal@bootlin.com
parent cde495f8
...@@ -543,12 +543,12 @@ static int __init ns_alloc_device(struct nandsim *ns) ...@@ -543,12 +543,12 @@ static int __init ns_alloc_device(struct nandsim *ns)
if (!(cfile->f_mode & FMODE_CAN_READ)) { if (!(cfile->f_mode & FMODE_CAN_READ)) {
NS_ERR("alloc_device: cache file not readable\n"); NS_ERR("alloc_device: cache file not readable\n");
err = -EINVAL; err = -EINVAL;
goto err_close; goto err_close_filp;
} }
if (!(cfile->f_mode & FMODE_CAN_WRITE)) { if (!(cfile->f_mode & FMODE_CAN_WRITE)) {
NS_ERR("alloc_device: cache file not writeable\n"); NS_ERR("alloc_device: cache file not writeable\n");
err = -EINVAL; err = -EINVAL;
goto err_close; goto err_close_filp;
} }
ns->pages_written = ns->pages_written =
vzalloc(array_size(sizeof(unsigned long), vzalloc(array_size(sizeof(unsigned long),
...@@ -556,16 +556,24 @@ static int __init ns_alloc_device(struct nandsim *ns) ...@@ -556,16 +556,24 @@ static int __init ns_alloc_device(struct nandsim *ns)
if (!ns->pages_written) { if (!ns->pages_written) {
NS_ERR("alloc_device: unable to allocate pages written array\n"); NS_ERR("alloc_device: unable to allocate pages written array\n");
err = -ENOMEM; err = -ENOMEM;
goto err_close; goto err_close_filp;
} }
ns->file_buf = kmalloc(ns->geom.pgszoob, GFP_KERNEL); ns->file_buf = kmalloc(ns->geom.pgszoob, GFP_KERNEL);
if (!ns->file_buf) { if (!ns->file_buf) {
NS_ERR("alloc_device: unable to allocate file buf\n"); NS_ERR("alloc_device: unable to allocate file buf\n");
err = -ENOMEM; err = -ENOMEM;
goto err_free; goto err_free_pw;
} }
ns->cfile = cfile; ns->cfile = cfile;
return 0; return 0;
err_free_pw:
vfree(ns->pages_written);
err_close_filp:
filp_close(cfile, NULL);
return err;
} }
ns->pages = vmalloc(array_size(sizeof(union ns_mem), ns->geom.pgnum)); ns->pages = vmalloc(array_size(sizeof(union ns_mem), ns->geom.pgnum));
...@@ -580,15 +588,15 @@ static int __init ns_alloc_device(struct nandsim *ns) ...@@ -580,15 +588,15 @@ static int __init ns_alloc_device(struct nandsim *ns)
ns->geom.pgszoob, 0, 0, NULL); ns->geom.pgszoob, 0, 0, NULL);
if (!ns->nand_pages_slab) { if (!ns->nand_pages_slab) {
NS_ERR("cache_create: unable to create kmem_cache\n"); NS_ERR("cache_create: unable to create kmem_cache\n");
return -ENOMEM; err = -ENOMEM;
goto err_free_pg;
} }
return 0; return 0;
err_free: err_free_pg:
vfree(ns->pages_written); vfree(ns->pages);
err_close:
filp_close(cfile, NULL);
return err; return err;
} }
......
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