mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 35/37] drivers/block/aoe: Use kmemdup
@ 2010-05-15 21:23 Julia Lawall
  2010-05-16 12:42 ` Ed Cashin
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2010-05-15 21:23 UTC (permalink / raw)
  To: Ed L. Cashin, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

Use kmemdup when some other buffer is immediately copied into the
allocated region.

A simplified version of the semantic patch that makes this change is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
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);
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 drivers/block/aoe/aoechr.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff -u -p a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -132,13 +132,12 @@ bail:		spin_unlock_irqrestore(&emsgs_loc
 		return;
 	}
 
-	mp = kmalloc(n, GFP_ATOMIC);
+	mp = kmemdup(msg, n, GFP_ATOMIC);
 	if (mp == NULL) {
 		printk(KERN_ERR "aoe: allocation failure, len=%ld\n", n);
 		goto bail;
 	}
 
-	memcpy(mp, msg, n);
 	em->msg = mp;
 	em->flags |= EMFL_VALID;
 	em->len = n;

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

end of thread, other threads:[~2010-05-16 16:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-15 21:23 [PATCH 35/37] drivers/block/aoe: Use kmemdup Julia Lawall
2010-05-16 12:42 ` Ed Cashin
2010-05-16 15:50   ` Dan Carpenter
2010-05-16 16:03     ` Julia Lawall
2010-05-16 16:38   ` Pekka Enberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®