Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 72975
b: refs/heads/master
c: 2e4afe7
h: refs/heads/master
i:
  72973: efebfef
  72971: d30fb70
  72967: 1d00669
  72959: c7a4b3c
v: v3
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Nov 1, 2007
1 parent 0a4846e commit 8c58cdc
Show file tree
Hide file tree
Showing 2 changed files with 27 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: 3f0666ee3039443fa7b7cf436dd16ce0dd8e3f95
refs/heads/master: 2e4afe7b35458beedba418a6e2aaf0b0ac82cc18
41 changes: 26 additions & 15 deletions trunk/net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,8 @@ static void sock_copy(struct sock *nsk, const struct sock *osk)
#endif
}

static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority)
static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority,
int family)
{
struct sock *sk;
struct kmem_cache *slab;
Expand All @@ -881,18 +882,40 @@ static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority)
else
sk = kmalloc(prot->obj_size, priority);

if (sk != NULL) {
if (security_sk_alloc(sk, family, priority))
goto out_free;

if (!try_module_get(prot->owner))
goto out_free_sec;
}

return sk;

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

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

owner = prot->owner;
slab = prot->slab;

security_sk_free(sk);
if (slab != NULL)
kmem_cache_free(slab, sk);
else
kfree(sk);
module_put(owner);
}

/**
Expand All @@ -911,7 +934,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
if (zero_it)
priority |= __GFP_ZERO;

sk = sk_prot_alloc(prot, priority);
sk = sk_prot_alloc(prot, priority, family);
if (sk) {
if (zero_it) {
sk->sk_family = family;
Expand All @@ -923,24 +946,14 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
sock_lock_init(sk);
sk->sk_net = get_net(net);
}

if (security_sk_alloc(sk, family, priority))
goto out_free;

if (!try_module_get(prot->owner))
goto out_free;
}
return sk;

out_free:
sk_prot_free(prot, sk);
return NULL;
return sk;
}

void sk_free(struct sock *sk)
{
struct sk_filter *filter;
struct module *owner = sk->sk_prot_creator->owner;

if (sk->sk_destruct)
sk->sk_destruct(sk);
Expand All @@ -957,10 +970,8 @@ void sk_free(struct sock *sk)
printk(KERN_DEBUG "%s: optmem leakage (%d bytes) detected.\n",
__FUNCTION__, atomic_read(&sk->sk_omem_alloc));

security_sk_free(sk);
put_net(sk->sk_net);
sk_prot_free(sk->sk_prot_creator, sk);
module_put(owner);
}

struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
Expand Down

0 comments on commit 8c58cdc

Please sign in to comment.