Skip to content

Commit e56c57d

Browse files
Eric Dumazetdavem330
authored andcommitted
net: rename sk_clone to sk_clone_lock
Make clear that sk_clone() and inet_csk_clone() return a locked socket. Add _lock() prefix and kerneldoc. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9ecd04b commit e56c57d

File tree

6 files changed

+29
-13
lines changed

6 files changed

+29
-13
lines changed

include/net/inet_connection_sock.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ static inline void *inet_csk_ca(const struct sock *sk)
143143
return (void *)inet_csk(sk)->icsk_ca_priv;
144144
}
145145

146-
extern struct sock *inet_csk_clone(struct sock *sk,
147-
const struct request_sock *req,
148-
const gfp_t priority);
146+
extern struct sock *inet_csk_clone_lock(const struct sock *sk,
147+
const struct request_sock *req,
148+
const gfp_t priority);
149149

150150
enum inet_csk_ack_state_t {
151151
ICSK_ACK_SCHED = 1,

include/net/sock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,8 +1089,8 @@ extern struct sock *sk_alloc(struct net *net, int family,
10891089
struct proto *prot);
10901090
extern void sk_free(struct sock *sk);
10911091
extern void sk_release_kernel(struct sock *sk);
1092-
extern struct sock *sk_clone(const struct sock *sk,
1093-
const gfp_t priority);
1092+
extern struct sock *sk_clone_lock(const struct sock *sk,
1093+
const gfp_t priority);
10941094

10951095
extern struct sk_buff *sock_wmalloc(struct sock *sk,
10961096
unsigned long size, int force,

net/core/sock.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,14 @@ void sk_release_kernel(struct sock *sk)
12041204
}
12051205
EXPORT_SYMBOL(sk_release_kernel);
12061206

1207-
struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
1207+
/**
1208+
* sk_clone_lock - clone a socket, and lock its clone
1209+
* @sk: the socket to clone
1210+
* @priority: for allocation (%GFP_KERNEL, %GFP_ATOMIC, etc)
1211+
*
1212+
* Caller must unlock socket even in error path (bh_unlock_sock(newsk))
1213+
*/
1214+
struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
12081215
{
12091216
struct sock *newsk;
12101217

@@ -1297,7 +1304,7 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
12971304
out:
12981305
return newsk;
12991306
}
1300-
EXPORT_SYMBOL_GPL(sk_clone);
1307+
EXPORT_SYMBOL_GPL(sk_clone_lock);
13011308

13021309
void sk_setup_caps(struct sock *sk, struct dst_entry *dst)
13031310
{

net/dccp/minisocks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct sock *dccp_create_openreq_child(struct sock *sk,
100100
* (* Generate a new socket and switch to that socket *)
101101
* Set S := new socket for this port pair
102102
*/
103-
struct sock *newsk = inet_csk_clone(sk, req, GFP_ATOMIC);
103+
struct sock *newsk = inet_csk_clone_lock(sk, req, GFP_ATOMIC);
104104

105105
if (newsk != NULL) {
106106
struct dccp_request_sock *dreq = dccp_rsk(req);

net/ipv4/inet_connection_sock.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,19 @@ void inet_csk_reqsk_queue_prune(struct sock *parent,
588588
}
589589
EXPORT_SYMBOL_GPL(inet_csk_reqsk_queue_prune);
590590

591-
struct sock *inet_csk_clone(struct sock *sk, const struct request_sock *req,
592-
const gfp_t priority)
591+
/**
592+
* inet_csk_clone_lock - clone an inet socket, and lock its clone
593+
* @sk: the socket to clone
594+
* @req: request_sock
595+
* @priority: for allocation (%GFP_KERNEL, %GFP_ATOMIC, etc)
596+
*
597+
* Caller must unlock socket even in error path (bh_unlock_sock(newsk))
598+
*/
599+
struct sock *inet_csk_clone_lock(const struct sock *sk,
600+
const struct request_sock *req,
601+
const gfp_t priority)
593602
{
594-
struct sock *newsk = sk_clone(sk, priority);
603+
struct sock *newsk = sk_clone_lock(sk, priority);
595604

596605
if (newsk != NULL) {
597606
struct inet_connection_sock *newicsk = inet_csk(newsk);
@@ -615,7 +624,7 @@ struct sock *inet_csk_clone(struct sock *sk, const struct request_sock *req,
615624
}
616625
return newsk;
617626
}
618-
EXPORT_SYMBOL_GPL(inet_csk_clone);
627+
EXPORT_SYMBOL_GPL(inet_csk_clone_lock);
619628

620629
/*
621630
* At this point, there should be no process reference to this

net/ipv4/tcp_minisocks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ static inline void TCP_ECN_openreq_child(struct tcp_sock *tp,
425425
*/
426426
struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req, struct sk_buff *skb)
427427
{
428-
struct sock *newsk = inet_csk_clone(sk, req, GFP_ATOMIC);
428+
struct sock *newsk = inet_csk_clone_lock(sk, req, GFP_ATOMIC);
429429

430430
if (newsk != NULL) {
431431
const struct inet_request_sock *ireq = inet_rsk(req);

0 commit comments

Comments
 (0)