diff mbox series

[v2,7/8] SUNRPC: svc_tcp_sendmsg() should handle errors from xdr_alloc_bvec()

Message ID 20220407184601.1064640-7-trondmy@kernel.org (mailing list archive)
State New, archived
Headers show
Series [v2,1/8] NFSv4.2: Fix missing removal of SLAB_ACCOUNT on kmem_cache allocation | expand

Commit Message

Trond Myklebust April 7, 2022, 6:46 p.m. UTC
From: Trond Myklebust <trond.myklebust@hammerspace.com>

The allocation is done with GFP_KERNEL, but it could still fail in a low
memory situation.

Fixes: 4a85a6a3320b ("SUNRPC: Handle TCP socket sends with kernel_sendpage() again")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 net/sunrpc/svcsock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Trond Myklebust April 7, 2022, 7:23 p.m. UTC | #1
On Thu, 2022-04-07 at 14:46 -0400, trondmy@kernel.org wrote:
> From: Trond Myklebust <trond.myklebust@hammerspace.com>
> 
> The allocation is done with GFP_KERNEL, but it could still fail in a
> low
> memory situation.
> 
> Fixes: 4a85a6a3320b ("SUNRPC: Handle TCP socket sends with
> kernel_sendpage() again")
> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> ---
>  net/sunrpc/svcsock.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
> index 478f857cdaed..6ea3d87e1147 100644
> --- a/net/sunrpc/svcsock.c
> +++ b/net/sunrpc/svcsock.c
> @@ -1096,7 +1096,9 @@ static int svc_tcp_sendmsg(struct socket *sock,
> struct xdr_buf *xdr,
>         int ret;
>  
>         *sentp = 0;
> -       xdr_alloc_bvec(xdr, GFP_KERNEL);
> +       ret = xdr_alloc_bvec(xdr, GFP_KERNEL);
> +       if (ret < 0)
> +               return ret;
>  
>         ret = kernel_sendmsg(sock, &msg, &rm, 1, rm.iov_len);
>         if (ret < 0)


Chuck,

Do you mind if I send this and the 8/8 as part of the client pull
request? I saw this while I was digging through the code and separating
out the client and server uses of xdr_alloc_bvec().
Chuck Lever III April 7, 2022, 7:30 p.m. UTC | #2
> On Apr 7, 2022, at 3:23 PM, Trond Myklebust <trondmy@hammerspace.com> wrote:
> 
> On Thu, 2022-04-07 at 14:46 -0400, trondmy@kernel.org wrote:
>> From: Trond Myklebust <trond.myklebust@hammerspace.com>
>> 
>> The allocation is done with GFP_KERNEL, but it could still fail in a
>> low
>> memory situation.
>> 
>> Fixes: 4a85a6a3320b ("SUNRPC: Handle TCP socket sends with
>> kernel_sendpage() again")
>> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
>> ---
>>  net/sunrpc/svcsock.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>> 
>> diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
>> index 478f857cdaed..6ea3d87e1147 100644
>> --- a/net/sunrpc/svcsock.c
>> +++ b/net/sunrpc/svcsock.c
>> @@ -1096,7 +1096,9 @@ static int svc_tcp_sendmsg(struct socket *sock,
>> struct xdr_buf *xdr,
>>         int ret;
>>  
>>         *sentp = 0;
>> -       xdr_alloc_bvec(xdr, GFP_KERNEL);
>> +       ret = xdr_alloc_bvec(xdr, GFP_KERNEL);
>> +       if (ret < 0)
>> +               return ret;
>>  
>>         ret = kernel_sendmsg(sock, &msg, &rm, 1, rm.iov_len);
>>         if (ret < 0)
> 
> 
> Chuck,
> 
> Do you mind if I send this and the 8/8 as part of the client pull
> request? I saw this while I was digging through the code and separating
> out the client and server uses of xdr_alloc_bvec().

I browsed through these a few minutes ago. I don't see any technical
issues. But as you're listed as a maintainer of the SUNRPC code, I
didn't think I needed to give explicit permission.


--
Chuck Lever
diff mbox series

Patch

diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 478f857cdaed..6ea3d87e1147 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -1096,7 +1096,9 @@  static int svc_tcp_sendmsg(struct socket *sock, struct xdr_buf *xdr,
 	int ret;
 
 	*sentp = 0;
-	xdr_alloc_bvec(xdr, GFP_KERNEL);
+	ret = xdr_alloc_bvec(xdr, GFP_KERNEL);
+	if (ret < 0)
+		return ret;
 
 	ret = kernel_sendmsg(sock, &msg, &rm, 1, rm.iov_len);
 	if (ret < 0)