aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/core/sock.c44
1 files changed, 29 insertions, 15 deletions
diff --git a/net/core/sock.c b/net/core/sock.c
index 9c2dbfaca60d..6ee2ed104a83 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -870,6 +870,31 @@ static void sock_copy(struct sock *nsk, const struct sock *osk)
870#endif 870#endif
871} 871}
872 872
873static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority)
874{
875 struct sock *sk;
876 struct kmem_cache *slab;
877
878 slab = prot->slab;
879 if (slab != NULL)
880 sk = kmem_cache_alloc(slab, priority);
881 else
882 sk = kmalloc(prot->obj_size, priority);
883
884 return sk;
885}
886
887static void sk_prot_free(struct proto *prot, struct sock *sk)
888{
889 struct kmem_cache *slab;
890
891 slab = prot->slab;
892 if (slab != NULL)
893 kmem_cache_free(slab, sk);
894 else
895 kfree(sk);
896}
897
873/** 898/**
874 * sk_alloc - All socket objects are allocated here 899 * sk_alloc - All socket objects are allocated here
875 * @net: the applicable net namespace 900 * @net: the applicable net namespace
@@ -881,14 +906,9 @@ static void sock_copy(struct sock *nsk, const struct sock *osk)
881struct sock *sk_alloc(struct net *net, int family, gfp_t priority, 906struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
882 struct proto *prot, int zero_it) 907 struct proto *prot, int zero_it)
883{ 908{
884 struct sock *sk = NULL; 909 struct sock *sk;
885 struct kmem_cache *slab = prot->slab;
886
887 if (slab != NULL)
888 sk = kmem_cache_alloc(slab, priority);
889 else
890 sk = kmalloc(prot->obj_size, priority);
891 910
911 sk = sk_prot_alloc(prot, priority);
892 if (sk) { 912 if (sk) {
893 if (zero_it) { 913 if (zero_it) {
894 memset(sk, 0, prot->obj_size); 914 memset(sk, 0, prot->obj_size);
@@ -911,10 +931,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
911 return sk; 931 return sk;
912 932
913out_free: 933out_free:
914 if (slab != NULL) 934 sk_prot_free(prot, sk);
915 kmem_cache_free(slab, sk);
916 else
917 kfree(sk);
918 return NULL; 935 return NULL;
919} 936}
920 937
@@ -940,10 +957,7 @@ void sk_free(struct sock *sk)
940 957
941 security_sk_free(sk); 958 security_sk_free(sk);
942 put_net(sk->sk_net); 959 put_net(sk->sk_net);
943 if (sk->sk_prot_creator->slab != NULL) 960 sk_prot_free(sk->sk_prot_creator, sk);
944 kmem_cache_free(sk->sk_prot_creator->slab, sk);
945 else
946 kfree(sk);
947 module_put(owner); 961 module_put(owner);
948} 962}
949 963