sunrpc: Fix return value of get_srcport()
authorAnna Schumaker <Anna.Schumaker@Netapp.com>
Tue, 20 Jul 2021 20:04:42 +0000 (16:04 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 18 Sep 2021 11:40:14 +0000 (13:40 +0200)
[ Upstream commit 5d46dd04cb68771f77ba66dbf6fd323a4a2ce00d ]

Since bc1c56e9bbe9 transport->srcport may by unset, causing
get_srcport() to return 0 when called. Fix this by querying the port
from the underlying socket instead of the transport.

Fixes: bc1c56e9bbe9 (SUNRPC: prevent port reuse on transports which don't request it)
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/sunrpc/xprtsock.c

index 7d7c08a..16c7758 100644 (file)
@@ -1642,7 +1642,7 @@ static int xs_get_srcport(struct sock_xprt *transport)
 unsigned short get_srcport(struct rpc_xprt *xprt)
 {
        struct sock_xprt *sock = container_of(xprt, struct sock_xprt, xprt);
-       return sock->srcport;
+       return xs_sock_getport(sock->sock);
 }
 EXPORT_SYMBOL(get_srcport);