diff mbox series

[v2,5/5] pNFS: Clean up open coded kmemdup_nul()

Message ID 20201109211029.540993-6-trond.myklebust@hammerspace.com (mailing list archive)
State New, archived
Headers show
Series Add RDMA support to the pNFS file+flexfiles data channels | expand

Commit Message

Trond Myklebust Nov. 9, 2020, 9:10 p.m. UTC
From: Trond Myklebust <trond.myklebust@hammerspace.com>

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 fs/nfs/pnfs_nfs.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/fs/nfs/pnfs_nfs.c b/fs/nfs/pnfs_nfs.c
index d00750743100..5acddd14ffe8 100644
--- a/fs/nfs/pnfs_nfs.c
+++ b/fs/nfs/pnfs_nfs.c
@@ -1085,13 +1085,10 @@  nfs4_decode_mp_ds_addr(struct net *net, struct xdr_stream *xdr, gfp_t gfp_flags)
 	if (unlikely(!p))
 		goto out_err;
 
-	netid = kmalloc(nlen+1, gfp_flags);
+	netid = kmemdup_nul(p, nlen, gfp_flags);
 	if (unlikely(!netid))
 		goto out_err;
 
-	netid[nlen] = '\0';
-	memcpy(netid, p, nlen);
-
 	/* r_addr: ip/ip6addr with port in dec octets - see RFC 5665 */
 	p = xdr_inline_decode(xdr, 4);
 	if (unlikely(!p))
@@ -1108,13 +1105,11 @@  nfs4_decode_mp_ds_addr(struct net *net, struct xdr_stream *xdr, gfp_t gfp_flags)
 			rlen);
 		goto out_free_netid;
 	}
-	buf = kmalloc(rlen + 1, gfp_flags);
+	buf = kmemdup_nul(p, rlen, gfp_flags);
 	if (!buf) {
 		dprintk("%s: Not enough memory\n", __func__);
 		goto out_free_netid;
 	}
-	buf[rlen] = '\0';
-	memcpy(buf, p, rlen);
 
 	/* replace port '.' with '-' */
 	portstr = strrchr(buf, '.');