Skip to content

Commit

Permalink
net: Introduce sk_clone_lock() error path routine
Browse files Browse the repository at this point in the history
When handling problems in cloning a socket with the sk_clone_locked()
function we need to perform several steps that were open coded in it and
its callers, so introduce a routine to avoid this duplication:
sk_free_unlock_clone().

Cc: Cong Wang <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Gerrit Renker <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
acmel authored and davem330 committed Mar 2, 2017
1 parent d5afb6f commit 94352d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
void sk_free(struct sock *sk);
void sk_destruct(struct sock *sk);
struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority);
void sk_free_unlock_clone(struct sock *sk);

struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force,
gfp_t priority);
Expand Down
16 changes: 11 additions & 5 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1539,11 +1539,7 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
is_charged = sk_filter_charge(newsk, filter);

if (unlikely(!is_charged || xfrm_sk_clone_policy(newsk, sk))) {
/* It is still raw copy of parent, so invalidate
* destructor and make plain sk_free() */
newsk->sk_destruct = NULL;
bh_unlock_sock(newsk);
sk_free(newsk);
sk_free_unlock_clone(newsk);
newsk = NULL;
goto out;
}
Expand Down Expand Up @@ -1592,6 +1588,16 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
}
EXPORT_SYMBOL_GPL(sk_clone_lock);

void sk_free_unlock_clone(struct sock *sk)
{
/* It is still raw copy of parent, so invalidate
* destructor and make plain sk_free() */
sk->sk_destruct = NULL;
bh_unlock_sock(sk);
sk_free(sk);
}
EXPORT_SYMBOL_GPL(sk_free_unlock_clone);

void sk_setup_caps(struct sock *sk, struct dst_entry *dst)
{
u32 max_segs = 1;
Expand Down
6 changes: 1 addition & 5 deletions net/dccp/minisocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ struct sock *dccp_create_openreq_child(const struct sock *sk,
* Activate features: initialise CCIDs, sequence windows etc.
*/
if (dccp_feat_activate_values(newsk, &dreq->dreq_featneg)) {
/* It is still raw copy of parent, so invalidate
* destructor and make plain sk_free() */
newsk->sk_destruct = NULL;
bh_unlock_sock(newsk);
sk_free(newsk);
sk_free_unlock_clone(newsk);
return NULL;
}
dccp_init_xmit_timers(newsk);
Expand Down

0 comments on commit 94352d4

Please sign in to comment.