ubifs: fix to check error code of register_shrinker
authorChao Yu <chao2.yu@samsung.com>
Mon, 18 May 2015 08:43:02 +0000 (16:43 +0800)
committerRichard Weinberger <richard@nod.at>
Tue, 2 Jun 2015 09:41:38 +0000 (11:41 +0200)
register_shrinker() in ubifs_init() can fail due to fail to call kzalloc.
This patch fixes to check the return value of register_shrinker, otherwise
our shrinker may be unregistered after ubifs initialized successfully.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
fs/ubifs/super.c

index 75e6f04bb795a9605a5d8c7cf6e4607b89a5f7cf..fa83d1bbba4473062615ffb8c8364435bad14c7a 100644 (file)
@@ -2245,7 +2245,9 @@ static int __init ubifs_init(void)
        if (!ubifs_inode_slab)
                return -ENOMEM;
 
-       register_shrinker(&ubifs_shrinker_info);
+       err = register_shrinker(&ubifs_shrinker_info);
+       if (err)
+               goto out_slab;
 
        err = ubifs_compressors_init();
        if (err)
@@ -2269,6 +2271,7 @@ out_compr:
        ubifs_compressors_exit();
 out_shrinker:
        unregister_shrinker(&ubifs_shrinker_info);
+out_slab:
        kmem_cache_destroy(ubifs_inode_slab);
        return err;
 }