Use kmemdup_nul() helper instead of open-coding to simplify the code. Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx> --- fs/nfs/nfs4proc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index e6b49d6318bc..60fcd98b40a6 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -4004,11 +4004,10 @@ static void test_fs_location_for_trunking(struct nfs4_fs_location *location, return; xprt_args.dstaddr = &addr; xprt_args.addrlen = addrlen; - servername = kmalloc(srv_loc->len + 1, GFP_KERNEL); + servername = kmemdup_nul(srv_loc->data, srv_loc->len, + GFP_KERNEL); if (!servername) return; - memcpy(servername, srv_loc->data, srv_loc->len); - servername[srv_loc->len] = '\0'; xprt_args.servername = servername; xprtdata.cred = nfs4_get_clid_cred(clp); -- 2.25.1