staging: android: check the return value of register_shrinker
authorXiongwei Song <sxwjean@gmail.com>
Thu, 4 Jan 2018 23:34:36 +0000 (07:34 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 8 Jan 2018 15:37:18 +0000 (16:37 +0100)
register_shrinker call is made in ashmem_init, it may return error code,
so we need to check it.

Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/android/ashmem.c

index 425c49f9330c6ad3fe981eb36014369fb3f2c718..8b52ca2af864dc3caaeeedb1c31773ce7dca01b9 100644 (file)
@@ -873,12 +873,18 @@ static int __init ashmem_init(void)
                goto out_free2;
        }
 
-       register_shrinker(&ashmem_shrinker);
+       ret = register_shrinker(&ashmem_shrinker);
+       if (ret) {
+               pr_err("failed to register shrinker!\n");
+               goto out_demisc;
+       }
 
        pr_info("initialized\n");
 
        return 0;
 
+out_demisc:
+       misc_deregister(&ashmem_misc);
 out_free2:
        kmem_cache_destroy(ashmem_range_cachep);
 out_free1: