Skip to content

Commit

Permalink
net: make sock_inuse_add() available
Browse files Browse the repository at this point in the history
commit d477eb9 upstream.

MPTCP hard codes it, let us instead provide this helper.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
[ cherry-pick from amazon-linux amazon-5.15.y/mainline ]
Link: https://github.com/amazonlinux/linux/commit/7154d8eaac16
Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com>
Signed-off-by: He Zhe <zhe.he@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Eric Dumazet authored and Greg Kroah-Hartman committed May 2, 2025
1 parent 480469f commit 58de45f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
10 changes: 10 additions & 0 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -1472,13 +1472,23 @@ static inline void sock_prot_inuse_add(const struct net *net,
{
this_cpu_add(net->core.prot_inuse->val[prot->inuse_idx], val);
}

static inline void sock_inuse_add(const struct net *net, int val)
{
this_cpu_add(*net->core.sock_inuse, val);
}

int sock_prot_inuse_get(struct net *net, struct proto *proto);
int sock_inuse_get(struct net *net);
#else
static inline void sock_prot_inuse_add(const struct net *net,
const struct proto *prot, int val)
{
}

static inline void sock_inuse_add(const struct net *net, int val)
{
}
#endif


Expand Down
10 changes: 0 additions & 10 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@
static DEFINE_MUTEX(proto_list_mutex);
static LIST_HEAD(proto_list);

static void sock_inuse_add(struct net *net, int val);

/**
* sk_ns_capable - General socket capability test
* @sk: Socket to use a capability on or through
Expand Down Expand Up @@ -3519,11 +3517,6 @@ int sock_prot_inuse_get(struct net *net, struct proto *prot)
}
EXPORT_SYMBOL_GPL(sock_prot_inuse_get);

static void sock_inuse_add(struct net *net, int val)
{
this_cpu_add(*net->core.sock_inuse, val);
}

int sock_inuse_get(struct net *net)
{
int cpu, res = 0;
Expand Down Expand Up @@ -3602,9 +3595,6 @@ static inline void release_proto_idx(struct proto *prot)
{
}

static void sock_inuse_add(struct net *net, int val)
{
}
#endif

static void tw_prot_cleanup(struct timewait_sock_ops *twsk_prot)
Expand Down
4 changes: 1 addition & 3 deletions net/mptcp/subflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -1584,9 +1584,7 @@ int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock)
*/
sf->sk->sk_net_refcnt = 1;
get_net(net);
#ifdef CONFIG_PROC_FS
this_cpu_add(*net->core.sock_inuse, 1);
#endif
sock_inuse_add(net, 1);
err = tcp_set_ulp(sf->sk, "mptcp");
release_sock(sf->sk);

Expand Down

0 comments on commit 58de45f

Please sign in to comment.