Skip to content

Commit

Permalink
tipc: Use kmemdup instead of kmalloc and memcpy
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Ying Xue <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
musicakc authored and davem330 committed Jun 27, 2016
1 parent ac5fd4f commit 810bf11
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions net/tipc/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,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;

Expand Down

0 comments on commit 810bf11

Please sign in to comment.