imamnurby/smpl_train_seed8 huggingface dataset:
--- initial
+++ final
@@ -1,25 +1,24 @@
 int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len) {
   u8 *buf = NULL;
   if (len > MAX_WPA_IE_LEN || (len && ie == NULL)) {
     printk("return error out, len:%zu\n", len);
     return -EINVAL;
   }
   if (len) {
     if (len != ie[1] + 2) {
       printk("len:%zu, ie:%d\n", len, ie[1]);
       return -EINVAL;
     }
-    buf = kmalloc(len, GFP_KERNEL);
+    buf = kmemdup(ie, len, GFP_KERNEL);
     if (buf == NULL) return -ENOMEM;
-    memcpy(buf, ie, len);
     kfree(ieee->wpa_ie);
     ieee->wpa_ie = buf;
     ieee->wpa_ie_len = len;
   } else {
     if (ieee->wpa_ie) kfree(ieee->wpa_ie);
     ieee->wpa_ie = NULL;
     ieee->wpa_ie_len = 0;
   }
   //	printk("<=====out %s()\n", __func__);
   return 0;
 }<sep>@@
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);
--- initial
+++ final
@@ -1,35 +1,34 @@
 int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len) {
 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)
 #if 0
 	printk("====>%s()\n", __FUNCTION__);
 	{
 		int i;
 		for (i=0; i<len; i++)
 		printk("%2x ", ie[i]&0xff);
 		printk("\n");
 	}
 #endif
   u8 *buf;
   if (len > MAX_WPA_IE_LEN || (len && ie == NULL)) {
     //	printk("return error out, len:%d\n", len);
     return -EINVAL;
   }
   if (len) {
     if (len != ie[1] + 2) {
       printk("len:%zu, ie:%d\n", len, ie[1]);
       return -EINVAL;
     }
-    buf = kmalloc(len, GFP_KERNEL);
+    buf = kmemdup(ie, len, GFP_KERNEL);
     if (buf == NULL) return -ENOMEM;
-    memcpy(buf, ie, len);
     kfree(ieee->wpa_ie);
     ieee->wpa_ie = buf;
     ieee->wpa_ie_len = len;
   } else {
     if (ieee->wpa_ie) kfree(ieee->wpa_ie);
     ieee->wpa_ie = NULL;
     ieee->wpa_ie_len = 0;
   }
 #endif
   return 0;
 }<sep>@@
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);
--- initial
+++ final
@@ -1,62 +1,61 @@
 static void stub_recv_cmd_submit(struct stub_device *sdev, struct usbip_header *pdu) {
   int ret;
   struct stub_priv *priv;
   struct usbip_device *ud = &sdev->ud;
   struct usb_device *udev = interface_to_usbdev(sdev->interface);
   int pipe = get_pipe(sdev, pdu->base.ep, pdu->base.direction);
   priv = stub_priv_alloc(sdev, pdu);
   if (!priv) return;
   /* setup a urb */
   if (usb_pipeisoc(pipe))
     priv->urb = usb_alloc_urb(pdu->u.cmd_submit.number_of_packets, GFP_KERNEL);
   else
     priv->urb = usb_alloc_urb(0, GFP_KERNEL);
   if (!priv->urb) {
     dev_err(&sdev->interface->dev, "malloc urb\n");
     usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
     return;
   }
   /* set priv->urb->transfer_buffer */
   if (pdu->u.cmd_submit.transfer_buffer_length > 0) {
     priv->urb->transfer_buffer = kzalloc(pdu->u.cmd_submit.transfer_buffer_length, GFP_KERNEL);
     if (!priv->urb->transfer_buffer) {
       dev_err(&sdev->interface->dev, "malloc x_buff\n");
       usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
       return;
     }
   }
   /* set priv->urb->setup_packet */
-  priv->urb->setup_packet = kzalloc(8, GFP_KERNEL);
+  priv->urb->setup_packet = kmemdup(&pdu->u.cmd_submit.setup, 8, GFP_KERNEL);
   if (!priv->urb->setup_packet) {
     dev_err(&sdev->interface->dev, "allocate setup_packet\n");
     usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
     return;
   }
-  memcpy(priv->urb->setup_packet, &pdu->u.cmd_submit.setup, 8);
   /* set other members from the base header of pdu */
   priv->urb->context = (void *)priv;
   priv->urb->dev = udev;
   priv->urb->pipe = pipe;
   priv->urb->complete = stub_complete;
   usbip_pack_pdu(pdu, priv->urb, USBIP_CMD_SUBMIT, 0);
   if (usbip_recv_xbuff(ud, priv->urb) < 0) return;
   if (usbip_recv_iso(ud, priv->urb) < 0) return;
   /* no need to submit an intercepted request, but harmless? */
   tweak_special_requests(priv->urb);
   /* urb is now ready to submit */
   ret = usb_submit_urb(priv->urb, GFP_KERNEL);
   if (ret == 0)
     usbip_dbg_stub_rx("submit urb ok, seqnum %u\n", pdu->base.seqnum);
   else {
     dev_err(&sdev->interface->dev, "submit_urb error, %d\n", ret);
     usbip_dump_header(pdu);
     usbip_dump_urb(priv->urb);
     /*
      * Pessimistic.
      * This connection will be discarded.
      */
     usbip_event_add(ud, SDEV_EVENT_ERROR_SUBMIT);
   }
   usbip_dbg_stub_rx("Leave\n");
   return;
 }<sep>@@
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);
--- initial
+++ final
@@ -1,36 +1,35 @@
 static int firmwareUpload(struct usbduxsub *usbduxsub, const u8 *firmwareBinary, int sizeFirmware) {
   int ret;
   uint8_t *fwBuf;
   if (!firmwareBinary) return 0;
   if (sizeFirmware > FIRMWARE_MAX_LEN) {
     dev_err(&usbduxsub->interface->dev, "usbdux firmware binary it too large for FX2.\n");
     return -ENOMEM;
   }
   /* we generate a local buffer for the firmware */
-  fwBuf = kzalloc(sizeFirmware, GFP_KERNEL);
+  fwBuf = kmemdup(firmwareBinary, sizeFirmware, GFP_KERNEL);
   if (!fwBuf) {
     dev_err(&usbduxsub->interface->dev, "comedi_: mem alloc for firmware failed\n");
     return -ENOMEM;
   }
-  memcpy(fwBuf, firmwareBinary, sizeFirmware);
   ret = usbduxsub_stop(usbduxsub);
   if (ret < 0) {
     dev_err(&usbduxsub->interface->dev, "comedi_: can not stop firmware\n");
     kfree(fwBuf);
     return ret;
   }
   ret = usbduxsub_upload(usbduxsub, fwBuf, 0, sizeFirmware);
   if (ret < 0) {
     dev_err(&usbduxsub->interface->dev, "comedi_: firmware upload failed\n");
     kfree(fwBuf);
     return ret;
   }
   ret = usbduxsub_start(usbduxsub);
   if (ret < 0) {
     dev_err(&usbduxsub->interface->dev, "comedi_: can not start firmware\n");
     kfree(fwBuf);
     return ret;
   }
   kfree(fwBuf);
   return 0;
 }<sep>@@
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);
--- initial
+++ final
@@ -1,36 +1,35 @@
 static int firmwareUpload(struct usbduxfastsub_s *usbduxfastsub, const u8 *firmwareBinary, int sizeFirmware) {
   int ret;
   uint8_t *fwBuf;
   if (!firmwareBinary) return 0;
   if (sizeFirmware > FIRMWARE_MAX_LEN) {
     dev_err(&usbduxfastsub->interface->dev, "comedi_: usbduxfast firmware binary it too large for FX2.\n");
     return -ENOMEM;
   }
   /* we generate a local buffer for the firmware */
-  fwBuf = kzalloc(sizeFirmware, GFP_KERNEL);
+  fwBuf = kmemdup(firmwareBinary, sizeFirmware, GFP_KERNEL);
   if (!fwBuf) {
     dev_err(&usbduxfastsub->interface->dev, "comedi_: mem alloc for firmware failed\n");
     return -ENOMEM;
   }
-  memcpy(fwBuf, firmwareBinary, sizeFirmware);
   ret = usbduxfastsub_stop(usbduxfastsub);
   if (ret < 0) {
     dev_err(&usbduxfastsub->interface->dev, "comedi_: can not stop firmware\n");
     kfree(fwBuf);
     return ret;
   }
   ret = usbduxfastsub_upload(usbduxfastsub, fwBuf, 0, sizeFirmware);
   if (ret < 0) {
     dev_err(&usbduxfastsub->interface->dev, "comedi_: firmware upload failed\n");
     kfree(fwBuf);
     return ret;
   }
   ret = usbduxfastsub_start(usbduxfastsub);
   if (ret < 0) {
     dev_err(&usbduxfastsub->interface->dev, "comedi_: can not start firmware\n");
     kfree(fwBuf);
     return ret;
   }
   kfree(fwBuf);
   return 0;
 }<sep>@@
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);
--- initial
+++ final
@@ -1,63 +1,62 @@
 int variax_init(struct usb_interface *interface, struct usb_line6_variax *variax) {
   int err;
   if ((interface == NULL) || (variax == NULL)) return -ENODEV;
   /* initialize USB buffers: */
   err = line6_dumpreq_init(&variax->dumpreq, variax_request_model1, sizeof(variax_request_model1));
   if (err < 0) {
     dev_err(&interface->dev, "Out of memory\n");
     variax_destruct(interface);
     return err;
   }
   err = line6_dumpreq_initbuf(&variax->dumpreq, variax_request_model2, sizeof(variax_request_model2), 1);
   if (err < 0) {
     dev_err(&interface->dev, "Out of memory\n");
     variax_destruct(interface);
     return err;
   }
   err = line6_dumpreq_initbuf(&variax->dumpreq, variax_request_bank, sizeof(variax_request_bank), 2);
   if (err < 0) {
     dev_err(&interface->dev, "Out of memory\n");
     variax_destruct(interface);
     return err;
   }
-  variax->buffer_activate = kmalloc(sizeof(variax_activate), GFP_KERNEL);
+  variax->buffer_activate = kmemdup(variax_activate, sizeof(variax_activate), GFP_KERNEL);
   if (variax->buffer_activate == NULL) {
     dev_err(&interface->dev, "Out of memory\n");
     variax_destruct(interface);
     return -ENOMEM;
   }
-  memcpy(variax->buffer_activate, variax_activate, sizeof(variax_activate));
   init_timer(&variax->activate_timer);
   /* create sysfs entries: */
   err = variax_create_files(0, 0, &interface->dev);
   if (err < 0) {
     variax_destruct(interface);
     return err;
   }
   err = variax_create_files2(&interface->dev);
   if (err < 0) {
     variax_destruct(interface);
     return err;
   }
   /* initialize audio system: */
   err = line6_init_audio(&variax->line6);
   if (err < 0) {
     variax_destruct(interface);
     return err;
   }
   /* initialize MIDI subsystem: */
   err = line6_init_midi(&variax->line6);
   if (err < 0) {
     variax_destruct(interface);
     return err;
   }
   /* register audio system: */
   err = line6_register_audio(&variax->line6);
   if (err < 0) {
     variax_destruct(interface);
     return err;
   }
   variax_activate_delayed(variax, VARIAX_ACTIVATE_DELAY);
   line6_startup_delayed(&variax->dumpreq, VARIAX_STARTUP_DELAY, variax_startup_timeout, variax);
   return 0;
 }<sep>@@
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);
--- initial
+++ final
@@ -1,34 +1,33 @@
 static void VmbusOnMsgDPC(struct hv_driver *drv) {
   int cpu = smp_processor_id();
   void *page_addr = gHvContext.synICMessagePage[cpu];
   struct hv_message *msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
   struct hv_message *copied;
   while (1) {
     if (msg->Header.MessageType == HvMessageTypeNone) {
       /* no msg */
       break;
     } else {
-      copied = kmalloc(sizeof(*copied), GFP_ATOMIC);
+      copied = kmemdup(msg, sizeof(*copied), GFP_ATOMIC);
       if (copied == NULL) continue;
-      memcpy(copied, msg, sizeof(*copied));
       osd_schedule_callback(gVmbusConnection.WorkQueue, VmbusOnChannelMessage, (void *)copied);
     }
     msg->Header.MessageType = HvMessageTypeNone;
     /*
      * Make sure the write to MessageType (ie set to
      * HvMessageTypeNone) happens before we read the
      * MessagePending and EOMing. Otherwise, the EOMing
      * will not deliver any more messages since there is
      * no empty slot
      */
     mb();
     if (msg->Header.MessageFlags.MessagePending) {
       /*
        * This will cause message queue rescan to
        * possibly deliver another msg from the
        * hypervisor
        */
       wrmsrl(HV_X64_MSR_EOM, 0);
     }
   }
 }<sep>@@
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);
--- initial
+++ final
@@ -1,39 +1,38 @@
 static __init acpi_status parse_wdg(acpi_handle handle) {
   struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
   union acpi_object *obj;
   struct guid_block *gblock;
   struct wmi_block *wblock;
   char guid_string[37];
   acpi_status status;
   u32 i, total;
   status = acpi_evaluate_object(handle, "_WDG", NULL, &out);
   if (ACPI_FAILURE(status)) return status;
   obj = (union acpi_object *)out.pointer;
   if (obj->type != ACPI_TYPE_BUFFER) return AE_ERROR;
   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
       duplicate GUID. It's not clear what we should do in this
       case yet, so for now, we'll just ignore the duplicate.
       Anyone who wants to add support for that device can come
       up with a better workaround for the mess then.
     */
     if (guid_already_parsed(gblock[i].guid) == true) {
       wmi_gtoa(gblock[i].guid, guid_string);
       printk(KERN_INFO PREFIX "Skipping duplicate GUID %s\n", guid_string);
       continue;
     }
     wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL);
     if (!wblock) return AE_NO_MEMORY;
     wblock->gblock = gblock[i];
     wblock->handle = handle;
     list_add_tail(&wblock->list, &wmi_blocks.list);
   }
   kfree(out.pointer);
   kfree(gblock);
   return status;
 }<sep>@@
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);
--- initial
+++ final
@@ -1,17 +1,16 @@
 int rdma_set_ib_paths(struct rdma_cm_id *id, struct ib_sa_path_rec *path_rec, int num_paths) {
   struct rdma_id_private *id_priv;
   int ret;
   id_priv = container_of(id, struct rdma_id_private, id);
   if (!cma_comp_exch(id_priv, CMA_ADDR_RESOLVED, CMA_ROUTE_RESOLVED)) return -EINVAL;
-  id->route.path_rec = kmalloc(sizeof *path_rec * num_paths, GFP_KERNEL);
+  id->route.path_rec = kmemdup(path_rec, sizeof *path_rec * num_paths, GFP_KERNEL);
   if (!id->route.path_rec) {
     ret = -ENOMEM;
     goto err;
   }
-  memcpy(id->route.path_rec, path_rec, sizeof *path_rec * num_paths);
   id->route.num_paths = num_paths;
   return 0;
 err:
   cma_comp_exch(id_priv, CMA_ROUTE_RESOLVED, CMA_ADDR_RESOLVED);
   return ret;
 }<sep>@@
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);
--- initial
+++ final
@@ -1,16 +1,15 @@
 static int p54u_firmware_reset_3887(struct ieee80211_hw *dev) {
   struct p54u_priv *priv = dev->priv;
   u8 *buf;
   int ret;
-  buf = kmalloc(4, GFP_KERNEL);
+  buf = kmemdup(p54u_romboot_3887, 4, GFP_KERNEL);
   if (!buf) return -ENOMEM;
-  memcpy(buf, p54u_romboot_3887, 4);
   ret = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, 4);
   kfree(buf);
   if (ret)
     dev_err(&priv->udev->dev,
             "(p54usb) unable to jump to "
             "boot ROM (%d)!\n",
             ret);
   return ret;
 }<sep>@@
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);
--- initial
+++ final
@@ -1,57 +1,56 @@
 static int concat_writev(struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen) {
   struct mtd_concat *concat = CONCAT(mtd);
   struct kvec *vecs_copy;
   unsigned long entry_low, entry_high;
   size_t total_len = 0;
   int i;
   int err = -EINVAL;
   if (!(mtd->flags & MTD_WRITEABLE)) return -EROFS;
   *retlen = 0;
   /* Calculate total length of data */
   for (i = 0; i < count; i++)
     total_len += vecs[i].iov_len;
   /* Do not allow write past end of device */
   if ((to + total_len) > mtd->size) return -EINVAL;
   /* Check alignment */
   if (mtd->writesize > 1) {
     uint64_t __to = to;
     if (do_div(__to, mtd->writesize) || (total_len % mtd->writesize)) return -EINVAL;
   }
   /* make a copy of vecs */
-  vecs_copy = kmalloc(sizeof(struct kvec) * count, GFP_KERNEL);
+  vecs_copy = kmemdup(vecs, sizeof(struct kvec) * count, GFP_KERNEL);
   if (!vecs_copy) return -ENOMEM;
-  memcpy(vecs_copy, vecs, sizeof(struct kvec) * count);
   entry_low = 0;
   for (i = 0; i < concat->num_subdev; i++) {
     struct mtd_info *subdev = concat->subdev[i];
     size_t size, wsize, retsize, old_iov_len;
     if (to >= subdev->size) {
       to -= subdev->size;
       continue;
     }
     size = min_t(uint64_t, total_len, subdev->size - to);
     wsize = size; /* store for future use */
     entry_high = entry_low;
     while (entry_high < count) {
       if (size <= vecs_copy[entry_high].iov_len) break;
       size -= vecs_copy[entry_high++].iov_len;
     }
     old_iov_len = vecs_copy[entry_high].iov_len;
     vecs_copy[entry_high].iov_len = size;
     if (!(subdev->flags & MTD_WRITEABLE))
       err = -EROFS;
     else
       err = subdev->writev(subdev, &vecs_copy[entry_low], entry_high - entry_low + 1, to, &retsize);
     vecs_copy[entry_high].iov_len = old_iov_len - size;
     vecs_copy[entry_high].iov_base += size;
     entry_low = entry_high;
     if (err) break;
     *retlen += retsize;
     total_len -= wsize;
     if (total_len == 0) break;
     err = -EINVAL;
     to = 0;
   }
   kfree(vecs_copy);
   return err;
 }<sep>@@
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);
--- initial
+++ final
@@ -1,29 +1,28 @@
 static int orinoco_ioctl_set_genie(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) {
   struct orinoco_private *priv = ndev_priv(dev);
   u8 *buf;
   unsigned long flags;
   /* cut off at IEEE80211_MAX_DATA_LEN */
   if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) || (wrqu->data.length && (extra == NULL))) return -EINVAL;
   if (wrqu->data.length) {
-    buf = kmalloc(wrqu->data.length, GFP_KERNEL);
+    buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
     if (buf == NULL) return -ENOMEM;
-    memcpy(buf, extra, wrqu->data.length);
   } else
     buf = NULL;
   if (orinoco_lock(priv, &flags) != 0) {
     kfree(buf);
     return -EBUSY;
   }
   kfree(priv->wpa_ie);
   priv->wpa_ie = buf;
   priv->wpa_ie_len = wrqu->data.length;
   if (priv->wpa_ie) {
     /* Looks like wl_lkm wants to check the auth alg, and
      * somehow pass it to the firmware.
      * Instead it just calls the key mgmt rid
      *   - we do this in set auth.
      */
   }
   orinoco_unlock(priv, &flags);
   return 0;
 }<sep>@@
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);
--- initial
+++ final
@@ -1,44 +1,42 @@
 struct kbd_data *kbd_alloc(void) {
   struct kbd_data *kbd;
   int i;
   kbd = kzalloc(sizeof(struct kbd_data), GFP_KERNEL);
   if (!kbd) goto out;
   kbd->key_maps = kzalloc(sizeof(key_maps), GFP_KERNEL);
   if (!kbd->key_maps) goto out_kbd;
   for (i = 0; i < ARRAY_SIZE(key_maps); i++) {
     if (key_maps[i]) {
-      kbd->key_maps[i] = kmalloc(sizeof(u_short) * NR_KEYS, GFP_KERNEL);
+      kbd->key_maps[i] = kmemdup(key_maps[i], sizeof(u_short) * NR_KEYS, GFP_KERNEL);
       if (!kbd->key_maps[i]) goto out_maps;
-      memcpy(kbd->key_maps[i], key_maps[i], sizeof(u_short) * NR_KEYS);
     }
   }
   kbd->func_table = kzalloc(sizeof(func_table), GFP_KERNEL);
   if (!kbd->func_table) goto out_maps;
   for (i = 0; i < ARRAY_SIZE(func_table); i++) {
     if (func_table[i]) {
       kbd->func_table[i] = kstrdup(func_table[i], GFP_KERNEL);
       if (!kbd->func_table[i]) goto out_func;
     }
   }
   kbd->fn_handler = kzalloc(sizeof(fn_handler_fn *) * NR_FN_HANDLER, GFP_KERNEL);
   if (!kbd->fn_handler) goto out_func;
-  kbd->accent_table = kmalloc(sizeof(struct kbdiacruc) * MAX_DIACR, GFP_KERNEL);
+  kbd->accent_table = kmemdup(accent_table, sizeof(struct kbdiacruc) * MAX_DIACR, GFP_KERNEL);
   if (!kbd->accent_table) goto out_fn_handler;
-  memcpy(kbd->accent_table, accent_table, sizeof(struct kbdiacruc) * MAX_DIACR);
   kbd->accent_table_size = accent_table_size;
   return kbd;
 out_fn_handler:
   kfree(kbd->fn_handler);
 out_func:
   for (i = 0; i < ARRAY_SIZE(func_table); i++)
     kfree(kbd->func_table[i]);
   kfree(kbd->func_table);
 out_maps:
   for (i = 0; i < ARRAY_SIZE(key_maps); i++)
     kfree(kbd->key_maps[i]);
   kfree(kbd->key_maps);
 out_kbd:
   kfree(kbd);
 out:
   return NULL;
 }<sep>@@
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);
--- initial
+++ final
@@ -1,67 +1,66 @@
 static int nexio_init(struct usbtouch_usb *usbtouch) {
   struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
   struct usb_host_interface *interface = usbtouch->interface->cur_altsetting;
   struct nexio_priv *priv;
   int ret = -ENOMEM;
   int actual_len, i;
   unsigned char *buf;
   char *firmware_ver = NULL, *device_name = NULL;
   int input_ep = 0, output_ep = 0;
   /* find first input and output endpoint */
   for (i = 0; i < interface->desc.bNumEndpoints; i++) {
     if (!input_ep && usb_endpoint_dir_in(&interface->endpoint[i].desc)) input_ep = interface->endpoint[i].desc.bEndpointAddress;
     if (!output_ep && usb_endpoint_dir_out(&interface->endpoint[i].desc)) output_ep = interface->endpoint[i].desc.bEndpointAddress;
   }
   if (!input_ep || !output_ep) return -ENXIO;
   buf = kmalloc(NEXIO_BUFSIZE, GFP_KERNEL);
   if (!buf) goto out_buf;
   /* two empty reads */
   for (i = 0; i < 2; i++) {
     ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep), buf, NEXIO_BUFSIZE, &actual_len, NEXIO_TIMEOUT);
     if (ret < 0) goto out_buf;
   }
   /* send init command */
   memcpy(buf, nexio_init_pkt, sizeof(nexio_init_pkt));
   ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, output_ep), buf, sizeof(nexio_init_pkt), &actual_len, NEXIO_TIMEOUT);
   if (ret < 0) goto out_buf;
   /* read replies */
   for (i = 0; i < 3; i++) {
     memset(buf, 0, NEXIO_BUFSIZE);
     ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep), buf, NEXIO_BUFSIZE, &actual_len, NEXIO_TIMEOUT);
     if (ret < 0 || actual_len < 1 || buf[1] != actual_len) continue;
     switch (buf[0]) {
     case 0x83: /* firmware version */
       if (!firmware_ver) firmware_ver = kstrdup(&buf[2], GFP_KERNEL);
       break;
     case 0x84: /* device name */
       if (!device_name) device_name = kstrdup(&buf[2], GFP_KERNEL);
       break;
     }
   }
   printk(KERN_INFO "Nexio device: %s, firmware version: %s\n", device_name, firmware_ver);
   kfree(firmware_ver);
   kfree(device_name);
   /* prepare ACK URB */
   ret = -ENOMEM;
   usbtouch->priv = kmalloc(sizeof(struct nexio_priv), GFP_KERNEL);
   if (!usbtouch->priv) goto out_buf;
   priv = usbtouch->priv;
-  priv->ack_buf = kmalloc(sizeof(nexio_ack_pkt), GFP_KERNEL);
+  priv->ack_buf = kmemdup(nexio_ack_pkt, sizeof(nexio_ack_pkt), GFP_KERNEL);
   if (!priv->ack_buf) goto err_priv;
-  memcpy(priv->ack_buf, nexio_ack_pkt, sizeof(nexio_ack_pkt));
   priv->ack = usb_alloc_urb(0, GFP_KERNEL);
   if (!priv->ack) {
     dbg("%s - usb_alloc_urb failed: usbtouch->ack", __func__);
     goto err_ack_buf;
   }
   usb_fill_bulk_urb(priv->ack, dev, usb_sndbulkpipe(dev, output_ep), priv->ack_buf, sizeof(nexio_ack_pkt), nexio_ack_complete, usbtouch);
   ret = 0;
   goto out_buf;
 err_ack_buf:
   kfree(priv->ack_buf);
 err_priv:
   kfree(priv);
 out_buf:
   kfree(buf);
   return ret;
 }<sep>@@
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);