Skip to content

Commit

Permalink
mptcp: avoid unneeded __mptcp_nmpc_socket() usage
Browse files Browse the repository at this point in the history
In a few spots, the mptcp code invokes the __mptcp_nmpc_socket() helper
multiple times under the same socket lock scope. Additionally, in such
places, the socket status ensures that there is no MP capable handshake
running.

Under the above condition we can replace the later __mptcp_nmpc_socket()
helper invocation with direct access to the msk->subflow pointer and
better document such access is not supposed to fail with WARN().

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Paolo Abeni authored and David S. Miller committed Apr 17, 2023
1 parent 7a486c4 commit 6176123
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions net/mptcp/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -3143,7 +3143,7 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
struct socket *listener;
struct sock *newsk;

listener = __mptcp_nmpc_socket(msk);
listener = msk->subflow;
if (WARN_ON_ONCE(!listener)) {
*err = -EINVAL;
return NULL;
Expand Down Expand Up @@ -3363,7 +3363,7 @@ static int mptcp_get_port(struct sock *sk, unsigned short snum)
struct mptcp_sock *msk = mptcp_sk(sk);
struct socket *ssock;

ssock = __mptcp_nmpc_socket(msk);
ssock = msk->subflow;
pr_debug("msk=%p, subflow=%p", msk, ssock);
if (WARN_ON_ONCE(!ssock))
return -EINVAL;
Expand Down Expand Up @@ -3709,7 +3709,10 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,

pr_debug("msk=%p", msk);

ssock = __mptcp_nmpc_socket(msk);
/* buggy applications can call accept on socket states other then LISTEN
* but no need to allocate the first subflow just to error out.
*/
ssock = msk->subflow;
if (!ssock)
return -EINVAL;

Expand Down

0 comments on commit 6176123

Please sign in to comment.