Skip to content

Commit 94352d4

Browse files
acmeldavem330
authored andcommitted
net: Introduce sk_clone_lock() error path routine
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]>
1 parent d5afb6f commit 94352d4

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

include/net/sock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
15261526
void sk_free(struct sock *sk);
15271527
void sk_destruct(struct sock *sk);
15281528
struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority);
1529+
void sk_free_unlock_clone(struct sock *sk);
15291530

15301531
struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force,
15311532
gfp_t priority);

net/core/sock.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,11 +1539,7 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
15391539
is_charged = sk_filter_charge(newsk, filter);
15401540

15411541
if (unlikely(!is_charged || xfrm_sk_clone_policy(newsk, sk))) {
1542-
/* It is still raw copy of parent, so invalidate
1543-
* destructor and make plain sk_free() */
1544-
newsk->sk_destruct = NULL;
1545-
bh_unlock_sock(newsk);
1546-
sk_free(newsk);
1542+
sk_free_unlock_clone(newsk);
15471543
newsk = NULL;
15481544
goto out;
15491545
}
@@ -1592,6 +1588,16 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
15921588
}
15931589
EXPORT_SYMBOL_GPL(sk_clone_lock);
15941590

1591+
void sk_free_unlock_clone(struct sock *sk)
1592+
{
1593+
/* It is still raw copy of parent, so invalidate
1594+
* destructor and make plain sk_free() */
1595+
sk->sk_destruct = NULL;
1596+
bh_unlock_sock(sk);
1597+
sk_free(sk);
1598+
}
1599+
EXPORT_SYMBOL_GPL(sk_free_unlock_clone);
1600+
15951601
void sk_setup_caps(struct sock *sk, struct dst_entry *dst)
15961602
{
15971603
u32 max_segs = 1;

net/dccp/minisocks.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,7 @@ struct sock *dccp_create_openreq_child(const struct sock *sk,
119119
* Activate features: initialise CCIDs, sequence windows etc.
120120
*/
121121
if (dccp_feat_activate_values(newsk, &dreq->dreq_featneg)) {
122-
/* It is still raw copy of parent, so invalidate
123-
* destructor and make plain sk_free() */
124-
newsk->sk_destruct = NULL;
125-
bh_unlock_sock(newsk);
126-
sk_free(newsk);
122+
sk_free_unlock_clone(newsk);
127123
return NULL;
128124
}
129125
dccp_init_xmit_timers(newsk);

0 commit comments

Comments
 (0)