Skip to content

Commit

Permalink
dlm: 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]>
Signed-off-by: David Teigland <[email protected]>
  • Loading branch information
musicakc authored and teigland committed Jun 23, 2016
1 parent 505ee52 commit 5c93f56
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions fs/dlm/lowcomms.c
Original file line number Diff line number Diff line change
Expand Up @@ -1279,10 +1279,9 @@ static void init_local(void)
if (dlm_our_addr(&sas, i))
break;

addr = kmalloc(sizeof(*addr), GFP_NOFS);
addr = kmemdup(&sas, sizeof(*addr), GFP_NOFS);
if (!addr)
break;
memcpy(addr, &sas, sizeof(*addr));
dlm_local_addr[dlm_local_count++] = addr;
}
}
Expand Down

0 comments on commit 5c93f56

Please sign in to comment.