Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 72973
b: refs/heads/master
c: c308c1b
h: refs/heads/master
i:
  72971: d30fb70
v: v3
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Nov 1, 2007
1 parent 0559b6a commit efebfef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1e2e6b89f1d3152da0606d23e65e8760bf62a4c3
refs/heads/master: c308c1b20e2eb7b13f200a7c18b3f23561318367
44 changes: 29 additions & 15 deletions trunk/net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,31 @@ static void sock_copy(struct sock *nsk, const struct sock *osk)
#endif
}

static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority)
{
struct sock *sk;
struct kmem_cache *slab;

slab = prot->slab;
if (slab != NULL)
sk = kmem_cache_alloc(slab, priority);
else
sk = kmalloc(prot->obj_size, priority);

return sk;
}

static void sk_prot_free(struct proto *prot, struct sock *sk)
{
struct kmem_cache *slab;

slab = prot->slab;
if (slab != NULL)
kmem_cache_free(slab, sk);
else
kfree(sk);
}

/**
* sk_alloc - All socket objects are allocated here
* @net: the applicable net namespace
Expand All @@ -881,14 +906,9 @@ static void sock_copy(struct sock *nsk, const struct sock *osk)
struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
struct proto *prot, int zero_it)
{
struct sock *sk = NULL;
struct kmem_cache *slab = prot->slab;

if (slab != NULL)
sk = kmem_cache_alloc(slab, priority);
else
sk = kmalloc(prot->obj_size, priority);
struct sock *sk;

sk = sk_prot_alloc(prot, priority);
if (sk) {
if (zero_it) {
memset(sk, 0, prot->obj_size);
Expand All @@ -911,10 +931,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
return sk;

out_free:
if (slab != NULL)
kmem_cache_free(slab, sk);
else
kfree(sk);
sk_prot_free(prot, sk);
return NULL;
}

Expand All @@ -940,10 +957,7 @@ void sk_free(struct sock *sk)

security_sk_free(sk);
put_net(sk->sk_net);
if (sk->sk_prot_creator->slab != NULL)
kmem_cache_free(sk->sk_prot_creator->slab, sk);
else
kfree(sk);
sk_prot_free(sk->sk_prot_creator, sk);
module_put(owner);
}

Expand Down

0 comments on commit efebfef

Please sign in to comment.