linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 30/37] drivers/platform/x86: Use kmemdup
@ 2010-05-15 21:22 Julia Lawall
  2010-05-20 13:26 ` Matthew Garrett
  0 siblings, 1 reply; 2+ messages in thread
From: Julia Lawall @ 2010-05-15 21:22 UTC (permalink / raw)
  To: Carlos Corbacho, Matthew Garrett, platform-driver-x86,
	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/platform/x86/wmi.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff -u -p a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -756,12 +756,10 @@ static __init acpi_status parse_wdg(acpi
 
 	total = obj->buffer.length / sizeof(struct guid_block);
 
-	gblock = kzalloc(obj->buffer.length, GFP_KERNEL);
+	gblock = kmemdup(obj->buffer.pointer, obj->buffer.length, GFP_KERNEL);
 	if (!gblock)
 		return AE_NO_MEMORY;
 
-	memcpy(gblock, obj->buffer.pointer, obj->buffer.length);
-
 	for (i = 0; i < total; i++) {
 		/*
 		  Some WMI devices, like those for nVidia hooks, have a

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

* Re: [PATCH 30/37] drivers/platform/x86: Use kmemdup
  2010-05-15 21:22 [PATCH 30/37] drivers/platform/x86: Use kmemdup Julia Lawall
@ 2010-05-20 13:26 ` Matthew Garrett
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Garrett @ 2010-05-20 13:26 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Carlos Corbacho, platform-driver-x86, linux-kernel,
	kernel-janitors

Applied, thanks.

-- 
Matthew Garrett | mjg59@srcf.ucam.org

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

end of thread, other threads:[~2010-05-20 13:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-15 21:22 [PATCH 30/37] drivers/platform/x86: Use kmemdup Julia Lawall
2010-05-20 13:26 ` Matthew Garrett

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).