linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nfsd4: Use kmemdup rather than duplicating its implementation
@ 2011-11-17 22:43 Thomas Meyer
  2011-11-22 20:26 ` J. Bruce Fields
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Meyer @ 2011-11-17 22:43 UTC (permalink / raw)
  To: linux-nfs, linux-kernel

The semantic patch that makes this change is available
in scripts/coccinelle/api/memdup.cocci.

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
---

diff -u -p a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
--- a/fs/nfsd/nfs4state.c 2011-11-07 19:38:23.353822940 +0100
+++ b/fs/nfsd/nfs4state.c 2011-11-08 10:34:05.545953251 +0100
@@ -985,12 +985,11 @@ static struct nfs4_client *alloc_client(
 	clp = kzalloc(sizeof(struct nfs4_client), GFP_KERNEL);
 	if (clp == NULL)
 		return NULL;
-	clp->cl_name.data = kmalloc(name.len, GFP_KERNEL);
+	clp->cl_name.data = kmemdup(name.data, name.len, GFP_KERNEL);
 	if (clp->cl_name.data == NULL) {
 		kfree(clp);
 		return NULL;
 	}
-	memcpy(clp->cl_name.data, name.data, name.len);
 	clp->cl_name.len = name.len;
 	return clp;
 }
diff -u -p a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
--- a/fs/nfsd/nfs4xdr.c 2011-11-07 19:38:23.357156324 +0100
+++ b/fs/nfsd/nfs4xdr.c 2011-11-08 10:34:08.289323359 +0100
@@ -215,10 +215,9 @@ defer_free(struct nfsd4_compoundargs *ar
 static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes)
 {
 	if (p == argp->tmp) {
-		p = kmalloc(nbytes, GFP_KERNEL);
+		p = kmemdup(argp->tmp, nbytes, GFP_KERNEL);
 		if (!p)
 			return NULL;
-		memcpy(p, argp->tmp, nbytes);
 	} else {
 		BUG_ON(p != argp->tmpp);
 		argp->tmpp = NULL;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] nfsd4: Use kmemdup rather than duplicating its implementation
  2011-11-17 22:43 [PATCH] nfsd4: Use kmemdup rather than duplicating its implementation Thomas Meyer
@ 2011-11-22 20:26 ` J. Bruce Fields
  0 siblings, 0 replies; 2+ messages in thread
From: J. Bruce Fields @ 2011-11-22 20:26 UTC (permalink / raw)
  To: Thomas Meyer; +Cc: linux-nfs, linux-kernel

On Thu, Nov 17, 2011 at 11:43:40PM +0100, Thomas Meyer wrote:
> The semantic patch that makes this change is available
> in scripts/coccinelle/api/memdup.cocci.

Thanks, applying for 3.3.--b.

> 
> Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
> ---
> 
> diff -u -p a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> --- a/fs/nfsd/nfs4state.c 2011-11-07 19:38:23.353822940 +0100
> +++ b/fs/nfsd/nfs4state.c 2011-11-08 10:34:05.545953251 +0100
> @@ -985,12 +985,11 @@ static struct nfs4_client *alloc_client(
>  	clp = kzalloc(sizeof(struct nfs4_client), GFP_KERNEL);
>  	if (clp == NULL)
>  		return NULL;
> -	clp->cl_name.data = kmalloc(name.len, GFP_KERNEL);
> +	clp->cl_name.data = kmemdup(name.data, name.len, GFP_KERNEL);
>  	if (clp->cl_name.data == NULL) {
>  		kfree(clp);
>  		return NULL;
>  	}
> -	memcpy(clp->cl_name.data, name.data, name.len);
>  	clp->cl_name.len = name.len;
>  	return clp;
>  }
> diff -u -p a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> --- a/fs/nfsd/nfs4xdr.c 2011-11-07 19:38:23.357156324 +0100
> +++ b/fs/nfsd/nfs4xdr.c 2011-11-08 10:34:08.289323359 +0100
> @@ -215,10 +215,9 @@ defer_free(struct nfsd4_compoundargs *ar
>  static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes)
>  {
>  	if (p == argp->tmp) {
> -		p = kmalloc(nbytes, GFP_KERNEL);
> +		p = kmemdup(argp->tmp, nbytes, GFP_KERNEL);
>  		if (!p)
>  			return NULL;
> -		memcpy(p, argp->tmp, nbytes);
>  	} else {
>  		BUG_ON(p != argp->tmpp);
>  		argp->tmpp = NULL;
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-11-22 20:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-17 22:43 [PATCH] nfsd4: Use kmemdup rather than duplicating its implementation Thomas Meyer
2011-11-22 20:26 ` J. Bruce Fields

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).