git: 6982be38cb7e - main - socket: Microoptimize soreceive_stream_locked()

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Mon, 19 Aug 2024 14:56:19 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=6982be38cb7e4254ff4ffbb334cd7e234b5f6cc2

commit 6982be38cb7e4254ff4ffbb334cd7e234b5f6cc2
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-07-05 18:01:29 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-08-19 14:52:39 +0000

    socket: Microoptimize soreceive_stream_locked()
    
    There is no need to hold the sockbuf lock while checking uio_resid.
    No functional change intended.
    
    MFC after:      2 weeks
    Sponsored by:   Klara, Inc.
    Sponsored by:   Stormshield
---
 sys/kern/uipc_socket.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index a5e88fc7ffc6..13b6253bd115 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -2604,14 +2604,12 @@ soreceive_stream_locked(struct socket *so, struct sockbuf *sb,
 
 	SOCK_IO_RECV_ASSERT_LOCKED(so);
 
-	SOCKBUF_LOCK(sb);
 	/* Easy one, no space to copyout anything. */
-	if (uio->uio_resid == 0) {
-		error = EINVAL;
-		goto out;
-	}
+	if (uio->uio_resid == 0)
+		return (EINVAL);
 	oresid = uio->uio_resid;
 
+	SOCKBUF_LOCK(sb);
 	/* We will never ever get anything unless we are or were connected. */
 	if (!(so->so_state & (SS_ISCONNECTED|SS_ISDISCONNECTED))) {
 		error = ENOTCONN;