staging: hv: Use kmemdup rather than duplicating its implementation
authorThomas Meyer <thomas@m3y3r.de>
Sat, 12 Nov 2011 12:21:49 +0000 (13:21 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Sun, 27 Nov 2011 01:03:56 +0000 (17:03 -0800)
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/hv/hv_mouse.c
drivers/staging/hv/netvsc.c

index 2c2e1b4e9b85f7f490ecc75c427b34db5895658e..a28c54983282975775b88e420afb175cb4dc0680 100644 (file)
@@ -201,13 +201,11 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device,
        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;
index b902579c7fe6802c26e7eb6882a37793ab7ce6e1..28e69a6c74a1a2e45b4d7b6d4553bf293e1ece27 100644 (file)
@@ -230,19 +230,14 @@ static int netvsc_init_recv_buf(struct hv_device *device)
        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