All of lore.kernel.org
 help / color / mirror / Atom feed
From: trondmy@gmail.com
To: linux-nfs@vger.kernel.org
Subject: [PATCH v2 5/5] pNFS: Clean up open coded kmemdup_nul()
Date: Mon,  9 Nov 2020 16:10:29 -0500	[thread overview]
Message-ID: <20201109211029.540993-6-trond.myklebust@hammerspace.com> (raw)
In-Reply-To: <20201109211029.540993-5-trond.myklebust@hammerspace.com>

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 --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, '.');
-- 
2.28.0


  reply	other threads:[~2020-11-09 21:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-09 21:10 [PATCH v2 0/5] Add RDMA support to the pNFS file+flexfiles data channels trondmy
2020-11-09 21:10 ` [PATCH v2 1/5] SUNRPC: xprt_load_transport() needs to support the netid "rdma6" trondmy
2020-11-09 21:10   ` [PATCH v2 2/5] NFSv4/pNFS: Use connections to a DS that are all of the same protocol family trondmy
2020-11-09 21:10     ` [PATCH v2 3/5] NFSv4/pNFS: Store the transport type in struct nfs4_pnfs_ds_addr trondmy
2020-11-09 21:10       ` [PATCH v2 4/5] pNFS/flexfiles: Fix up layoutstats reporting for non-TCP transports trondmy
2020-11-09 21:10         ` trondmy [this message]
2020-11-09 21:50   ` [PATCH v2 1/5] SUNRPC: xprt_load_transport() needs to support the netid "rdma6" Chuck Lever
2020-11-09 22:06     ` Trond Myklebust

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=20201109211029.540993-6-trond.myklebust@hammerspace.com \
    --to=trondmy@gmail.com \
    --cc=linux-nfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.