null_blk: Fix error path in module initialization
PATCH 1/1 null_blk: Fix error path in module initialization
From: Minfei Huang <[email protected]>
Module couldn't release resource properly during the initialization. To fix this issue, we will clean up the proper resource before returning.
--- drivers/block/null_blk.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/block/null_blk.c +17 -7
@@ -780,7 +780,9 @@ out:static int __init null_init (void ) { +int ret =0 ;unsigned int i; +struct nullb *nullb;if (bs >PAGE_SIZE ) {pr_warn ("null_blk: invalid block size\n" );
@@ -835,22 +837,30 @@ static int __init null_init(void) 0, 0, NULL);if (!ppa_cache) {pr_err ("null_blk: unable to create ppa cache\n" ); -return -ENOMEM ; + ret = -ENOMEM ; + goto err_ppa; } }for (i =0 ; i < nr_devices; i++) { -if (null_add_dev ()) { -unregister_blkdev (null_major,"nullb" ); - goto err_ppa; - } + ret =null_add_dev (); +if (ret) + goto err_dev; }pr_info ("null: module loaded\n" );return 0 ; + +err_dev: +while (!list_empty (&nullb_list)) { + nullb = list_entry(nullb_list.next, struct nullb, list); +null_del_dev (nullb); + } +if (use_lightnvm) +kmem_cache_destroy (ppa_cache); err_ppa: -kmem_cache_destroy (ppa_cache); -return -EINVAL ; +unregister_blkdev (null_major,"nullb" ); +return ret; } static void __exit null_exit(void)
Signature · 1 line
1.8.3.1
Ping.
Any comment is appreciate.
Thanks
Minfei
Quoted 65 lines · Minfei Huang
From: Minfei Huang <[email protected]>
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 Minfei Huang <[email protected]>--- drivers/block/null_blk.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)drivers/block/null_blk.c +17
-7@@ -780,7 +780,9 @@ out:static int __init null_init (void ) { +int ret =0 ;unsigned int i; +struct nullb *nullb;if (bs >PAGE_SIZE ) {pr_warn ("null_blk: invalid block size\n" );@@ -835,22 +837,30 @@ static int __init null_init(void) 0, 0, NULL);if (!ppa_cache) {pr_err ("null_blk: unable to create ppa cache\n" ); -return -ENOMEM ; + ret = -ENOMEM ; + goto err_ppa; } }for (i =0 ; i < nr_devices; i++) { -if (null_add_dev ()) { -unregister_blkdev (null_major,"nullb" ); - goto err_ppa; - } + ret =null_add_dev (); +if (ret) + goto err_dev; }pr_info ("null: module loaded\n" );return 0 ; + +err_dev: +while (!list_empty (&nullb_list)) { + nullb = list_entry(nullb_list.next, struct nullb, list); +null_del_dev (nullb); + } +if (use_lightnvm) +kmem_cache_destroy (ppa_cache); err_ppa: -kmem_cache_destroy (ppa_cache); -return -EINVAL ; +unregister_blkdev (null_major,"nullb" ); +return ret; } static void __exit null_exit(void)Signature · 1 line
1.8.3.1
Jens Axboe
AppliedQuoted 3 lines · Minfei Huang
Ping.
Any comment is appreciate.
Applied, it is indeed pretty broken after the lightnvm update.
I killed the use_lightnvm check before kmem_cache_destroy, that's not needed.
Signature · 1 line
Jens Axboe
Quoted 8 lines · Jens Axboe
Quoted 3 lines · Minfei Huang
Ping.
Any comment is appreciate.
Applied, it is indeed pretty broken after the lightnvm update. I killed the
use_lightnvmcheck beforekmem_cache_destroy, that's not needed.
Agreed.
Thanks
Minfei