Commit b1b00a5b authored by Sergey Senozhatsky's avatar Sergey Senozhatsky Committed by Linus Torvalds

zsmalloc: fix zs_init cpu notifier error handling

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
[akpm@linux-foundation.org: squash bogus gcc warning]
[akpm@linux-foundation.org: use __init and __exit]
Signed-off-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Reported-by: default avatarMahendran Ganesh <opensource.ganesh@gmail.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8c7f0102
...@@ -881,14 +881,10 @@ static struct notifier_block zs_cpu_nb = { ...@@ -881,14 +881,10 @@ static struct notifier_block zs_cpu_nb = {
.notifier_call = zs_cpu_notifier .notifier_call = zs_cpu_notifier
}; };
static void zs_exit(void) static void zs_unregister_cpu_notifier(void)
{ {
int cpu; int cpu;
#ifdef CONFIG_ZPOOL
zpool_unregister_driver(&zs_zpool_driver);
#endif
cpu_notifier_register_begin(); cpu_notifier_register_begin();
for_each_online_cpu(cpu) for_each_online_cpu(cpu)
...@@ -898,31 +894,44 @@ static void zs_exit(void) ...@@ -898,31 +894,44 @@ static void zs_exit(void)
cpu_notifier_register_done(); cpu_notifier_register_done();
} }
static int zs_init(void) static int zs_register_cpu_notifier(void)
{ {
int cpu, ret; int cpu, uninitialized_var(ret);
cpu_notifier_register_begin(); cpu_notifier_register_begin();
__register_cpu_notifier(&zs_cpu_nb); __register_cpu_notifier(&zs_cpu_nb);
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
ret = zs_cpu_notifier(NULL, CPU_UP_PREPARE, (void *)(long)cpu); ret = zs_cpu_notifier(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
if (notifier_to_errno(ret)) { if (notifier_to_errno(ret))
cpu_notifier_register_done(); break;
goto fail;
}
} }
cpu_notifier_register_done(); cpu_notifier_register_done();
return notifier_to_errno(ret);
}
static void __exit zs_exit(void)
{
#ifdef CONFIG_ZPOOL #ifdef CONFIG_ZPOOL
zpool_register_driver(&zs_zpool_driver); zpool_unregister_driver(&zs_zpool_driver);
#endif #endif
zs_unregister_cpu_notifier();
}
static int __init 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; return 0;
fail:
zs_exit();
return notifier_to_errno(ret);
} }
static unsigned int get_maxobj_per_zspage(int size, int pages_per_zspage) static unsigned int get_maxobj_per_zspage(int size, int pages_per_zspage)
......
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