Skip to content

Commit 67114fe

Browse files
thomasmeyJ. Bruce Fields
authored and
J. Bruce Fields
committed
nfsd4: Use kmemdup rather than duplicating its implementation
The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci. Signed-off-by: Thomas Meyer <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent 009673b commit 67114fe

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

fs/nfsd/nfs4state.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,12 +986,11 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
986986
clp = kzalloc(sizeof(struct nfs4_client), GFP_KERNEL);
987987
if (clp == NULL)
988988
return NULL;
989-
clp->cl_name.data = kmalloc(name.len, GFP_KERNEL);
989+
clp->cl_name.data = kmemdup(name.data, name.len, GFP_KERNEL);
990990
if (clp->cl_name.data == NULL) {
991991
kfree(clp);
992992
return NULL;
993993
}
994-
memcpy(clp->cl_name.data, name.data, name.len);
995994
clp->cl_name.len = name.len;
996995
return clp;
997996
}

fs/nfsd/nfs4xdr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,9 @@ defer_free(struct nfsd4_compoundargs *argp,
215215
static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes)
216216
{
217217
if (p == argp->tmp) {
218-
p = kmalloc(nbytes, GFP_KERNEL);
218+
p = kmemdup(argp->tmp, nbytes, GFP_KERNEL);
219219
if (!p)
220220
return NULL;
221-
memcpy(p, argp->tmp, nbytes);
222221
} else {
223222
BUG_ON(p != argp->tmpp);
224223
argp->tmpp = NULL;

0 commit comments

Comments
 (0)