linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ying Xue <ying.xue0@gmail.com>
To: Amitoj Kaur Chawla <amitoj1606@gmail.com>,
	jon.maloy@ericsson.com, davem@davemloft.net,
	netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Cc: julia.lawall@lip6.fr
Subject: Re: [PATCH] tipc: Use kmemdup instead of kmalloc and memcpy
Date: Mon, 27 Jun 2016 15:37:54 +0800	[thread overview]
Message-ID: <5770D7D2.7070204@gmail.com> (raw)
In-Reply-To: <20160623044937.GA14109@amitoj-Inspiron-3542>

On 06/23/2016 12:49 PM, Amitoj Kaur Chawla wrote:
> Replace calls to kmalloc followed by a memcpy with a direct call to
> kmemdup.
> 
> The Coccinelle semantic patch used to make this change is as follows:
> @@
> expression from,to,size,flag;
> statement S;
> @@
> 
> -  to = \(kmalloc\|kzalloc\)(size,flag);
> +  to = kmemdup(from,size,flag);
>    if (to==NULL || ...) S
> -  memcpy(to, from, size);
> 
> Signed-off-by: Amitoj Kaur Chawla <amitoj1606@gmail.com>

Acked-by: Ying Xue <ying.xue@windriver.com>

> ---
>  net/tipc/server.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/net/tipc/server.c b/net/tipc/server.c
> index 2446bfb..38a6f33 100644
> --- a/net/tipc/server.c
> +++ b/net/tipc/server.c
> @@ -411,13 +411,12 @@ static struct outqueue_entry *tipc_alloc_entry(void *data, int len)
>  	if (!entry)
>  		return NULL;
>  
> -	buf = kmalloc(len, GFP_ATOMIC);
> +	buf = kmemdup(data, len, GFP_ATOMIC);
>  	if (!buf) {
>  		kfree(entry);
>  		return NULL;
>  	}
>  
> -	memcpy(buf, data, len);
>  	entry->iov.iov_base = buf;
>  	entry->iov.iov_len = len;
>  
> 

  reply	other threads:[~2016-06-27  7:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-23  4:49 [PATCH] tipc: Use kmemdup instead of kmalloc and memcpy Amitoj Kaur Chawla
2016-06-27  7:37 ` Ying Xue [this message]
2016-06-27 13:59 ` David Miller

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=5770D7D2.7070204@gmail.com \
    --to=ying.xue0@gmail.com \
    --cc=amitoj1606@gmail.com \
    --cc=davem@davemloft.net \
    --cc=jon.maloy@ericsson.com \
    --cc=julia.lawall@lip6.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tipc-discussion@lists.sourceforge.net \
    /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 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).