imamnurby/smpl_train_seed8 huggingface dataset:
--- initial
+++ final
@@ -1,19 +1,13 @@
 static int fld_client_debugfs_init(struct lu_client_fld *fld) {
   int rc;
-  fld->lcf_debugfs_entry = ldebugfs_register(fld->lcf_name, fld_debugfs_dir, NULL, NULL);
-  if (IS_ERR_OR_NULL(fld->lcf_debugfs_entry)) {
-    CERROR("%s: LdebugFS failed in fld-init\n", fld->lcf_name);
-    rc = fld->lcf_debugfs_entry ? PTR_ERR(fld->lcf_debugfs_entry) : -ENOMEM;
-    fld->lcf_debugfs_entry = NULL;
-    return rc;
-  }
+  fld->lcf_debugfs_entry = debugfs_create_dir(fld->lcf_name, fld_debugfs_dir);
   rc = ldebugfs_add_vars(fld->lcf_debugfs_entry, fld_client_debugfs_list, fld);
   if (rc) {
     CERROR("%s: Can't init FLD debufs, rc %d\n", fld->lcf_name, rc);
     goto out_cleanup;
   }
   return 0;
 out_cleanup:
   fld_client_debugfs_fini(fld);
   return rc;
 }<sep>@@
expression e,e1,e2,e3;
statement S;
@@

e =
- ldebugfs_register
+ debugfs_create_dir
     (e1,e2
-     ,NULL,e3
     )
;
-if (IS_ERR_OR_NULL(e)) S
--- initial
+++ final
@@ -1,7 +1,7 @@
 static int __init fld_init(void) {
   int rc;
   rc = libcfs_setup();
   if (rc) return rc;
-  fld_debugfs_dir = ldebugfs_register(LUSTRE_FLD_NAME, debugfs_lustre_root, NULL, NULL);
-  return PTR_ERR_OR_ZERO(fld_debugfs_dir);
+  fld_debugfs_dir = debugfs_create_dir(LUSTRE_FLD_NAME, debugfs_lustre_root);
+  return 0;
 }<sep>@@
expression e,e1,e2,e3;
@@

e =
- ldebugfs_register
+ debugfs_create_dir
     (e1,e2
-     ,NULL,e3
     )
;
-return PTR_ERR_OR_ZERO(e);
+return 0;
--- initial
+++ final
@@ -1,49 +1,44 @@
 int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, const char *name, struct lu_device_type *ldt) {
   struct obd_type *type;
   int rc;
   /* sanity check */
   LASSERT(strnlen(name, CLASS_MAX_NAME) < CLASS_MAX_NAME);
   if (class_search_type(name)) {
     CDEBUG(D_IOCTL, "Type %s already registered\n", name);
     return -EEXIST;
   }
   rc = -ENOMEM;
   type = kzalloc(sizeof(*type), GFP_NOFS);
   if (!type) return rc;
   type->typ_dt_ops = kzalloc(sizeof(*type->typ_dt_ops), GFP_NOFS);
   type->typ_md_ops = kzalloc(sizeof(*type->typ_md_ops), GFP_NOFS);
   type->typ_name = kzalloc(strlen(name) + 1, GFP_NOFS);
   if (!type->typ_dt_ops || !type->typ_md_ops || !type->typ_name) goto failed;
   *type->typ_dt_ops = *dt_ops;
   /* md_ops is optional */
   if (md_ops) *type->typ_md_ops = *md_ops;
   strcpy(type->typ_name, name);
   spin_lock_init(&type->obd_type_lock);
-  type->typ_debugfs_entry = ldebugfs_register(type->typ_name, debugfs_lustre_root, NULL, type);
-  if (IS_ERR_OR_NULL(type->typ_debugfs_entry)) {
-    rc = type->typ_debugfs_entry ? PTR_ERR(type->typ_debugfs_entry) : -ENOMEM;
-    type->typ_debugfs_entry = NULL;
-    goto failed;
-  }
+  type->typ_debugfs_entry = debugfs_create_dir(type->typ_name, debugfs_lustre_root);
   type->typ_kobj = kobject_create_and_add(type->typ_name, lustre_kobj);
   if (!type->typ_kobj) {
     rc = -ENOMEM;
     goto failed;
   }
   if (ldt) {
     type->typ_lu = ldt;
     rc = lu_device_type_init(ldt);
     if (rc != 0) goto failed;
   }
   spin_lock(&obd_types_lock);
   list_add(&type->typ_chain, &obd_types);
   spin_unlock(&obd_types_lock);
   return 0;
 failed:
   if (type->typ_kobj) kobject_put(type->typ_kobj);
   kfree(type->typ_name);
   kfree(type->typ_md_ops);
   kfree(type->typ_dt_ops);
   kfree(type);
   return rc;
 }<sep>@@
expression e,e1,e2,e3;
statement S;
@@

e =
- ldebugfs_register
+ debugfs_create_dir
     (e1,e2
-     ,NULL,e3
     )
;
-if (IS_ERR_OR_NULL(e)) S
--- initial
+++ final
@@ -1,46 +1,40 @@
 static int ldlm_pool_debugfs_init(struct ldlm_pool *pl) {
   struct ldlm_namespace *ns = container_of(pl, struct ldlm_namespace, ns_pool);
   struct dentry *debugfs_ns_parent;
   struct lprocfs_vars pool_vars[2];
   char *var_name = NULL;
   int rc = 0;
   var_name = kzalloc(MAX_STRING_SIZE + 1, GFP_NOFS);
   if (!var_name) return -ENOMEM;
   debugfs_ns_parent = ns->ns_debugfs_entry;
   if (IS_ERR_OR_NULL(debugfs_ns_parent)) {
     CERROR("%s: debugfs entry is not initialized\n", ldlm_ns_name(ns));
     rc = -EINVAL;
     goto out_free_name;
   }
-  pl->pl_debugfs_entry = ldebugfs_register("pool", debugfs_ns_parent, NULL, NULL);
-  if (IS_ERR(pl->pl_debugfs_entry)) {
-    CERROR("LdebugFS failed in ldlm-pool-init\n");
-    rc = PTR_ERR(pl->pl_debugfs_entry);
-    pl->pl_debugfs_entry = NULL;
-    goto out_free_name;
-  }
+  pl->pl_debugfs_entry = debugfs_create_dir("pool", debugfs_ns_parent);
   var_name[MAX_STRING_SIZE] = '\0';
   memset(pool_vars, 0, sizeof(pool_vars));
   pool_vars[0].name = var_name;
   LDLM_POOL_ADD_VAR(state, pl, &lprocfs_pool_state_fops);
   pl->pl_stats = lprocfs_alloc_stats(LDLM_POOL_LAST_STAT - LDLM_POOL_FIRST_STAT, 0);
   if (!pl->pl_stats) {
     rc = -ENOMEM;
     goto out_free_name;
   }
   lprocfs_counter_init(pl->pl_stats, LDLM_POOL_GRANTED_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "granted", "locks");
   lprocfs_counter_init(pl->pl_stats, LDLM_POOL_GRANT_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "grant", "locks");
   lprocfs_counter_init(pl->pl_stats, LDLM_POOL_CANCEL_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "cancel", "locks");
   lprocfs_counter_init(pl->pl_stats, LDLM_POOL_GRANT_RATE_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "grant_rate", "locks/s");
   lprocfs_counter_init(pl->pl_stats, LDLM_POOL_CANCEL_RATE_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "cancel_rate", "locks/s");
   lprocfs_counter_init(pl->pl_stats, LDLM_POOL_GRANT_PLAN_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "grant_plan", "locks/s");
   lprocfs_counter_init(pl->pl_stats, LDLM_POOL_SLV_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "slv", "slv");
   lprocfs_counter_init(pl->pl_stats, LDLM_POOL_SHRINK_REQTD_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "shrink_request", "locks");
   lprocfs_counter_init(pl->pl_stats, LDLM_POOL_SHRINK_FREED_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "shrink_freed", "locks");
   lprocfs_counter_init(pl->pl_stats, LDLM_POOL_RECALC_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "recalc_freed", "locks");
   lprocfs_counter_init(pl->pl_stats, LDLM_POOL_TIMING_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "recalc_timing", "sec");
   debugfs_create_file("stats", 0644, pl->pl_debugfs_entry, pl->pl_stats, &lprocfs_stats_seq_fops);
 out_free_name:
   kfree(var_name);
   return rc;
 }<sep>@@
expression e,e1,e2,e3;
statement S;
@@

e =
- ldebugfs_register
+ debugfs_create_dir
     (e1,e2
-     ,NULL,e3
     )
;
-if (IS_ERR(e)) S
--- initial
+++ final
@@ -1,38 +1,23 @@
 int ldlm_debugfs_setup(void) {
   int rc;
-  ldlm_debugfs_dir = ldebugfs_register(OBD_LDLM_DEVICENAME, debugfs_lustre_root, NULL, NULL);
-  if (IS_ERR_OR_NULL(ldlm_debugfs_dir)) {
-    CERROR("LProcFS failed in ldlm-init\n");
-    rc = ldlm_debugfs_dir ? PTR_ERR(ldlm_debugfs_dir) : -ENOMEM;
-    goto err;
-  }
-  ldlm_ns_debugfs_dir = ldebugfs_register("namespaces", ldlm_debugfs_dir, NULL, NULL);
-  if (IS_ERR_OR_NULL(ldlm_ns_debugfs_dir)) {
-    CERROR("LProcFS failed in ldlm-init\n");
-    rc = ldlm_ns_debugfs_dir ? PTR_ERR(ldlm_ns_debugfs_dir) : -ENOMEM;
-    goto err_type;
-  }
-  ldlm_svc_debugfs_dir = ldebugfs_register("services", ldlm_debugfs_dir, NULL, NULL);
-  if (IS_ERR_OR_NULL(ldlm_svc_debugfs_dir)) {
-    CERROR("LProcFS failed in ldlm-init\n");
-    rc = ldlm_svc_debugfs_dir ? PTR_ERR(ldlm_svc_debugfs_dir) : -ENOMEM;
-    goto err_ns;
-  }
+  ldlm_debugfs_dir = debugfs_create_dir(OBD_LDLM_DEVICENAME, debugfs_lustre_root);
+  ldlm_ns_debugfs_dir = debugfs_create_dir("namespaces", ldlm_debugfs_dir);
+  ldlm_svc_debugfs_dir = debugfs_create_dir("services", ldlm_debugfs_dir);
   rc = ldebugfs_add_vars(ldlm_debugfs_dir, ldlm_debugfs_list, NULL);
   if (rc) {
     CERROR("LProcFS failed in ldlm-init\n");
     goto err_svc;
   }
   return 0;
 err_svc:
   ldebugfs_remove(&ldlm_svc_debugfs_dir);
 err_ns:
   ldebugfs_remove(&ldlm_ns_debugfs_dir);
 err_type:
   ldebugfs_remove(&ldlm_debugfs_dir);
 err:
   ldlm_svc_debugfs_dir = NULL;
   ldlm_ns_debugfs_dir = NULL;
   ldlm_debugfs_dir = NULL;
   return rc;
 }<sep>@@
expression e,e1,e2,e3;
statement S;
@@

e =
- ldebugfs_register
+ debugfs_create_dir
     (e1,e2
-     ,NULL,e3
     )
;
-if (IS_ERR_OR_NULL(e)) S
--- initial
+++ final
@@ -1,45 +1,45 @@
 int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg) {
   struct lprocfs_static_vars lvars = {NULL};
   struct lov_desc *desc;
   struct lov_obd *lov = &obd->u.lov;
   int rc;
   if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
     CERROR("LOV setup requires a descriptor\n");
     return -EINVAL;
   }
   desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
   if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
     CERROR("descriptor size wrong: %d > %d\n", (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
     return -EINVAL;
   }
   if (desc->ld_magic != LOV_DESC_MAGIC) {
     if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
       CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n", obd->obd_name, desc);
       lustre_swab_lov_desc(desc);
     } else {
       CERROR("%s: Bad lov desc magic: %#x\n", obd->obd_name, desc->ld_magic);
       return -EINVAL;
     }
   }
   lov_fix_desc(desc);
   desc->ld_active_tgt_count = 0;
   lov->desc = *desc;
   lov->lov_tgt_size = 0;
   mutex_init(&lov->lov_lock);
   atomic_set(&lov->lov_refcount, 0);
   lov->lov_sp_me = LUSTRE_SP_CLI;
   init_rwsem(&lov->lov_notify_lock);
   INIT_LIST_HEAD(&lov->lov_pool_list);
   lov->lov_pool_count = 0;
   rc = lov_pool_hash_init(&lov->lov_pools_hash_body);
   if (rc) goto out;
   rc = lov_ost_pool_init(&lov->lov_packed, 0);
   if (rc) goto out;
   lprocfs_lov_init_vars(&lvars);
   lprocfs_obd_setup(obd, lvars.obd_vars, lvars.sysfs_vars);
   debugfs_create_file("target_obd", 0444, obd->obd_debugfs_entry, obd, &lov_proc_target_fops);
-  lov->lov_pool_debugfs_entry = ldebugfs_register("pools", obd->obd_debugfs_entry, NULL, NULL);
+  lov->lov_pool_debugfs_entry = debugfs_create_dir("pools", obd->obd_debugfs_entry);
   return 0;
 out:
   return rc;
 }<sep>@@
expression e1,e2,e3;
@@

- ldebugfs_register
+ debugfs_create_dir
     (e1,e2
-     ,NULL,e3
     )
--- initial
+++ final
@@ -1,40 +1,35 @@
 static void ptlrpc_ldebugfs_register(struct dentry *root, char *dir, char *name, struct dentry **debugfs_root_ret, struct lprocfs_stats **stats_ret) {
   struct dentry *svc_debugfs_entry;
   struct lprocfs_stats *svc_stats;
   int i;
   unsigned int svc_counter_config = LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV;
   LASSERT(!*debugfs_root_ret);
   LASSERT(!*stats_ret);
   svc_stats = lprocfs_alloc_stats(EXTRA_MAX_OPCODES + LUSTRE_MAX_OPCODES, 0);
   if (!svc_stats) return;
-  if (dir) {
-    svc_debugfs_entry = ldebugfs_register(dir, root, NULL, NULL);
-    if (IS_ERR(svc_debugfs_entry)) {
-      lprocfs_free_stats(&svc_stats);
-      return;
-    }
-  } else {
+  if (dir)
+    svc_debugfs_entry = debugfs_create_dir(dir, root);
+  else
     svc_debugfs_entry = root;
-  }
   lprocfs_counter_init(svc_stats, PTLRPC_REQWAIT_CNTR, svc_counter_config, "req_waittime", "usec");
   lprocfs_counter_init(svc_stats, PTLRPC_REQQDEPTH_CNTR, svc_counter_config, "req_qdepth", "reqs");
   lprocfs_counter_init(svc_stats, PTLRPC_REQACTIVE_CNTR, svc_counter_config, "req_active", "reqs");
   lprocfs_counter_init(svc_stats, PTLRPC_TIMEOUT, svc_counter_config, "req_timeout", "sec");
   lprocfs_counter_init(svc_stats, PTLRPC_REQBUF_AVAIL_CNTR, svc_counter_config, "reqbuf_avail", "bufs");
   for (i = 0; i < EXTRA_LAST_OPC; i++) {
     char *units;
     switch (i) {
     case BRW_WRITE_BYTES:
     case BRW_READ_BYTES: units = "bytes"; break;
     default: units = "reqs"; break;
     }
     lprocfs_counter_init(svc_stats, PTLRPC_LAST_CNTR + i, svc_counter_config, ll_eopcode2str(i), units);
   }
   for (i = 0; i < LUSTRE_MAX_OPCODES; i++) {
     __u32 opcode = ll_rpc_opcode_table[i].opcode;
     lprocfs_counter_init(svc_stats, EXTRA_MAX_OPCODES + i, svc_counter_config, ll_opcode2str(opcode), "usec");
   }
   debugfs_create_file("stats", 0644, svc_debugfs_entry, svc_stats, &lprocfs_stats_seq_fops);
   if (dir) *debugfs_root_ret = svc_debugfs_entry;
   *stats_ret = svc_stats;
 }<sep>@@
expression e,e1,e2,e3;
statement S;
@@

e =
- ldebugfs_register
+ debugfs_create_dir
     (e1,e2
-     ,NULL,e3
     )
;
-if (IS_ERR(e)) S

@@
expression e,e1,e2;
statement S;
@@



if (...)
- {
  e = debugfs_create_dir(e1,e2);
- }
  else
- {
  S
- }
--- initial
+++ final
@@ -1,36 +1,35 @@
 static int set_register(pegasus_t *pegasus, __u16 indx, __u8 data) {
   int ret;
   char *tmp;
   DECLARE_WAITQUEUE(wait, current);
-  tmp = kmalloc(1, GFP_KERNEL);
+  tmp = kmemdup(&data, 1, GFP_KERNEL);
   if (!tmp) {
     netif_warn(pegasus, drv, pegasus->net, "out of memory in %s\n", __func__);
     return -ENOMEM;
   }
-  memcpy(tmp, &data, 1);
   add_wait_queue(&pegasus->ctrl_wait, &wait);
   set_current_state(TASK_UNINTERRUPTIBLE);
   while (pegasus->flags & ETH_REGS_CHANGED)
     schedule();
   remove_wait_queue(&pegasus->ctrl_wait, &wait);
   set_current_state(TASK_RUNNING);
   pegasus->dr.bRequestType = PEGASUS_REQT_WRITE;
   pegasus->dr.bRequest = PEGASUS_REQ_SET_REG;
   pegasus->dr.wValue = cpu_to_le16(data);
   pegasus->dr.wIndex = cpu_to_le16(indx);
   pegasus->dr.wLength = cpu_to_le16(1);
   pegasus->ctrl_urb->transfer_buffer_length = 1;
   usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0), (char *)&pegasus->dr, tmp, 1, ctrl_callback, pegasus);
   add_wait_queue(&pegasus->ctrl_wait, &wait);
   set_current_state(TASK_UNINTERRUPTIBLE);
   if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
     if (ret == -ENODEV) netif_device_detach(pegasus->net);
     if (net_ratelimit()) netif_err(pegasus, drv, pegasus->net, "%s, status %d\n", __func__, ret);
     goto out;
   }
   schedule();
 out:
   remove_wait_queue(&pegasus->ctrl_wait, &wait);
   kfree(tmp);
   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,36 +1,35 @@
 static int set_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data) {
   int ret;
   char *buffer;
   DECLARE_WAITQUEUE(wait, current);
-  buffer = kmalloc(size, GFP_KERNEL);
+  buffer = kmemdup(data, size, GFP_KERNEL);
   if (!buffer) {
     netif_warn(pegasus, drv, pegasus->net, "out of memory in %s\n", __func__);
     return -ENOMEM;
   }
-  memcpy(buffer, data, size);
   add_wait_queue(&pegasus->ctrl_wait, &wait);
   set_current_state(TASK_UNINTERRUPTIBLE);
   while (pegasus->flags & ETH_REGS_CHANGED)
     schedule();
   remove_wait_queue(&pegasus->ctrl_wait, &wait);
   set_current_state(TASK_RUNNING);
   pegasus->dr.bRequestType = PEGASUS_REQT_WRITE;
   pegasus->dr.bRequest = PEGASUS_REQ_SET_REGS;
   pegasus->dr.wValue = cpu_to_le16(0);
   pegasus->dr.wIndex = cpu_to_le16(indx);
   pegasus->dr.wLength = cpu_to_le16(size);
   pegasus->ctrl_urb->transfer_buffer_length = size;
   usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0), (char *)&pegasus->dr, buffer, size, ctrl_callback, pegasus);
   add_wait_queue(&pegasus->ctrl_wait, &wait);
   set_current_state(TASK_UNINTERRUPTIBLE);
   if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
     if (ret == -ENODEV) netif_device_detach(pegasus->net);
     netif_err(pegasus, drv, pegasus->net, "%s, status %d\n", __func__, ret);
     goto out;
   }
   schedule();
 out:
   remove_wait_queue(&pegasus->ctrl_wait, &wait);
   kfree(buffer);
   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,14 +1,13 @@
 static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, u16 size, void *data) {
   void *buf = NULL;
   int err = -ENOMEM;
   netdev_dbg(dev->net, "asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n", cmd, value, index, size);
   if (data) {
-    buf = kmalloc(size, GFP_KERNEL);
+    buf = kmemdup(data, size, GFP_KERNEL);
     if (!buf) goto out;
-    memcpy(buf, data, size);
   }
   err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), cmd, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, value, index, buf, size, USB_CTRL_SET_TIMEOUT);
   kfree(buf);
 out:
   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,11 +1,10 @@
 static int mcs7830_set_reg(struct usbnet *dev, u16 index, u16 size, const void *data) {
   struct usb_device *xdev = dev->udev;
   int ret;
   void *buffer;
-  buffer = kmalloc(size, GFP_NOIO);
+  buffer = kmemdup(data, size, GFP_NOIO);
   if (buffer == NULL) return -ENOMEM;
-  memcpy(buffer, data, size);
   ret = usb_control_msg(xdev, usb_sndctrlpipe(xdev, 0), MCS7830_WR_BREQ, MCS7830_WR_BMREQ, 0x0000, index, buffer, size, MCS7830_CTRL_TIMEOUT);
   kfree(buffer);
   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,15 +1,14 @@
 static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data) {
   void *buf = NULL;
   int err = -ENOMEM;
   netdev_dbg(dev->net, "dm_write() reg=0x%02x, length=%d\n", reg, length);
   if (data) {
-    buf = kmalloc(length, GFP_KERNEL);
+    buf = kmemdup(data, length, GFP_KERNEL);
     if (!buf) goto out;
-    memcpy(buf, data, length);
   }
   err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), DM_WRITE_REGS, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0, reg, buf, length, USB_CTRL_SET_TIMEOUT);
   kfree(buf);
   if (err >= 0 && err < length) err = -EINVAL;
 out:
   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,27 +1,26 @@
 static int wl1251_fetch_nvs(struct wl1251 *wl) {
   const struct firmware *fw;
   struct device *dev = wiphy_dev(wl->hw->wiphy);
   int ret;
   ret = request_firmware(&fw, WL1251_NVS_NAME, dev);
   if (ret < 0) {
     wl1251_error("could not get nvs file: %d", ret);
     return ret;
   }
   if (fw->size % 4) {
     wl1251_error("nvs size is not multiple of 32 bits: %zu", fw->size);
     ret = -EILSEQ;
     goto out;
   }
   wl->nvs_len = fw->size;
-  wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
+  wl->nvs = kmemdup(fw->data, wl->nvs_len, GFP_KERNEL);
   if (!wl->nvs) {
     wl1251_error("could not allocate memory for the nvs file");
     ret = -ENOMEM;
     goto out;
   }
-  memcpy(wl->nvs, fw->data, wl->nvs_len);
   ret = 0;
 out:
   release_firmware(fw);
   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,26 +1,25 @@
 static int queue_dbg_open(struct inode *inode, struct file *file) {
   struct usba_ep *ep = inode->i_private;
   struct usba_request *req, *req_copy;
   struct list_head *queue_data;
   queue_data = kmalloc(sizeof(*queue_data), GFP_KERNEL);
   if (!queue_data) return -ENOMEM;
   INIT_LIST_HEAD(queue_data);
   spin_lock_irq(&ep->udc->lock);
   list_for_each_entry(req, &ep->queue, queue) {
-    req_copy = kmalloc(sizeof(*req_copy), GFP_ATOMIC);
+    req_copy = kmemdup(req, sizeof(*req_copy), GFP_ATOMIC);
     if (!req_copy) goto fail;
-    memcpy(req_copy, req, sizeof(*req_copy));
     list_add_tail(&req_copy->queue, queue_data);
   }
   spin_unlock_irq(&ep->udc->lock);
   file->private_data = queue_data;
   return 0;
 fail:
   spin_unlock_irq(&ep->udc->lock);
   list_for_each_entry_safe(req, req_copy, queue_data, queue) {
     list_del(&req->queue);
     kfree(req);
   }
   kfree(queue_data);
   return -ENOMEM;
 }<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,59 +1,58 @@
 int __init acpi_ec_ecdt_probe(void) {
   acpi_status status;
   struct acpi_ec *saved_ec = NULL;
   struct acpi_table_ecdt *ecdt_ptr;
   boot_ec = make_acpi_ec();
   if (!boot_ec) return -ENOMEM;
   /*
    * Generate a boot ec context
    */
   dmi_check_system(ec_dmi_table);
   status = acpi_get_table(ACPI_SIG_ECDT, 1, (struct acpi_table_header **)&ecdt_ptr);
   if (ACPI_SUCCESS(status)) {
     pr_info(PREFIX "EC description table is found, configuring boot EC\n");
     boot_ec->command_addr = ecdt_ptr->control.address;
     boot_ec->data_addr = ecdt_ptr->data.address;
     boot_ec->gpe = ecdt_ptr->gpe;
     boot_ec->handle = ACPI_ROOT_OBJECT;
     acpi_get_handle(ACPI_ROOT_OBJECT, ecdt_ptr->id, &boot_ec->handle);
     /* Don't trust ECDT, which comes from ASUSTek */
     if (!EC_FLAGS_VALIDATE_ECDT) goto install;
-    saved_ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
+    saved_ec = kmemdup(boot_ec, sizeof(struct acpi_ec), GFP_KERNEL);
     if (!saved_ec) return -ENOMEM;
-    memcpy(saved_ec, boot_ec, sizeof(struct acpi_ec));
     /* fall through */
   }
   if (EC_FLAGS_SKIP_DSDT_SCAN) return -ENODEV;
   /* This workaround is needed only on some broken machines,
    * which require early EC, but fail to provide ECDT */
   printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n");
   status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, boot_ec, NULL);
   /* Check that acpi_get_devices actually find something */
   if (ACPI_FAILURE(status) || !boot_ec->handle) goto error;
   if (saved_ec) {
     /* try to find good ECDT from ASUSTek */
     if (saved_ec->command_addr != boot_ec->command_addr || saved_ec->data_addr != boot_ec->data_addr || saved_ec->gpe != boot_ec->gpe || saved_ec->handle != boot_ec->handle)
       pr_info(PREFIX "ASUSTek keeps feeding us with broken "
                      "ECDT tables, which are very hard to workaround. "
                      "Trying to use DSDT EC info instead. Please send "
                      "output of acpidump to linux-acpi@vger.kernel.org\n");
     kfree(saved_ec);
     saved_ec = NULL;
   } else {
     /* We really need to limit this workaround, the only ASUS,
      * which needs it, has fake EC._INI method, so use it as flag.
      * Keep boot_ec struct as it will be needed soon.
      */
     acpi_handle dummy;
     if (!dmi_name_in_vendors("ASUS") || ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI", &dummy))) return -ENODEV;
   }
 install:
   if (!ec_install_handlers(boot_ec)) {
     first_ec = boot_ec;
     return 0;
   }
 error:
   kfree(boot_ec);
   boot_ec = NULL;
   return -ENODEV;
 }<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);