public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] null_blk: Fix error path in module initialization
@ 2015-11-26 13:48 Minfei Huang
  2015-12-08 12:35 ` Minfei Huang
  0 siblings, 1 reply; 4+ messages in thread
From: Minfei Huang @ 2015-11-26 13:48 UTC (permalink / raw)
  To: axboe, m, akinobu.mita, rusty, keith.busch, mcgrof, krinkin.m.u
  Cc: linux-kernel, Minfei Huang

From: Minfei Huang <mnfhuang@gmail.com>

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 <mnfhuang@gmail.com>
---
 drivers/block/null_blk.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
index 5c8ba54..ec99568 100644
--- a/drivers/block/null_blk.c
+++ b/drivers/block/null_blk.c
@@ -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)
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] null_blk: Fix error path in module initialization
  2015-11-26 13:48 [PATCH] null_blk: Fix error path in module initialization Minfei Huang
@ 2015-12-08 12:35 ` Minfei Huang
  2015-12-08 20:48   ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Minfei Huang @ 2015-12-08 12:35 UTC (permalink / raw)
  To: Minfei Huang
  Cc: axboe, m, akinobu.mita, rusty, keith.busch, mcgrof, krinkin.m.u,
	linux-kernel

Ping.

Any comment is appreciate.

Thanks
Minfei

On 11/26/15 at 09:48P, Minfei Huang wrote:
> From: Minfei Huang <mnfhuang@gmail.com>
> 
> 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 <mnfhuang@gmail.com>
> ---
>  drivers/block/null_blk.c | 24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
> index 5c8ba54..ec99568 100644
> --- a/drivers/block/null_blk.c
> +++ b/drivers/block/null_blk.c
> @@ -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)
> -- 
> 1.8.3.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] null_blk: Fix error path in module initialization
  2015-12-08 12:35 ` Minfei Huang
@ 2015-12-08 20:48   ` Jens Axboe
  2015-12-09  4:20     ` Minfei Huang
  0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2015-12-08 20:48 UTC (permalink / raw)
  To: Minfei Huang, Minfei Huang
  Cc: m, akinobu.mita, rusty, keith.busch, mcgrof, krinkin.m.u,
	linux-kernel

On 12/08/2015 05:35 AM, Minfei Huang wrote:
> 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.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] null_blk: Fix error path in module initialization
  2015-12-08 20:48   ` Jens Axboe
@ 2015-12-09  4:20     ` Minfei Huang
  0 siblings, 0 replies; 4+ messages in thread
From: Minfei Huang @ 2015-12-09  4:20 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Minfei Huang, m, akinobu.mita, rusty, keith.busch, mcgrof,
	krinkin.m.u, linux-kernel

On 12/08/15 at 01:48pm, Jens Axboe wrote:
> On 12/08/2015 05:35 AM, Minfei Huang wrote:
> >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.

Agreed.

Thanks
Minfei

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-12-09  4:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-26 13:48 [PATCH] null_blk: Fix error path in module initialization Minfei Huang
2015-12-08 12:35 ` Minfei Huang
2015-12-08 20:48   ` Jens Axboe
2015-12-09  4:20     ` Minfei Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox