imamnurby/smpl_train_seed8 huggingface dataset:
--- initial
+++ final
@@ -1,12 +1,11 @@
 static int __init copy_keymap(void) {
   const struct key_entry *key;
   struct key_entry *new_keymap;
   unsigned int length = 1;
   for (key = keymap; key->type != KE_END; key++)
     length++;
-  new_keymap = kmalloc(length * sizeof(struct key_entry), GFP_KERNEL);
+  new_keymap = kmemdup(keymap, length * sizeof(struct key_entry), GFP_KERNEL);
   if (!new_keymap) return -ENOMEM;
-  memcpy(new_keymap, keymap, length * sizeof(struct key_entry));
   keymap = new_keymap;
   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,16 +1,15 @@
 static void reg_w_buf(struct gspca_dev *gspca_dev, const u8 *buffer, u16 len) {
   if (len <= USB_BUF_SZ) {
     memcpy(gspca_dev->usb_buf, buffer, len);
     usb_control_msg(gspca_dev->dev, usb_sndctrlpipe(gspca_dev->dev, 0), 0, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0x01, 0, gspca_dev->usb_buf, len, 500);
   } else {
     u8 *tmpbuf;
-    tmpbuf = kmalloc(len, GFP_KERNEL);
+    tmpbuf = kmemdup(buffer, len, GFP_KERNEL);
     if (!tmpbuf) {
       err("Out of memory");
       return;
     }
-    memcpy(tmpbuf, buffer, len);
     usb_control_msg(gspca_dev->dev, usb_sndctrlpipe(gspca_dev->dev, 0), 0, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0x01, 0, tmpbuf, len, 500);
     kfree(tmpbuf);
   }
 }<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,31 +1,30 @@
 static int firmware_download(struct usb_device *udev) {
   int ret = 0, actual_length;
   const struct firmware *fw = NULL;
   void *fwbuf = NULL;
   size_t fwlength = 0, offset;
   size_t max_packet_size;
   ret = request_firmware(&fw, firmware_name, &udev->dev);
   if (ret) {
     log("download err : %d", ret);
     return ret;
   }
   fwlength = fw->size;
-  fwbuf = kzalloc(fwlength, GFP_KERNEL);
+  fwbuf = kmemdup(fw->data, fwlength, GFP_KERNEL);
   if (!fwbuf) {
     ret = -ENOMEM;
     goto out;
   }
-  memcpy(fwbuf, fw->data, fwlength);
   max_packet_size = udev->ep_out[0x1]->desc.wMaxPacketSize;
   log("\t\t download size : %d", (int)max_packet_size);
   for (offset = 0; offset < fwlength; offset += max_packet_size) {
     actual_length = 0;
     ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x01), /* ep 1 */
                        fwbuf + offset, min(max_packet_size, fwlength - offset), &actual_length, HZ * 10);
     if (ret) break;
   }
   kfree(fwbuf);
 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,63 +1,62 @@
 struct videocodec *videocodec_attach(struct videocodec_master *master) {
   struct codec_list *h = codeclist_top;
   struct attached_list *a, *ptr;
   struct videocodec *codec;
   int res;
   if (!master) {
     dprintk(1, KERN_ERR "videocodec_attach: no data\n");
     return NULL;
   }
   dprintk(2, "videocodec_attach: '%s', flags %lx, magic %lx\n", master->name, master->flags, master->magic);
   if (!h) {
     dprintk(1, KERN_ERR "videocodec_attach: no device available\n");
     return NULL;
   }
   while (h) {
     // attach only if the slave has at least the flags
     // expected by the master
     if ((master->flags & h->codec->flags) == master->flags) {
       dprintk(4, "videocodec_attach: try '%s'\n", h->codec->name);
       if (!try_module_get(h->codec->owner)) return NULL;
-      codec = kmalloc(sizeof(struct videocodec), GFP_KERNEL);
+      codec = kmemdup(h->codec, sizeof(struct videocodec), GFP_KERNEL);
       if (!codec) {
         dprintk(1, KERN_ERR "videocodec_attach: no mem\n");
         goto out_module_put;
       }
-      memcpy(codec, h->codec, sizeof(struct videocodec));
       snprintf(codec->name, sizeof(codec->name), "%s[%d]", codec->name, h->attached);
       codec->master_data = master;
       res = codec->setup(codec);
       if (res == 0) {
         dprintk(3, "videocodec_attach '%s'\n", codec->name);
         ptr = kzalloc(sizeof(struct attached_list), GFP_KERNEL);
         if (!ptr) {
           dprintk(1, KERN_ERR "videocodec_attach: no memory\n");
           goto out_kfree;
         }
         ptr->codec = codec;
         a = h->list;
         if (!a) {
           h->list = ptr;
           dprintk(4, "videocodec: first element\n");
         } else {
           while (a->next)
             a = a->next; // find end
           a->next = ptr;
           dprintk(4, "videocodec: in after '%s'\n", h->codec->name);
         }
         h->attached += 1;
         return codec;
       } else {
         kfree(codec);
       }
     }
     h = h->next;
   }
   dprintk(1, KERN_ERR "videocodec_attach: no codec found!\n");
   return NULL;
 out_module_put:
   module_put(h->codec->owner);
 out_kfree:
   kfree(codec);
   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,64 +1,63 @@
 int ceph_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags) {
   struct inode *inode = dentry->d_inode;
   struct ceph_inode_info *ci = ceph_inode(inode);
   struct ceph_vxattr_cb *vxattrs = ceph_inode_vxattrs(inode);
   int err;
   int name_len = strlen(name);
   int val_len = size;
   char *newname = NULL;
   char *newval = NULL;
   struct ceph_inode_xattr *xattr = NULL;
   int issued;
   int required_blob_size;
   if (ceph_snap(inode) != CEPH_NOSNAP) return -EROFS;
   if (!ceph_is_valid_xattr(name)) return -EOPNOTSUPP;
   if (vxattrs) {
     struct ceph_vxattr_cb *vxattr = ceph_match_vxattr(vxattrs, name);
     if (vxattr && vxattr->readonly) return -EOPNOTSUPP;
   }
   /* preallocate memory for xattr name, value, index node */
   err = -ENOMEM;
-  newname = kmalloc(name_len + 1, GFP_NOFS);
+  newname = kmemdup(name, name_len + 1, GFP_NOFS);
   if (!newname) goto out;
-  memcpy(newname, name, name_len + 1);
   if (val_len) {
     newval = kmalloc(val_len + 1, GFP_NOFS);
     if (!newval) goto out;
     memcpy(newval, value, val_len);
     newval[val_len] = '\0';
   }
   xattr = kmalloc(sizeof(struct ceph_inode_xattr), GFP_NOFS);
   if (!xattr) goto out;
   spin_lock(&inode->i_lock);
 retry:
   issued = __ceph_caps_issued(ci, NULL);
   if (!(issued & CEPH_CAP_XATTR_EXCL)) goto do_sync;
   __build_xattrs(inode);
   required_blob_size = __get_required_blob_size(ci, name_len, val_len);
   if (!ci->i_xattrs.prealloc_blob || required_blob_size > ci->i_xattrs.prealloc_blob->alloc_len) {
     struct ceph_buffer *blob = NULL;
     spin_unlock(&inode->i_lock);
     dout(" preaallocating new blob size=%d\n", required_blob_size);
     blob = ceph_buffer_new(required_blob_size, GFP_NOFS);
     if (!blob) goto out;
     spin_lock(&inode->i_lock);
     if (ci->i_xattrs.prealloc_blob) ceph_buffer_put(ci->i_xattrs.prealloc_blob);
     ci->i_xattrs.prealloc_blob = blob;
     goto retry;
   }
   dout("setxattr %p issued %s\n", inode, ceph_cap_string(issued));
   err = __set_xattr(ci, newname, name_len, newval, val_len, 1, 1, 1, &xattr);
   __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
   ci->i_xattrs.dirty = true;
   inode->i_ctime = CURRENT_TIME;
   spin_unlock(&inode->i_lock);
   return err;
 do_sync:
   spin_unlock(&inode->i_lock);
   err = ceph_sync_setxattr(dentry, name, value, size, flags);
 out:
   kfree(newname);
   kfree(newval);
   kfree(xattr);
   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,24 +1,22 @@
 static int vf610_ocotp_probe(struct platform_device *pdev) {
   struct device *dev = &pdev->dev;
   struct resource *res;
   struct vf610_ocotp *ocotp_dev;
   ocotp_dev = devm_kzalloc(&pdev->dev, sizeof(struct vf610_ocotp), GFP_KERNEL);
   if (!ocotp_dev) return -ENOMEM;
   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   ocotp_dev->base = devm_ioremap_resource(dev, res);
   if (IS_ERR(ocotp_dev->base)) return PTR_ERR(ocotp_dev->base);
   ocotp_dev->clk = devm_clk_get(dev, NULL);
   if (IS_ERR(ocotp_dev->clk)) {
     dev_err(dev, "failed getting clock, err = %ld\n", PTR_ERR(ocotp_dev->clk));
     return PTR_ERR(ocotp_dev->clk);
   }
   ocotp_config.size = resource_size(res);
   ocotp_config.priv = ocotp_dev;
   ocotp_config.dev = dev;
-  ocotp_dev->nvmem = nvmem_register(&ocotp_config);
-  if (IS_ERR(ocotp_dev->nvmem)) return PTR_ERR(ocotp_dev->nvmem);
   ocotp_dev->dev = dev;
-  platform_set_drvdata(pdev, ocotp_dev);
   ocotp_dev->timing = vf610_ocotp_calculate_timing(ocotp_dev);
-  return 0;
+  ocotp_dev->nvmem = devm_nvmem_register(dev, &ocotp_config);
+  return PTR_ERR_OR_ZERO(ocotp_dev->nvmem);
 }<sep>@@
expression nvmem,e,e1,pdev;
identifier d;
@@

	struct device *d = &pdev->dev;
	... when exists
-	nvmem = nvmem_register(e);
-	if (IS_ERR(nvmem))
-		return PTR_ERR(nvmem);
	...
-	platform_set_drvdata(pdev, e1);
	...
-	return 0;
+	nvmem = devm_nvmem_register(d, e);
+	return PTR_ERR_OR_ZERO(nvmem);
--- initial
+++ final
@@ -1,25 +1,23 @@
 static int imx_ocotp_probe(struct platform_device *pdev) {
   const struct of_device_id *of_id;
   struct device *dev = &pdev->dev;
   struct resource *res;
   struct ocotp_priv *priv;
   struct nvmem_device *nvmem;
   priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
   if (!priv) return -ENOMEM;
   priv->dev = dev;
   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   priv->base = devm_ioremap_resource(dev, res);
   if (IS_ERR(priv->base)) return PTR_ERR(priv->base);
   priv->clk = devm_clk_get(dev, NULL);
   if (IS_ERR(priv->clk)) return PTR_ERR(priv->clk);
   of_id = of_match_device(imx_ocotp_dt_ids, dev);
   priv->params = of_device_get_match_data(&pdev->dev);
   imx_ocotp_nvmem_config.size = 4 * priv->params->nregs;
   imx_ocotp_nvmem_config.dev = dev;
   imx_ocotp_nvmem_config.priv = priv;
   priv->config = &imx_ocotp_nvmem_config;
-  nvmem = nvmem_register(&imx_ocotp_nvmem_config);
-  if (IS_ERR(nvmem)) return PTR_ERR(nvmem);
-  platform_set_drvdata(pdev, nvmem);
-  return 0;
+  nvmem = devm_nvmem_register(dev, &imx_ocotp_nvmem_config);
+  return PTR_ERR_OR_ZERO(nvmem);
 }<sep>@@
expression nvmem,e,e1,pdev;
identifier d;
@@

	struct device *d = &pdev->dev;
	... when exists
-	nvmem = nvmem_register(e);
-	if (IS_ERR(nvmem))
-		return PTR_ERR(nvmem);
	...
-	platform_set_drvdata(pdev, e1);
	...
-	return 0;
+	nvmem = devm_nvmem_register(d, e);
+	return PTR_ERR_OR_ZERO(nvmem);
--- initial
+++ final
@@ -1,23 +1,21 @@
 static int uniphier_efuse_probe(struct platform_device *pdev) {
   struct device *dev = &pdev->dev;
   struct resource *res;
   struct nvmem_device *nvmem;
   struct nvmem_config econfig = {};
   struct uniphier_efuse_priv *priv;
   priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
   if (!priv) return -ENOMEM;
   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   priv->base = devm_ioremap_resource(dev, res);
   if (IS_ERR(priv->base)) return PTR_ERR(priv->base);
   econfig.stride = 1;
   econfig.word_size = 1;
   econfig.read_only = true;
   econfig.reg_read = uniphier_reg_read;
   econfig.size = resource_size(res);
   econfig.priv = priv;
   econfig.dev = dev;
-  nvmem = nvmem_register(&econfig);
-  if (IS_ERR(nvmem)) return PTR_ERR(nvmem);
-  platform_set_drvdata(pdev, nvmem);
-  return 0;
+  nvmem = devm_nvmem_register(dev, &econfig);
+  return PTR_ERR_OR_ZERO(nvmem);
 }<sep>@@
expression nvmem,e,e1,pdev;
identifier d;
@@

	struct device *d = &pdev->dev;
	... when exists
-	nvmem = nvmem_register(e);
-	if (IS_ERR(nvmem))
-		return PTR_ERR(nvmem);
	...
-	platform_set_drvdata(pdev, e1);
	...
-	return 0;
+	nvmem = devm_nvmem_register(d, e);
+	return PTR_ERR_OR_ZERO(nvmem);
--- initial
+++ final
@@ -1,28 +1,26 @@
 static int rockchip_efuse_probe(struct platform_device *pdev) {
   struct resource *res;
   struct nvmem_device *nvmem;
   struct rockchip_efuse_chip *efuse;
   const struct of_device_id *match;
   struct device *dev = &pdev->dev;
   match = of_match_device(dev->driver->of_match_table, dev);
   if (!match || !match->data) {
     dev_err(dev, "failed to get match data\n");
     return -EINVAL;
   }
   efuse = devm_kzalloc(&pdev->dev, sizeof(struct rockchip_efuse_chip), GFP_KERNEL);
   if (!efuse) return -ENOMEM;
   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   efuse->base = devm_ioremap_resource(&pdev->dev, res);
   if (IS_ERR(efuse->base)) return PTR_ERR(efuse->base);
   efuse->clk = devm_clk_get(&pdev->dev, "pclk_efuse");
   if (IS_ERR(efuse->clk)) return PTR_ERR(efuse->clk);
   efuse->dev = &pdev->dev;
   if (of_property_read_u32(dev->of_node, "rockchip,efuse-size", &econfig.size)) econfig.size = resource_size(res);
   econfig.reg_read = match->data;
   econfig.priv = efuse;
   econfig.dev = efuse->dev;
-  nvmem = nvmem_register(&econfig);
-  if (IS_ERR(nvmem)) return PTR_ERR(nvmem);
-  platform_set_drvdata(pdev, nvmem);
-  return 0;
+  nvmem = devm_nvmem_register(dev, &econfig);
+  return PTR_ERR_OR_ZERO(nvmem);
 }<sep>@@
expression nvmem,e,e1,pdev;
identifier d;
@@

	struct device *d = &pdev->dev;
	... when exists
-	nvmem = nvmem_register(e);
-	if (IS_ERR(nvmem))
-		return PTR_ERR(nvmem);
	...
-	platform_set_drvdata(pdev, e1);
	...
-	return 0;
+	nvmem = devm_nvmem_register(d, e);
+	return PTR_ERR_OR_ZERO(nvmem);
--- initial
+++ final
@@ -1,23 +1,21 @@
 static int mtk_efuse_probe(struct platform_device *pdev) {
   struct device *dev = &pdev->dev;
   struct resource *res;
   struct nvmem_device *nvmem;
   struct nvmem_config econfig = {};
   struct mtk_efuse_priv *priv;
   priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
   if (!priv) return -ENOMEM;
   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   priv->base = devm_ioremap_resource(dev, res);
   if (IS_ERR(priv->base)) return PTR_ERR(priv->base);
   econfig.stride = 4;
   econfig.word_size = 4;
   econfig.reg_read = mtk_reg_read;
   econfig.reg_write = mtk_reg_write;
   econfig.size = resource_size(res);
   econfig.priv = priv;
   econfig.dev = dev;
-  nvmem = nvmem_register(&econfig);
-  if (IS_ERR(nvmem)) return PTR_ERR(nvmem);
-  platform_set_drvdata(pdev, nvmem);
-  return 0;
+  nvmem = devm_nvmem_register(dev, &econfig);
+  return PTR_ERR_OR_ZERO(nvmem);
 }<sep>@@
expression nvmem,e,e1,pdev;
identifier d;
@@

	struct device *d = &pdev->dev;
	... when exists
-	nvmem = nvmem_register(e);
-	if (IS_ERR(nvmem))
-		return PTR_ERR(nvmem);
	...
-	platform_set_drvdata(pdev, e1);
	...
-	return 0;
+	nvmem = devm_nvmem_register(d, e);
+	return PTR_ERR_OR_ZERO(nvmem);
--- initial
+++ final
@@ -1,30 +1,28 @@
 static int meson_mx_efuse_probe(struct platform_device *pdev) {
   const struct meson_mx_efuse_platform_data *drvdata;
   struct meson_mx_efuse *efuse;
   struct resource *res;
   drvdata = of_device_get_match_data(&pdev->dev);
   if (!drvdata) return -EINVAL;
   efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL);
   if (!efuse) return -ENOMEM;
   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   efuse->base = devm_ioremap_resource(&pdev->dev, res);
   if (IS_ERR(efuse->base)) return PTR_ERR(efuse->base);
   efuse->config.name = devm_kstrdup(&pdev->dev, drvdata->name, GFP_KERNEL);
   efuse->config.owner = THIS_MODULE;
   efuse->config.dev = &pdev->dev;
   efuse->config.priv = efuse;
   efuse->config.stride = drvdata->word_size;
   efuse->config.word_size = drvdata->word_size;
   efuse->config.size = SZ_512;
   efuse->config.read_only = true;
   efuse->config.reg_read = meson_mx_efuse_read;
   efuse->core_clk = devm_clk_get(&pdev->dev, "core");
   if (IS_ERR(efuse->core_clk)) {
     dev_err(&pdev->dev, "Failed to get core clock\n");
     return PTR_ERR(efuse->core_clk);
   }
-  efuse->nvmem = nvmem_register(&efuse->config);
-  if (IS_ERR(efuse->nvmem)) return PTR_ERR(efuse->nvmem);
-  platform_set_drvdata(pdev, efuse);
-  return 0;
+  efuse->nvmem = devm_nvmem_register(&pdev->dev, &efuse->config);
+  return PTR_ERR_OR_ZERO(efuse->nvmem);
 }<sep>@@
expression nvmem,e,e1,pdev;
@@

-	nvmem = nvmem_register(e);
-	if (IS_ERR(nvmem))
-		return PTR_ERR(nvmem);
	...
-	platform_set_drvdata(pdev, e1);
	...
-	return 0;
+	nvmem = devm_nvmem_register(&pdev->dev, e);
+	return PTR_ERR_OR_ZERO(nvmem);
--- initial
+++ final
@@ -1,12 +1,10 @@
 static int meson_efuse_probe(struct platform_device *pdev) {
   struct nvmem_device *nvmem;
   unsigned int size;
   if (meson_sm_call(SM_EFUSE_USER_MAX, &size, 0, 0, 0, 0, 0) < 0) return -EINVAL;
   econfig.dev = &pdev->dev;
   econfig.reg_read = meson_efuse_read;
   econfig.size = size;
-  nvmem = nvmem_register(&econfig);
-  if (IS_ERR(nvmem)) return PTR_ERR(nvmem);
-  platform_set_drvdata(pdev, nvmem);
-  return 0;
+  nvmem = devm_nvmem_register(&pdev->dev, &econfig);
+  return PTR_ERR_OR_ZERO(nvmem);
 }<sep>@@
expression nvmem,e,e1,pdev;
@@

-	nvmem = nvmem_register(e);
-	if (IS_ERR(nvmem))
-		return PTR_ERR(nvmem);
	...
-	platform_set_drvdata(pdev, e1);
	...
-	return 0;
+	nvmem = devm_nvmem_register(&pdev->dev, e);
+	return PTR_ERR_OR_ZERO(nvmem);
--- initial
+++ final
@@ -1,17 +1,15 @@
 static int lpc18xx_otp_probe(struct platform_device *pdev) {
   struct nvmem_device *nvmem;
   struct lpc18xx_otp *otp;
   struct resource *res;
   otp = devm_kzalloc(&pdev->dev, sizeof(*otp), GFP_KERNEL);
   if (!otp) return -ENOMEM;
   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   otp->base = devm_ioremap_resource(&pdev->dev, res);
   if (IS_ERR(otp->base)) return PTR_ERR(otp->base);
   lpc18xx_otp_nvmem_config.size = LPC18XX_OTP_SIZE;
   lpc18xx_otp_nvmem_config.dev = &pdev->dev;
   lpc18xx_otp_nvmem_config.priv = otp;
-  nvmem = nvmem_register(&lpc18xx_otp_nvmem_config);
-  if (IS_ERR(nvmem)) return PTR_ERR(nvmem);
-  platform_set_drvdata(pdev, nvmem);
-  return 0;
+  nvmem = devm_nvmem_register(&pdev->dev, &lpc18xx_otp_nvmem_config);
+  return PTR_ERR_OR_ZERO(nvmem);
 }<sep>@@
expression nvmem,e,e1,pdev;
@@

-	nvmem = nvmem_register(e);
-	if (IS_ERR(nvmem))
-		return PTR_ERR(nvmem);
	...
-	platform_set_drvdata(pdev, e1);
	...
-	return 0;
+	nvmem = devm_nvmem_register(&pdev->dev, e);
+	return PTR_ERR_OR_ZERO(nvmem);
--- initial
+++ final
@@ -1,26 +1,24 @@
 static int imx_iim_probe(struct platform_device *pdev) {
   const struct of_device_id *of_id;
   struct device *dev = &pdev->dev;
   struct resource *res;
   struct iim_priv *iim;
   struct nvmem_device *nvmem;
   struct nvmem_config cfg = {};
   const struct imx_iim_drvdata *drvdata = NULL;
   iim = devm_kzalloc(dev, sizeof(*iim), GFP_KERNEL);
   if (!iim) return -ENOMEM;
   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   iim->base = devm_ioremap_resource(dev, res);
   if (IS_ERR(iim->base)) return PTR_ERR(iim->base);
   of_id = of_match_device(imx_iim_dt_ids, dev);
   if (!of_id) return -ENODEV;
   drvdata = of_id->data;
   iim->clk = devm_clk_get(&pdev->dev, NULL);
   if (IS_ERR(iim->clk)) return PTR_ERR(iim->clk);
   cfg.name = "imx-iim", cfg.read_only = true, cfg.word_size = 1, cfg.stride = 1, cfg.reg_read = imx_iim_read, cfg.dev = dev;
   cfg.size = drvdata->nregs;
   cfg.priv = iim;
-  nvmem = nvmem_register(&cfg);
-  if (IS_ERR(nvmem)) return PTR_ERR(nvmem);
-  platform_set_drvdata(pdev, nvmem);
-  return 0;
+  nvmem = devm_nvmem_register(dev, &cfg);
+  return PTR_ERR_OR_ZERO(nvmem);
 }<sep>@@
expression nvmem,e,e1,pdev;
identifier d;
@@

	struct device *d = &pdev->dev;
	... when exists
-	nvmem = nvmem_register(e);
-	if (IS_ERR(nvmem))
-		return PTR_ERR(nvmem);
	...
-	platform_set_drvdata(pdev, e1);
	...
-	return 0;
+	nvmem = devm_nvmem_register(d, e);
+	return PTR_ERR_OR_ZERO(nvmem);
--- initial
+++ final
@@ -1,53 +1,52 @@
 static int bcm_otpc_probe(struct platform_device *pdev) {
   struct device *dev = &pdev->dev;
   struct device_node *dn = dev->of_node;
   struct resource *res;
   struct otpc_priv *priv;
   struct nvmem_device *nvmem;
   int err;
   u32 num_words;
   priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
   if (!priv) return -ENOMEM;
   if (of_device_is_compatible(dev->of_node, "brcm,ocotp"))
     priv->map = &otp_map;
   else if (of_device_is_compatible(dev->of_node, "brcm,ocotp-v2"))
     priv->map = &otp_map_v2;
   else {
     dev_err(&pdev->dev, "%s otpc config map not defined\n", __func__);
     return -EINVAL;
   }
   /* Get OTP base address register. */
   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   priv->base = devm_ioremap_resource(dev, res);
   if (IS_ERR(priv->base)) {
     dev_err(dev, "unable to map I/O memory\n");
     return PTR_ERR(priv->base);
   }
   /* Enable CPU access to OTPC. */
   writel(readl(priv->base + OTPC_MODE_REG_OFFSET) | BIT(OTPC_MODE_REG_OTPC_MODE), priv->base + OTPC_MODE_REG_OFFSET);
   reset_start_bit(priv->base);
   /* Read size of memory in words. */
   err = of_property_read_u32(dn, "brcm,ocotp-size", &num_words);
   if (err) {
     dev_err(dev, "size parameter not specified\n");
     return -EINVAL;
   } else if (num_words == 0) {
     dev_err(dev, "size must be > 0\n");
     return -EINVAL;
   }
   bcm_otpc_nvmem_config.size = 4 * num_words;
   bcm_otpc_nvmem_config.dev = dev;
   bcm_otpc_nvmem_config.priv = priv;
   if (of_device_is_compatible(dev->of_node, "brcm,ocotp-v2")) {
     bcm_otpc_nvmem_config.word_size = 8;
     bcm_otpc_nvmem_config.stride = 8;
   }
   priv->config = &bcm_otpc_nvmem_config;
-  nvmem = nvmem_register(&bcm_otpc_nvmem_config);
+  nvmem = devm_nvmem_register(dev, &bcm_otpc_nvmem_config);
   if (IS_ERR(nvmem)) {
     dev_err(dev, "error registering nvmem config\n");
     return PTR_ERR(nvmem);
   }
-  platform_set_drvdata(pdev, nvmem);
   return 0;
 }<sep>@@
expression nvmem,e,e1,pdev;
identifier d;
@@

	struct device *d = &pdev->dev;
	... when exists 
-	nvmem = nvmem_register(e);
+	nvmem = devm_nvmem_register(d, e);
	if (IS_ERR(nvmem)) { ... }
	...
-	platform_set_drvdata(pdev, e1);
--- initial
+++ final
@@ -1,18 +1,16 @@
 static int qfprom_probe(struct platform_device *pdev) {
   struct device *dev = &pdev->dev;
   struct resource *res;
   struct nvmem_device *nvmem;
   struct qfprom_priv *priv;
   priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
   if (!priv) return -ENOMEM;
   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   priv->base = devm_ioremap_resource(dev, res);
   if (IS_ERR(priv->base)) return PTR_ERR(priv->base);
   econfig.size = resource_size(res);
   econfig.dev = dev;
   econfig.priv = priv;
-  nvmem = nvmem_register(&econfig);
-  if (IS_ERR(nvmem)) return PTR_ERR(nvmem);
-  platform_set_drvdata(pdev, nvmem);
-  return 0;
+  nvmem = devm_nvmem_register(dev, &econfig);
+  return PTR_ERR_OR_ZERO(nvmem);
 }<sep>@@
expression nvmem,e,e1,pdev;
identifier d;
@@

	struct device *d = &pdev->dev;
	... when exists
-	nvmem = nvmem_register(e);
-	if (IS_ERR(nvmem))
-		return PTR_ERR(nvmem);
	...
-	platform_set_drvdata(pdev, e1);
	...
-	return 0;
+	nvmem = devm_nvmem_register(d, e);
+	return PTR_ERR_OR_ZERO(nvmem);
--- initial
+++ final
@@ -1,22 +1,22 @@
 int ll_d_init(struct dentry *de) {
   LASSERT(de != NULL);
   CDEBUG(D_DENTRY, "ldd on dentry %.*s (%p) parent %p inode %p refc %d\n", de->d_name.len, de->d_name.name, de, de->d_parent, de->d_inode, d_count(de));
   if (de->d_fsdata == NULL) {
     struct ll_dentry_data *lld;
-    OBD_ALLOC_PTR(lld);
-    if (likely(lld != NULL)) {
+    lld = kzalloc(sizeof(*lld), GFP_NOFS);
+    if (likely(lld)) {
       spin_lock(&de->d_lock);
       if (likely(de->d_fsdata == NULL)) {
         de->d_fsdata = lld;
         __d_lustre_invalidate(de);
       } else {
         OBD_FREE_PTR(lld);
       }
       spin_unlock(&de->d_lock);
     } else {
       return -ENOMEM;
     }
   }
   LASSERT(de->d_op == &ll_d_ops);
   return 0;
 }<sep>@@
expression e;
statement S1,S2;
@@

-	OBD_ALLOC_PTR(e);
+	e = kzalloc(sizeof(*e), GFP_NOFS);
 	if (likely(
-	    e != NULL
+	    e
	   ))
	S1 else S2