Commit af096e22 authored by Minfei Huang's avatar Minfei Huang Committed by Jens Axboe

null_blk: Fix error path in module initialization

Module couldn't release resource properly during the initialization. To
fix this issue, we will clean up the proper resource before returning.
Signed-off-by: default avatarMinfei Huang <mnfhuang@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 41586244
...@@ -766,7 +766,9 @@ static int null_add_dev(void) ...@@ -766,7 +766,9 @@ static int null_add_dev(void)
static int __init null_init(void) static int __init null_init(void)
{ {
int ret = 0;
unsigned int i; unsigned int i;
struct nullb *nullb;
if (bs > PAGE_SIZE) { if (bs > PAGE_SIZE) {
pr_warn("null_blk: invalid block size\n"); pr_warn("null_blk: invalid block size\n");
...@@ -808,22 +810,29 @@ static int __init null_init(void) ...@@ -808,22 +810,29 @@ static int __init null_init(void)
0, 0, NULL); 0, 0, NULL);
if (!ppa_cache) { if (!ppa_cache) {
pr_err("null_blk: unable to create ppa cache\n"); pr_err("null_blk: unable to create ppa cache\n");
return -ENOMEM; ret = -ENOMEM;
goto err_ppa;
} }
} }
for (i = 0; i < nr_devices; i++) { for (i = 0; i < nr_devices; i++) {
if (null_add_dev()) { ret = null_add_dev();
unregister_blkdev(null_major, "nullb"); if (ret)
goto err_ppa; goto err_dev;
}
} }
pr_info("null: module loaded\n"); pr_info("null: module loaded\n");
return 0; return 0;
err_ppa:
err_dev:
while (!list_empty(&nullb_list)) {
nullb = list_entry(nullb_list.next, struct nullb, list);
null_del_dev(nullb);
}
kmem_cache_destroy(ppa_cache); kmem_cache_destroy(ppa_cache);
return -EINVAL; err_ppa:
unregister_blkdev(null_major, "nullb");
return ret;
} }
static void __exit null_exit(void) static void __exit null_exit(void)
......
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