From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>
Subject: [PATCH v1 net-next 02/15] af_unix: Clean up error paths in unix_stream_connect().
Date: Fri, 6 Dec 2024 14:25:54 +0900 [thread overview]
Message-ID: <20241206052607.1197-3-kuniyu@amazon.com> (raw)
In-Reply-To: <20241206052607.1197-1-kuniyu@amazon.com>
The label order is weird in unix_stream_connect(), and all NULL checks
are unnecessary if reordered.
Let's clean up the error paths to make it easy to set a drop reason
for each path.
While at it, a comment with the old style is updated.
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
net/unix/af_unix.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 6435ce699289..bdf88ddfb3e4 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1563,15 +1563,14 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
/* First of all allocate resources.
- If we will make it after state is locked,
- we will have to recheck all again in any case.
+ * If we will make it after state is locked,
+ * we will have to recheck all again in any case.
*/
/* create new sock for complete connection */
newsk = unix_create1(net, NULL, 0, sock->type);
if (IS_ERR(newsk)) {
err = PTR_ERR(newsk);
- newsk = NULL;
goto out;
}
@@ -1579,7 +1578,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
skb = sock_wmalloc(newsk, 1, 0, GFP_KERNEL);
if (!skb) {
err = -ENOMEM;
- goto out;
+ goto out_free_sk;
}
restart:
@@ -1587,8 +1586,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
other = unix_find_other(net, sunaddr, addr_len, sk->sk_type);
if (IS_ERR(other)) {
err = PTR_ERR(other);
- other = NULL;
- goto out;
+ goto out_free_skb;
}
unix_state_lock(other);
@@ -1613,11 +1611,12 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
}
timeo = unix_wait_for_peer(other, timeo);
+ sock_put(other);
err = sock_intr_errno(timeo);
if (signal_pending(current))
- goto out;
- sock_put(other);
+ goto out_free_skb;
+
goto restart;
}
@@ -1702,15 +1701,13 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
return 0;
out_unlock:
- if (other)
- unix_state_unlock(other);
-
-out:
+ unix_state_unlock(other);
+ sock_put(other);
+out_free_skb:
kfree_skb(skb);
- if (newsk)
- unix_release_sock(newsk, 0);
- if (other)
- sock_put(other);
+out_free_sk:
+ unix_release_sock(newsk, 0);
+out:
return err;
}
--
2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2024-12-06 5:27 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-06 5:25 [PATCH v1 net-next 00/15] af_unix: Prepare for skb drop reason Kuniyuki Iwashima
2024-12-06 5:25 ` [PATCH v1 net-next 01/15] af_unix: Set error only when needed in unix_stream_connect() Kuniyuki Iwashima
2024-12-06 5:25 ` Kuniyuki Iwashima [this message]
2024-12-06 5:25 ` [PATCH v1 net-next 03/15] af_unix: Set error only when needed in unix_stream_sendmsg() Kuniyuki Iwashima
2024-12-06 5:25 ` [PATCH v1 net-next 04/15] af_unix: Remove redundant SEND_SHUTDOWN check " Kuniyuki Iwashima
2024-12-10 11:48 ` Paolo Abeni
2024-12-13 8:18 ` Kuniyuki Iwashima
2024-12-06 5:25 ` [PATCH v1 net-next 05/15] af_unix: Clean up error paths " Kuniyuki Iwashima
2024-12-06 5:25 ` [PATCH v1 net-next 06/15] af_unix: Set error only when needed in unix_dgram_sendmsg() Kuniyuki Iwashima
2024-12-06 5:25 ` [PATCH v1 net-next 07/15] af_unix: Call unix_autobind() only when msg_namelen is specified " Kuniyuki Iwashima
2024-12-10 11:11 ` Paolo Abeni
2024-12-10 11:33 ` Kuniyuki Iwashima
2024-12-06 5:26 ` [PATCH v1 net-next 08/15] af_unix: Move !sunaddr case " Kuniyuki Iwashima
2024-12-06 5:26 ` [PATCH v1 net-next 09/15] af_unix: Use msg->{msg_name,msg_namelen} " Kuniyuki Iwashima
2024-12-06 5:26 ` [PATCH v1 net-next 10/15] af_unix: Split restart label " Kuniyuki Iwashima
2024-12-06 5:26 ` [PATCH v1 net-next 11/15] af_unix: Defer sock_put() to clean up path " Kuniyuki Iwashima
2024-12-06 5:26 ` [PATCH v1 net-next 12/15] af_unix: Clean up SOCK_DEAD error paths " Kuniyuki Iwashima
2024-12-06 5:26 ` [PATCH v1 net-next 13/15] af_unix: Clean up error path " Kuniyuki Iwashima
2024-12-06 5:26 ` [PATCH v1 net-next 14/15] af_unix: Remove sk_locked logic " Kuniyuki Iwashima
2024-12-10 11:42 ` Paolo Abeni
2024-12-13 8:26 ` Kuniyuki Iwashima
2024-12-06 5:26 ` [PATCH v1 net-next 15/15] af_unix: Remove unix_our_peer() Kuniyuki Iwashima
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241206052607.1197-3-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).