Skip to content

Commit 73f2b68

Browse files
committed
mtd: rawnand: nandsim: Manage lists on error in ns_init_module()
Lists are filled with calls to ns_parse_weakblocks(), ns_parse_weakpages() and ns_parse_gravepages(). Handle them in the error path, all at the same time. Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent dc2733d commit 73f2b68

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

drivers/mtd/nand/raw/nandsim.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,7 @@ static const struct nand_controller_ops ns_controller_ops = {
22732273
*/
22742274
static int __init ns_init_module(void)
22752275
{
2276+
struct list_head *pos, *n;
22762277
struct nand_chip *chip;
22772278
struct nandsim *ns;
22782279
int ret;
@@ -2340,11 +2341,11 @@ static int __init ns_init_module(void)
23402341

23412342
ret = ns_parse_weakpages();
23422343
if (ret)
2343-
goto error;
2344+
goto free_wb_list;
23442345

23452346
ret = ns_parse_gravepages();
23462347
if (ret)
2347-
goto error;
2348+
goto free_wp_list;
23482349

23492350
nand_controller_init(&ns->base);
23502351
ns->base.ops = &ns_controller_ops;
@@ -2353,7 +2354,7 @@ static int __init ns_init_module(void)
23532354
ret = nand_scan(chip, 1);
23542355
if (ret) {
23552356
NS_ERR("Could not scan NAND Simulator device\n");
2356-
goto error;
2357+
goto free_gp_list;
23572358
}
23582359

23592360
if (overridesize) {
@@ -2412,9 +2413,23 @@ static int __init ns_init_module(void)
24122413
kfree(erase_block_wear);
24132414
cleanup_nand:
24142415
nand_cleanup(chip);
2416+
free_gp_list:
2417+
list_for_each_safe(pos, n, &grave_pages) {
2418+
list_del(pos);
2419+
kfree(list_entry(pos, struct grave_page, list));
2420+
}
2421+
free_wp_list:
2422+
list_for_each_safe(pos, n, &weak_pages) {
2423+
list_del(pos);
2424+
kfree(list_entry(pos, struct weak_page, list));
2425+
}
2426+
free_wb_list:
2427+
list_for_each_safe(pos, n, &weak_blocks) {
2428+
list_del(pos);
2429+
kfree(list_entry(pos, struct weak_block, list));
2430+
}
24152431
error:
24162432
kfree(ns);
2417-
ns_free_lists();
24182433

24192434
return ret;
24202435
}

0 commit comments

Comments
 (0)