mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] staging: hv: Use kmemdup rather than duplicating its implementation
@ 2011-11-12 12:21 Thomas Meyer
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Meyer @ 2011-11-12 12:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman, devel, linux-kernel

Use kmemdup rather than duplicating its implementation

The semantic patch that makes this change is available
in scripts/coccinelle/api/memdup.cocci.

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
---

diff -u -p a/drivers/staging/hv/hv_mouse.c b/drivers/staging/hv/hv_mouse.c
--- a/drivers/staging/hv/hv_mouse.c 2011-11-07 19:38:10.923634136 +0100
+++ b/drivers/staging/hv/hv_mouse.c 2011-11-08 10:52:29.944091035 +0100
@@ -205,13 +205,11 @@ static void mousevsc_on_receive_device_i
 	desc = &device_info->hid_descriptor;
 	WARN_ON(desc->bLength == 0);
 
-	input_device->hid_desc = kzalloc(desc->bLength, GFP_ATOMIC);
+	input_device->hid_desc = kmemdup(desc, desc->bLength, GFP_ATOMIC);
 
 	if (!input_device->hid_desc)
 		goto cleanup;
 
-	memcpy(input_device->hid_desc, desc, desc->bLength);
-
 	input_device->report_desc_size = desc->desc[0].wDescriptorLength;
 	if (input_device->report_desc_size == 0)
 		goto cleanup;
diff -u -p a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c
--- a/drivers/staging/hv/netvsc.c 2011-11-07 19:38:10.923634136 +0100
+++ b/drivers/staging/hv/netvsc.c 2011-11-08 10:52:30.410763958 +0100
@@ -230,19 +230,14 @@ static int netvsc_init_recv_buf(struct h
 	net_device->recv_section_cnt = init_packet->msg.
 		v1_msg.send_recv_buf_complete.num_sections;
 
-	net_device->recv_section = kmalloc(net_device->recv_section_cnt
-		* sizeof(struct nvsp_1_receive_buffer_section), GFP_KERNEL);
+	net_device->recv_section = kmemdup(init_packet->msg.v1_msg.send_recv_buf_complete.sections,
+					   net_device->recv_section_cnt * sizeof(struct nvsp_1_receive_buffer_section),
+					   GFP_KERNEL);
 	if (net_device->recv_section == NULL) {
 		ret = -EINVAL;
 		goto cleanup;
 	}
 
-	memcpy(net_device->recv_section,
-		init_packet->msg.v1_msg.
-	       send_recv_buf_complete.sections,
-		net_device->recv_section_cnt *
-	       sizeof(struct nvsp_1_receive_buffer_section));
-
 	/*
 	 * For 1st release, there should only be 1 section that represents the
 	 * entire receive buffer



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

* [PATCH] staging: hv: Use kmemdup rather than duplicating its implementation
@ 2011-11-12 17:04 Thomas Meyer
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Meyer @ 2011-11-12 17:04 UTC (permalink / raw)
  To: Greg Kroah-Hartman, devel, linux-kernel

Use kmemdup rather than duplicating its implementation

The semantic patch that makes this change is available
in scripts/coccinelle/api/memdup.cocci.

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
---

diff -u -p a/drivers/staging/hv/hv_mouse.c b/drivers/staging/hv/hv_mouse.c
--- a/drivers/staging/hv/hv_mouse.c 2011-11-07 19:38:10.923634136 +0100
+++ b/drivers/staging/hv/hv_mouse.c 2011-11-08 10:52:29.944091035 +0100
@@ -205,13 +205,11 @@ static void mousevsc_on_receive_device_i
 	desc = &device_info->hid_descriptor;
 	WARN_ON(desc->bLength == 0);
 
-	input_device->hid_desc = kzalloc(desc->bLength, GFP_ATOMIC);
+	input_device->hid_desc = kmemdup(desc, desc->bLength, GFP_ATOMIC);
 
 	if (!input_device->hid_desc)
 		goto cleanup;
 
-	memcpy(input_device->hid_desc, desc, desc->bLength);
-
 	input_device->report_desc_size = desc->desc[0].wDescriptorLength;
 	if (input_device->report_desc_size == 0)
 		goto cleanup;
diff -u -p a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c
--- a/drivers/staging/hv/netvsc.c 2011-11-07 19:38:10.923634136 +0100
+++ b/drivers/staging/hv/netvsc.c 2011-11-08 10:52:30.410763958 +0100
@@ -230,19 +230,14 @@ static int netvsc_init_recv_buf(struct h
 	net_device->recv_section_cnt = init_packet->msg.
 		v1_msg.send_recv_buf_complete.num_sections;
 
-	net_device->recv_section = kmalloc(net_device->recv_section_cnt
-		* sizeof(struct nvsp_1_receive_buffer_section), GFP_KERNEL);
+	net_device->recv_section = kmemdup(init_packet->msg.v1_msg.send_recv_buf_complete.sections,
+					   net_device->recv_section_cnt * sizeof(struct nvsp_1_receive_buffer_section),
+					   GFP_KERNEL);
 	if (net_device->recv_section == NULL) {
 		ret = -EINVAL;
 		goto cleanup;
 	}
 
-	memcpy(net_device->recv_section,
-		init_packet->msg.v1_msg.
-	       send_recv_buf_complete.sections,
-		net_device->recv_section_cnt *
-	       sizeof(struct nvsp_1_receive_buffer_section));
-
 	/*
 	 * For 1st release, there should only be 1 section that represents the
 	 * entire receive buffer




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

end of thread, other threads:[~2011-11-12 17:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-12 12:21 [PATCH] staging: hv: Use kmemdup rather than duplicating its implementation Thomas Meyer
2011-11-12 17:04 Thomas Meyer

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®