[SOCK]: on failure free the sock from the right place
[linux-3.10.git] / net / core / sock.c
index 629ab4a5b45b5a0c45b100752080fc9a4d816980..4df4fa3c5de047e3ee099b64b38c4948b2dd406a 100644 (file)
@@ -641,7 +641,10 @@ struct sock *sk_alloc(int family, int priority, struct proto *prot, int zero_it)
                }
                
                if (security_sk_alloc(sk, family, priority)) {
-                       kmem_cache_free(slab, sk);
+                       if (slab != NULL)
+                               kmem_cache_free(slab, sk);
+                       else
+                               kfree(sk);
                        sk = NULL;
                } else
                        __module_get(prot->owner);
@@ -1359,8 +1362,6 @@ int proto_register(struct proto *prot, int alloc_slab)
 {
        int rc = -ENOBUFS;
 
-       write_lock(&proto_list_lock);
-
        if (alloc_slab) {
                prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0,
                                               SLAB_HWCACHE_ALIGN, NULL, NULL);
@@ -1368,14 +1369,15 @@ int proto_register(struct proto *prot, int alloc_slab)
                if (prot->slab == NULL) {
                        printk(KERN_CRIT "%s: Can't create sock SLAB cache!\n",
                               prot->name);
-                       goto out_unlock;
+                       goto out;
                }
        }
 
+       write_lock(&proto_list_lock);
        list_add(&prot->node, &proto_list);
-       rc = 0;
-out_unlock:
        write_unlock(&proto_list_lock);
+       rc = 0;
+out:
        return rc;
 }