Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tipc: Use kmemdup instead of kmalloc and memcpy

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>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Amitoj Kaur Chawla and committed by
David S. Miller
810bf110 ac5fd4f4

+1 -2
+1 -2
net/tipc/server.c
··· 418 418 if (!entry) 419 419 return NULL; 420 420 421 - buf = kmalloc(len, GFP_ATOMIC); 421 + buf = kmemdup(data, len, GFP_ATOMIC); 422 422 if (!buf) { 423 423 kfree(entry); 424 424 return NULL; 425 425 } 426 426 427 - memcpy(buf, data, len); 428 427 entry->iov.iov_base = buf; 429 428 entry->iov.iov_len = len; 430 429