Commit 5bd5f5812bfa753218e02cb773e06ede48055798

Authored by Akinobu Mita
Committed by Linus Torvalds
1 parent cd123012d9

sunrpc: fix error path in module_init

register_rpc_pipefs() needs to clean up rpc_inode_cache
by kmem_cache_destroy() on register_filesystem() failure.

init_sunrpc() needs to unregister rpc_pipe_fs by unregister_rpc_pipefs()
when rpc_init_mempool() returns error.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Neil Brown <neilb@suse.de>
Cc: Trond Myklebust <trond.myklebust@fys.uio.no>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 2 changed files with 12 additions and 3 deletions Side-by-side Diff

net/sunrpc/rpc_pipe.c
... ... @@ -845,6 +845,8 @@
845 845  
846 846 int register_rpc_pipefs(void)
847 847 {
  848 + int err;
  849 +
848 850 rpc_inode_cachep = kmem_cache_create("rpc_inode_cache",
849 851 sizeof(struct rpc_inode),
850 852 0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
... ... @@ -852,7 +854,12 @@
852 854 init_once, NULL);
853 855 if (!rpc_inode_cachep)
854 856 return -ENOMEM;
855   - register_filesystem(&rpc_pipe_fs_type);
  857 + err = register_filesystem(&rpc_pipe_fs_type);
  858 + if (err) {
  859 + kmem_cache_destroy(rpc_inode_cachep);
  860 + return err;
  861 + }
  862 +
856 863 return 0;
857 864 }
858 865  
net/sunrpc/sunrpc_syms.c
... ... @@ -146,9 +146,11 @@
146 146 int err = register_rpc_pipefs();
147 147 if (err)
148 148 goto out;
149   - err = rpc_init_mempool() != 0;
150   - if (err)
  149 + err = rpc_init_mempool();
  150 + if (err) {
  151 + unregister_rpc_pipefs();
151 152 goto out;
  153 + }
152 154 #ifdef RPC_DEBUG
153 155 rpc_register_sysctl();
154 156 #endif