public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] zsmalloc: fix zs_init cpu notifier error handling
@ 2014-11-14 12:57 Sergey Senozhatsky
  2014-11-18 22:12 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Sergey Senozhatsky @ 2014-11-14 12:57 UTC (permalink / raw)
  To: Minchan Kim
  Cc: Andrew Morton, Mahendran Ganesh, Nitin Gupta, linux-mm,
	linux-kernel, Sergey Senozhatsky

Mahendran Ganesh reported that zpool-enabled zsmalloc should not
call zpool_unregister_driver() from zs_init() if cpu notifier
registration has failed, because error handling is performed
before we register the driver via zpool_register_driver() call.

Factor out cpu notifier registration and unregistration code and
fix zs_init() error handling.

link: http://lkml.iu.edu//hypermail/linux/kernel/1411.1/04156.html
Reported-by: Mahendran Ganesh <opensource.ganesh@gmail.com>
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
 mm/zsmalloc.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index b3b57ef..b8c2d41 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -881,14 +881,10 @@ static struct notifier_block zs_cpu_nb = {
 	.notifier_call = zs_cpu_notifier
 };
 
-static void zs_exit(void)
+static void zs_unregister_cpu_notifier(void)
 {
 	int cpu;
 
-#ifdef CONFIG_ZPOOL
-	zpool_unregister_driver(&zs_zpool_driver);
-#endif
-
 	cpu_notifier_register_begin();
 
 	for_each_online_cpu(cpu)
@@ -898,7 +894,7 @@ static void zs_exit(void)
 	cpu_notifier_register_done();
 }
 
-static int zs_init(void)
+static int zs_register_cpu_notifier(void)
 {
 	int cpu, ret;
 
@@ -907,22 +903,35 @@ static int zs_init(void)
 	__register_cpu_notifier(&zs_cpu_nb);
 	for_each_online_cpu(cpu) {
 		ret = zs_cpu_notifier(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
-		if (notifier_to_errno(ret)) {
-			cpu_notifier_register_done();
-			goto fail;
-		}
+		if (notifier_to_errno(ret))
+			break;
 	}
 
 	cpu_notifier_register_done();
+	return notifier_to_errno(ret);
+}
+
+static void zs_exit(void)
+{
+#ifdef CONFIG_ZPOOL
+	zpool_unregister_driver(&zs_zpool_driver);
+#endif
+	zs_unregister_cpu_notifier();
+}
+
+static int zs_init(void)
+{
+	int ret = zs_register_cpu_notifier();
+
+	if (ret) {
+		zs_unregister_cpu_notifier();
+		return ret;
+	}
 
 #ifdef CONFIG_ZPOOL
 	zpool_register_driver(&zs_zpool_driver);
 #endif
-
 	return 0;
-fail:
-	zs_exit();
-	return notifier_to_errno(ret);
 }
 
 static unsigned int get_maxobj_per_zspage(int size, int pages_per_zspage)
-- 
2.2.0.rc0.218.ge7f43d6


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

* Re: [PATCH] zsmalloc: fix zs_init cpu notifier error handling
  2014-11-14 12:57 [PATCH] zsmalloc: fix zs_init cpu notifier error handling Sergey Senozhatsky
@ 2014-11-18 22:12 ` Andrew Morton
  2014-11-19 13:14   ` Sergey Senozhatsky
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2014-11-18 22:12 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Minchan Kim, Mahendran Ganesh, Nitin Gupta, linux-mm,
	linux-kernel

On Fri, 14 Nov 2014 21:57:06 +0900 Sergey Senozhatsky <sergey.senozhatsky@gmail.com> wrote:

> Mahendran Ganesh reported that zpool-enabled zsmalloc should not
> call zpool_unregister_driver() from zs_init() if cpu notifier
> registration has failed, because error handling is performed
> before we register the driver via zpool_register_driver() call.
> 
> Factor out cpu notifier registration and unregistration code and
> fix zs_init() error handling.


So we can now do this, yes?

--- a/mm/zsmalloc.c~mm-zsmallocc-use-__init-and-__exit
+++ a/mm/zsmalloc.c
@@ -911,7 +911,7 @@ static int zs_register_cpu_notifier(void
 	return notifier_to_errno(ret);
 }
 
-static void zs_exit(void)
+static void __exit zs_exit(void)
 {
 #ifdef CONFIG_ZPOOL
 	zpool_unregister_driver(&zs_zpool_driver);
@@ -919,7 +919,7 @@ static void zs_exit(void)
 	zs_unregister_cpu_notifier();
 }
 
-static int zs_init(void)
+static int __init zs_init(void)
 {
 	int ret = zs_register_cpu_notifier();
 


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

* Re: [PATCH] zsmalloc: fix zs_init cpu notifier error handling
  2014-11-18 22:12 ` Andrew Morton
@ 2014-11-19 13:14   ` Sergey Senozhatsky
  0 siblings, 0 replies; 3+ messages in thread
From: Sergey Senozhatsky @ 2014-11-19 13:14 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Sergey Senozhatsky, Minchan Kim, Mahendran Ganesh, Nitin Gupta,
	linux-mm, linux-kernel

On (11/18/14 14:12), Andrew Morton wrote:
> > Mahendran Ganesh reported that zpool-enabled zsmalloc should not
> > call zpool_unregister_driver() from zs_init() if cpu notifier
> > registration has failed, because error handling is performed
> > before we register the driver via zpool_register_driver() call.
> > 
> > Factor out cpu notifier registration and unregistration code and
> > fix zs_init() error handling.
> 
> 
> So we can now do this, yes?

yes, sir.

I didn't do this because I though Mahendran would resend his
patch.

thank you.

	-ss

> 
> --- a/mm/zsmalloc.c~mm-zsmallocc-use-__init-and-__exit
> +++ a/mm/zsmalloc.c
> @@ -911,7 +911,7 @@ static int zs_register_cpu_notifier(void
>  	return notifier_to_errno(ret);
>  }
>  
> -static void zs_exit(void)
> +static void __exit zs_exit(void)
>  {
>  #ifdef CONFIG_ZPOOL
>  	zpool_unregister_driver(&zs_zpool_driver);
> @@ -919,7 +919,7 @@ static void zs_exit(void)
>  	zs_unregister_cpu_notifier();
>  }
>  
> -static int zs_init(void)
> +static int __init zs_init(void)
>  {
>  	int ret = zs_register_cpu_notifier();
>  
> 

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

end of thread, other threads:[~2014-11-19 13:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-14 12:57 [PATCH] zsmalloc: fix zs_init cpu notifier error handling Sergey Senozhatsky
2014-11-18 22:12 ` Andrew Morton
2014-11-19 13:14   ` Sergey Senozhatsky

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