imamnurby/smpl_train_seed8 huggingface dataset:
--- initial
+++ final
@@ -1,65 +1,65 @@
 static int omapdrm_init(struct omap_drm_private *priv, struct device *dev) {
   const struct soc_device_attribute *soc;
   struct drm_device *ddev;
   unsigned int i;
   int ret;
   DBG("%s", dev_name(dev));
   /* Allocate and initialize the DRM device. */
   ddev = drm_dev_alloc(&omap_drm_driver, dev);
   if (IS_ERR(ddev)) return PTR_ERR(ddev);
   priv->ddev = ddev;
   ddev->dev_private = priv;
   priv->dev = dev;
   priv->dss = omapdss_get_dss();
   priv->dispc = dispc_get_dispc(priv->dss);
   priv->dispc_ops = dispc_get_ops(priv->dss);
   omap_crtc_pre_init(priv);
   ret = omap_connect_pipelines(ddev);
   if (ret) goto err_crtc_uninit;
   soc = soc_device_match(omapdrm_soc_devices);
   priv->omaprev = soc ? (unsigned int)soc->data : 0;
   priv->wq = alloc_ordered_workqueue("omapdrm", 0);
   mutex_init(&priv->list_lock);
   INIT_LIST_HEAD(&priv->obj_list);
   /* Get memory bandwidth limits */
   if (priv->dispc_ops->get_memory_bandwidth_limit) priv->max_bandwidth = priv->dispc_ops->get_memory_bandwidth_limit(priv->dispc);
   omap_gem_init(ddev);
   ret = omap_modeset_init(ddev);
   if (ret) {
     dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret);
     goto err_gem_deinit;
   }
   /* Initialize vblank handling, start with all CRTCs disabled. */
   ret = drm_vblank_init(ddev, priv->num_pipes);
   if (ret) {
     dev_err(priv->dev, "could not init vblank\n");
     goto err_cleanup_modeset;
   }
   for (i = 0; i < priv->num_pipes; i++)
     drm_crtc_vblank_off(priv->pipes[i].crtc);
   omap_fbdev_init(ddev);
   drm_kms_helper_poll_init(ddev);
   omap_modeset_enable_external_hpd(ddev);
   /*
    * Register the DRM device with the core and the connectors with
    * sysfs.
    */
   ret = drm_dev_register(ddev, 0);
   if (ret) goto err_cleanup_helpers;
   return 0;
 err_cleanup_helpers:
   omap_modeset_disable_external_hpd(ddev);
   drm_kms_helper_poll_fini(ddev);
   omap_fbdev_fini(ddev);
 err_cleanup_modeset:
   drm_mode_config_cleanup(ddev);
   omap_drm_irq_uninstall(ddev);
 err_gem_deinit:
   omap_gem_deinit(ddev);
   destroy_workqueue(priv->wq);
   omap_disconnect_pipelines(ddev);
 err_crtc_uninit:
   omap_crtc_pre_uninit(priv);
-  drm_dev_unref(ddev);
+  drm_dev_put(ddev);
   return ret;
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,34 +1,34 @@
 static int hibmc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) {
   struct drm_device *dev;
   int ret;
   dev = drm_dev_alloc(&hibmc_driver, &pdev->dev);
   if (IS_ERR(dev)) {
     DRM_ERROR("failed to allocate drm_device\n");
     return PTR_ERR(dev);
   }
   dev->pdev = pdev;
   pci_set_drvdata(pdev, dev);
   ret = pci_enable_device(pdev);
   if (ret) {
     DRM_ERROR("failed to enable pci device: %d\n", ret);
     goto err_free;
   }
   ret = hibmc_load(dev);
   if (ret) {
     DRM_ERROR("failed to load hibmc: %d\n", ret);
     goto err_disable;
   }
   ret = drm_dev_register(dev, 0);
   if (ret) {
     DRM_ERROR("failed to register drv for userspace access: %d\n", ret);
     goto err_unload;
   }
   return 0;
 err_unload:
   hibmc_unload(dev);
 err_disable:
   pci_disable_device(pdev);
 err_free:
-  drm_dev_unref(dev);
+  drm_dev_put(dev);
   return ret;
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,6 +1,6 @@
 static void hibmc_pci_remove(struct pci_dev *pdev) {
   struct drm_device *dev = pci_get_drvdata(pdev);
   drm_dev_unregister(dev);
   hibmc_unload(dev);
-  drm_dev_unref(dev);
+  drm_dev_put(dev);
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,17 +1,17 @@
 static int kirin_drm_bind(struct device *dev) {
   struct drm_driver *driver = &kirin_drm_driver;
   struct drm_device *drm_dev;
   int ret;
   drm_dev = drm_dev_alloc(driver, dev);
   if (IS_ERR(drm_dev)) return PTR_ERR(drm_dev);
   ret = kirin_drm_kms_init(drm_dev);
   if (ret) goto err_drm_dev_unref;
   ret = drm_dev_register(drm_dev, 0);
   if (ret) goto err_kms_cleanup;
   return 0;
 err_kms_cleanup:
   kirin_drm_kms_cleanup(drm_dev);
 err_drm_dev_unref:
-  drm_dev_unref(drm_dev);
+  drm_dev_put(drm_dev);
   return ret;
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,6 +1,6 @@
 static void kirin_drm_unbind(struct device *dev) {
   struct drm_device *drm_dev = dev_get_drvdata(dev);
   drm_dev_unregister(drm_dev);
   kirin_drm_kms_cleanup(drm_dev);
-  drm_dev_unref(drm_dev);
+  drm_dev_put(drm_dev);
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,10 +1,10 @@
 static void qxl_pci_remove(struct pci_dev *pdev) {
   struct drm_device *dev = pci_get_drvdata(pdev);
   struct qxl_device *qdev = dev->dev_private;
   drm_dev_unregister(dev);
   qxl_modeset_fini(qdev);
   qxl_device_fini(qdev);
   dev->dev_private = NULL;
   kfree(qdev);
-  drm_dev_unref(dev);
+  drm_dev_put(dev);
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,6 +1,6 @@
 static void tinydrm_fini(struct tinydrm_device *tdev) {
   drm_mode_config_cleanup(tdev->drm);
   mutex_destroy(&tdev->dirty_lock);
   tdev->drm->dev_private = NULL;
-  drm_dev_unref(tdev->drm);
+  drm_dev_put(tdev->drm);
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,4 +1,4 @@
 static void __exit vgem_exit(void) {
   drm_dev_unregister(&vgem_device->drm);
-  drm_dev_unref(&vgem_device->drm);
+  drm_dev_put(&vgem_device->drm);
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,25 +1,25 @@
 int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev) {
   struct drm_device *dev;
   int ret;
   dev = drm_dev_alloc(driver, &vdev->dev);
   if (IS_ERR(dev)) return PTR_ERR(dev);
   vdev->priv = dev;
   if (strcmp(vdev->dev.parent->bus->name, "pci") == 0) {
     struct pci_dev *pdev = to_pci_dev(vdev->dev.parent);
     const char *pname = dev_name(&pdev->dev);
     bool vga = (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA;
     char unique[20];
     DRM_INFO("pci: %s detected at %s\n", vga ? "virtio-vga" : "virtio-gpu-pci", pname);
     dev->pdev = pdev;
     if (vga) virtio_pci_kick_out_firmware_fb(pdev);
     snprintf(unique, sizeof(unique), "pci:%s", pname);
     ret = drm_dev_set_unique(dev, unique);
     if (ret) goto err_free;
   }
   ret = drm_dev_register(dev, 0);
   if (ret) goto err_free;
   return 0;
 err_free:
-  drm_dev_unref(dev);
+  drm_dev_put(dev);
   return ret;
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,52 +1,52 @@
 static int rockchip_drm_bind(struct device *dev) {
   struct drm_device *drm_dev;
   struct rockchip_drm_private *private;
   int ret;
   drm_dev = drm_dev_alloc(&rockchip_drm_driver, dev);
   if (IS_ERR(drm_dev)) return PTR_ERR(drm_dev);
   dev_set_drvdata(dev, drm_dev);
 private
   = devm_kzalloc(drm_dev->dev, sizeof(*private), GFP_KERNEL);
   if (!private) {
     ret = -ENOMEM;
     goto err_free;
   }
   drm_dev->dev_private = private;
   INIT_LIST_HEAD(&private->psr_list);
   mutex_init(&private->psr_list_lock);
   ret = rockchip_drm_init_iommu(drm_dev);
   if (ret) goto err_free;
   drm_mode_config_init(drm_dev);
   rockchip_drm_mode_config_init(drm_dev);
   /* Try to bind all sub drivers. */
   ret = component_bind_all(dev, drm_dev);
   if (ret) goto err_mode_config_cleanup;
   ret = drm_vblank_init(drm_dev, drm_dev->mode_config.num_crtc);
   if (ret) goto err_unbind_all;
   drm_mode_config_reset(drm_dev);
   /*
    * enable drm irq mode.
    * - with irq_enabled = true, we can use the vblank feature.
    */
   drm_dev->irq_enabled = true;
   ret = rockchip_drm_fbdev_init(drm_dev);
   if (ret) goto err_unbind_all;
   /* init kms poll for handling hpd */
   drm_kms_helper_poll_init(drm_dev);
   ret = drm_dev_register(drm_dev, 0);
   if (ret) goto err_kms_helper_poll_fini;
   return 0;
 err_kms_helper_poll_fini:
   drm_kms_helper_poll_fini(drm_dev);
   rockchip_drm_fbdev_fini(drm_dev);
 err_unbind_all:
   component_unbind_all(dev, drm_dev);
 err_mode_config_cleanup:
   drm_mode_config_cleanup(drm_dev);
   rockchip_iommu_cleanup(drm_dev);
 err_free:
   drm_dev->dev_private = NULL;
   dev_set_drvdata(dev, NULL);
-  drm_dev_unref(drm_dev);
+  drm_dev_put(drm_dev);
   return ret;
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,13 +1,13 @@
 static void rockchip_drm_unbind(struct device *dev) {
   struct drm_device *drm_dev = dev_get_drvdata(dev);
   drm_dev_unregister(drm_dev);
   rockchip_drm_fbdev_fini(drm_dev);
   drm_kms_helper_poll_fini(drm_dev);
   drm_atomic_helper_shutdown(drm_dev);
   component_unbind_all(dev, drm_dev);
   drm_mode_config_cleanup(drm_dev);
   rockchip_iommu_cleanup(drm_dev);
   drm_dev->dev_private = NULL;
   dev_set_drvdata(dev, NULL);
-  drm_dev_unref(drm_dev);
+  drm_dev_put(drm_dev);
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,80 +1,80 @@
 static int fsl_dcu_drm_probe(struct platform_device *pdev) {
   struct fsl_dcu_drm_device *fsl_dev;
   struct drm_device *drm;
   struct device *dev = &pdev->dev;
   struct resource *res;
   void __iomem *base;
   struct drm_driver *driver = &fsl_dcu_drm_driver;
   struct clk *pix_clk_in;
   char pix_clk_name[32];
   const char *pix_clk_in_name;
   const struct of_device_id *id;
   int ret;
   u8 div_ratio_shift = 0;
   fsl_dev = devm_kzalloc(dev, sizeof(*fsl_dev), GFP_KERNEL);
   if (!fsl_dev) return -ENOMEM;
   id = of_match_node(fsl_dcu_of_match, pdev->dev.of_node);
   if (!id) return -ENODEV;
   fsl_dev->soc = id->data;
   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   base = devm_ioremap_resource(dev, res);
   if (IS_ERR(base)) {
     ret = PTR_ERR(base);
     return ret;
   }
   fsl_dev->irq = platform_get_irq(pdev, 0);
   if (fsl_dev->irq < 0) {
     dev_err(dev, "failed to get irq\n");
     return fsl_dev->irq;
   }
   fsl_dev->regmap = devm_regmap_init_mmio(dev, base, &fsl_dcu_regmap_config);
   if (IS_ERR(fsl_dev->regmap)) {
     dev_err(dev, "regmap init failed\n");
     return PTR_ERR(fsl_dev->regmap);
   }
   fsl_dev->clk = devm_clk_get(dev, "dcu");
   if (IS_ERR(fsl_dev->clk)) {
     dev_err(dev, "failed to get dcu clock\n");
     return PTR_ERR(fsl_dev->clk);
   }
   ret = clk_prepare_enable(fsl_dev->clk);
   if (ret < 0) {
     dev_err(dev, "failed to enable dcu clk\n");
     return ret;
   }
   pix_clk_in = devm_clk_get(dev, "pix");
   if (IS_ERR(pix_clk_in)) {
     /* legancy binding, use dcu clock as pixel clock input */
     pix_clk_in = fsl_dev->clk;
   }
   if (of_property_read_bool(dev->of_node, "big-endian")) div_ratio_shift = 24;
   pix_clk_in_name = __clk_get_name(pix_clk_in);
   snprintf(pix_clk_name, sizeof(pix_clk_name), "%s_pix", pix_clk_in_name);
   fsl_dev->pix_clk = clk_register_divider(dev, pix_clk_name, pix_clk_in_name, 0, base + DCU_DIV_RATIO, div_ratio_shift, 8, CLK_DIVIDER_ROUND_CLOSEST, NULL);
   if (IS_ERR(fsl_dev->pix_clk)) {
     dev_err(dev, "failed to register pix clk\n");
     ret = PTR_ERR(fsl_dev->pix_clk);
     goto disable_clk;
   }
   fsl_dev->tcon = fsl_tcon_init(dev);
   drm = drm_dev_alloc(driver, dev);
   if (IS_ERR(drm)) {
     ret = PTR_ERR(drm);
     goto unregister_pix_clk;
   }
   fsl_dev->dev = dev;
   fsl_dev->drm = drm;
   fsl_dev->np = dev->of_node;
   drm->dev_private = fsl_dev;
   dev_set_drvdata(dev, fsl_dev);
   ret = drm_dev_register(drm, 0);
   if (ret < 0) goto unref;
   return 0;
 unref:
-  drm_dev_unref(drm);
+  drm_dev_put(drm);
 unregister_pix_clk:
   clk_unregister(fsl_dev->pix_clk);
 disable_clk:
   clk_disable_unprepare(fsl_dev->clk);
   return ret;
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,8 +1,8 @@
 static int fsl_dcu_drm_remove(struct platform_device *pdev) {
   struct fsl_dcu_drm_device *fsl_dev = platform_get_drvdata(pdev);
   drm_dev_unregister(fsl_dev->drm);
-  drm_dev_unref(fsl_dev->drm);
+  drm_dev_put(fsl_dev->drm);
   clk_disable_unprepare(fsl_dev->clk);
   clk_unregister(fsl_dev->pix_clk);
   return 0;
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,58 +1,58 @@
 static int msm_drm_uninit(struct device *dev) {
   struct platform_device *pdev = to_platform_device(dev);
   struct drm_device *ddev = platform_get_drvdata(pdev);
   struct msm_drm_private *priv = ddev->dev_private;
   struct msm_kms *kms = priv->kms;
   struct msm_mdss *mdss = priv->mdss;
   struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl;
   struct vblank_event *vbl_ev, *tmp;
   int i;
   /* We must cancel and cleanup any pending vblank enable/disable
    * work before drm_irq_uninstall() to avoid work re-enabling an
    * irq after uninstall has disabled it.
    */
   kthread_flush_work(&vbl_ctrl->work);
   list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) {
     list_del(&vbl_ev->node);
     kfree(vbl_ev);
   }
   /* clean up display commit/event worker threads */
   for (i = 0; i < priv->num_crtcs; i++) {
     if (priv->disp_thread[i].thread) {
       kthread_flush_worker(&priv->disp_thread[i].worker);
       kthread_stop(priv->disp_thread[i].thread);
       priv->disp_thread[i].thread = NULL;
     }
     if (priv->event_thread[i].thread) {
       kthread_flush_worker(&priv->event_thread[i].worker);
       kthread_stop(priv->event_thread[i].thread);
       priv->event_thread[i].thread = NULL;
     }
   }
   msm_gem_shrinker_cleanup(ddev);
   drm_kms_helper_poll_fini(ddev);
   drm_dev_unregister(ddev);
   msm_perf_debugfs_cleanup(priv);
   msm_rd_debugfs_cleanup(priv);
 #ifdef CONFIG_DRM_FBDEV_EMULATION
   if (fbdev && priv->fbdev) msm_fbdev_free(ddev);
 #endif
   drm_mode_config_cleanup(ddev);
   pm_runtime_get_sync(dev);
   drm_irq_uninstall(ddev);
   pm_runtime_put_sync(dev);
   flush_workqueue(priv->wq);
   destroy_workqueue(priv->wq);
   if (kms && kms->funcs) kms->funcs->destroy(kms);
   if (priv->vram.paddr) {
     unsigned long attrs = DMA_ATTR_NO_KERNEL_MAPPING;
     drm_mm_takedown(&priv->vram.mm);
     dma_free_attrs(dev, priv->vram.size, NULL, priv->vram.paddr, attrs);
   }
   component_unbind_all(dev, ddev);
   if (mdss && mdss->funcs) mdss->funcs->destroy(ddev);
   ddev->dev_private = NULL;
-  drm_dev_unref(ddev);
+  drm_dev_put(ddev);
   kfree(priv);
   return 0;
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,15 +1,15 @@
 static int udl_usb_probe(struct usb_interface *interface, const struct usb_device_id *id) {
   struct usb_device *udev = interface_to_usbdev(interface);
   struct drm_device *dev;
   int r;
   dev = drm_dev_alloc(&driver, &interface->dev);
   if (IS_ERR(dev)) return PTR_ERR(dev);
   r = drm_dev_register(dev, (unsigned long)udev);
   if (r) goto err_free;
   usb_set_intfdata(interface, dev);
   DRM_INFO("Initialized udl on minor %d\n", dev->primary->index);
   return 0;
 err_free:
-  drm_dev_unref(dev);
+  drm_dev_put(dev);
   return r;
 }<sep>@@
expression ddev;
@@
-       drm_dev_unref(ddev);
+       drm_dev_put(ddev);
--- initial
+++ final
@@ -1,70 +1,67 @@
 static int altera_cvp_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id) {
   struct altera_cvp_conf *conf;
   struct fpga_manager *mgr;
   u16 cmd, val;
   int ret;
   /*
    * First check if this is the expected FPGA device. PCI config
    * space access works without enabling the PCI device, memory
    * space access is enabled further down.
    */
   pci_read_config_word(pdev, VSE_PCIE_EXT_CAP_ID, &val);
   if (val != VSE_PCIE_EXT_CAP_ID_VAL) {
     dev_err(&pdev->dev, "Wrong EXT_CAP_ID value 0x%x\n", val);
     return -ENODEV;
   }
   conf = devm_kzalloc(&pdev->dev, sizeof(*conf), GFP_KERNEL);
   if (!conf) return -ENOMEM;
   /*
    * Enable memory BAR access. We cannot use pci_enable_device() here
    * because it will make the driver unusable with FPGA devices that
    * have additional big IOMEM resources (e.g. 4GiB BARs) on 32-bit
    * platform. Such BARs will not have an assigned address range and
    * pci_enable_device() will fail, complaining about not claimed BAR,
    * even if the concerned BAR is not needed for FPGA configuration
    * at all. Thus, enable the device via PCI config space command.
    */
   pci_read_config_word(pdev, PCI_COMMAND, &cmd);
   if (!(cmd & PCI_COMMAND_MEMORY)) {
     cmd |= PCI_COMMAND_MEMORY;
     pci_write_config_word(pdev, PCI_COMMAND, cmd);
   }
   ret = pci_request_region(pdev, CVP_BAR, "CVP");
   if (ret) {
     dev_err(&pdev->dev, "Requesting CVP BAR region failed\n");
     goto err_disable;
   }
   conf->pci_dev = pdev;
   conf->write_data = altera_cvp_write_data_iomem;
   conf->map = pci_iomap(pdev, CVP_BAR, 0);
   if (!conf->map) {
     dev_warn(&pdev->dev, "Mapping CVP BAR failed\n");
     conf->write_data = altera_cvp_write_data_config;
   }
   snprintf(conf->mgr_name, sizeof(conf->mgr_name), "%s @%s", ALTERA_CVP_MGR_NAME, pci_name(pdev));
-  mgr = fpga_mgr_create(&pdev->dev, conf->mgr_name, &altera_cvp_ops, conf);
+  mgr = devm_fpga_mgr_create(&pdev->dev, conf->mgr_name, &altera_cvp_ops, conf);
   if (!mgr) {
     ret = -ENOMEM;
     goto err_unmap;
   }
   pci_set_drvdata(pdev, mgr);
   ret = fpga_mgr_register(mgr);
-  if (ret) {
-    fpga_mgr_free(mgr);
-    goto err_unmap;
-  }
+  if (ret) goto err_unmap;
   ret = driver_create_file(&altera_cvp_driver.driver, &driver_attr_chkcfg);
   if (ret) {
     dev_err(&pdev->dev, "Can't create sysfs chkcfg file\n");
     fpga_mgr_unregister(mgr);
     goto err_unmap;
   }
   return 0;
 err_unmap:
   pci_iounmap(pdev, conf->map);
   pci_release_region(pdev, CVP_BAR);
 err_disable:
   cmd &= ~PCI_COMMAND_MEMORY;
   pci_write_config_word(pdev, PCI_COMMAND, cmd);
   return ret;
 }<sep>@@
expression mgr,ret,e1,e2,e3,e4;
statement S;
@@

	mgr =
-           fpga_mgr_create
+           devm_fpga_mgr_create
		(e1,e2,e3,e4);
	... 
        ret = fpga_mgr_register(mgr);
        if (ret)
-       {
-               fpga_mgr_free(mgr);
		S
-	}
--- initial
+++ final
@@ -1,17 +1,14 @@
 int alt_pr_register(struct device *dev, void __iomem *reg_base) {
   struct alt_pr_priv *priv;
   struct fpga_manager *mgr;
-  int ret;
   u32 val;
   priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
   if (!priv) return -ENOMEM;
   priv->reg_base = reg_base;
   val = readl(priv->reg_base + ALT_PR_CSR_OFST);
   dev_dbg(dev, "%s status=%d start=%d\n", __func__, (val & ALT_PR_CSR_STATUS_MSK) >> ALT_PR_CSR_STATUS_SFT, (int)(val & ALT_PR_CSR_PR_START));
-  mgr = fpga_mgr_create(dev, dev_name(dev), &alt_pr_ops, priv);
+  mgr = devm_fpga_mgr_create(dev, dev_name(dev), &alt_pr_ops, priv);
   if (!mgr) return -ENOMEM;
   dev_set_drvdata(dev, mgr);
-  ret = fpga_mgr_register(mgr);
-  if (ret) fpga_mgr_free(mgr);
-  return ret;
+  return fpga_mgr_register(mgr);
 }<sep>@@
expression mgr,e1,e2,e3,e4;
identifier ret;
type T;
@@

(
-	T ret;
	...
	mgr =
-           fpga_mgr_create
+           devm_fpga_mgr_create
		(e1,e2,e3,e4);
	... when != ret
-       ret = fpga_mgr_register(mgr);
-       if (ret)
-               fpga_mgr_free(mgr);
-
-       return ret;
+       return fpga_mgr_register(mgr);
&
	T ret;
	... when != ret
	    when strict
?       ret = fpga_mgr_register(mgr);
)
--- initial
+++ final
@@ -1,32 +1,29 @@
 static int altera_ps_probe(struct spi_device *spi) {
   struct altera_ps_conf *conf;
   const struct of_device_id *of_id;
   struct fpga_manager *mgr;
-  int ret;
   conf = devm_kzalloc(&spi->dev, sizeof(*conf), GFP_KERNEL);
   if (!conf) return -ENOMEM;
   of_id = of_match_device(of_ef_match, &spi->dev);
   if (!of_id) return -ENODEV;
   conf->data = of_id->data;
   conf->spi = spi;
   conf->config = devm_gpiod_get(&spi->dev, "nconfig", GPIOD_OUT_LOW);
   if (IS_ERR(conf->config)) {
     dev_err(&spi->dev, "Failed to get config gpio: %ld\n", PTR_ERR(conf->config));
     return PTR_ERR(conf->config);
   }
   conf->status = devm_gpiod_get(&spi->dev, "nstat", GPIOD_IN);
   if (IS_ERR(conf->status)) {
     dev_err(&spi->dev, "Failed to get status gpio: %ld\n", PTR_ERR(conf->status));
     return PTR_ERR(conf->status);
   }
   conf->confd = devm_gpiod_get(&spi->dev, "confd", GPIOD_IN);
   if (IS_ERR(conf->confd)) { dev_warn(&spi->dev, "Not using confd gpio: %ld\n", PTR_ERR(conf->confd)); }
   /* Register manager with unique name */
   snprintf(conf->mgr_name, sizeof(conf->mgr_name), "%s %s", dev_driver_string(&spi->dev), dev_name(&spi->dev));
-  mgr = fpga_mgr_create(&spi->dev, conf->mgr_name, &altera_ps_ops, conf);
+  mgr = devm_fpga_mgr_create(&spi->dev, conf->mgr_name, &altera_ps_ops, conf);
   if (!mgr) return -ENOMEM;
   spi_set_drvdata(spi, mgr);
-  ret = fpga_mgr_register(mgr);
-  if (ret) fpga_mgr_free(mgr);
-  return ret;
+  return fpga_mgr_register(mgr);
 }<sep>@@
expression mgr,e1,e2,e3,e4;
identifier ret;
type T;
@@

(
-	T ret;
	...
	mgr =
-           fpga_mgr_create
+           devm_fpga_mgr_create
		(e1,e2,e3,e4);
	... when != ret
-       ret = fpga_mgr_register(mgr);
-       if (ret)
-               fpga_mgr_free(mgr);
-
-       return ret;
+       return fpga_mgr_register(mgr);
&
	T ret;
	... when != ret
	    when strict
?       ret = fpga_mgr_register(mgr);
)
--- initial
+++ final
@@ -1,27 +1,24 @@
 static int fme_mgr_probe(struct platform_device *pdev) {
   struct dfl_fme_mgr_pdata *pdata = dev_get_platdata(&pdev->dev);
   struct fpga_compat_id *compat_id;
   struct device *dev = &pdev->dev;
   struct fme_mgr_priv *priv;
   struct fpga_manager *mgr;
   struct resource *res;
-  int ret;
   priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
   if (!priv) return -ENOMEM;
   if (pdata->ioaddr) priv->ioaddr = pdata->ioaddr;
   if (!priv->ioaddr) {
     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
     priv->ioaddr = devm_ioremap_resource(dev, res);
     if (IS_ERR(priv->ioaddr)) return PTR_ERR(priv->ioaddr);
   }
   compat_id = devm_kzalloc(dev, sizeof(*compat_id), GFP_KERNEL);
   if (!compat_id) return -ENOMEM;
   fme_mgr_get_compat_id(priv->ioaddr, compat_id);
-  mgr = fpga_mgr_create(dev, "DFL FME FPGA Manager", &fme_mgr_ops, priv);
+  mgr = devm_fpga_mgr_create(dev, "DFL FME FPGA Manager", &fme_mgr_ops, priv);
   if (!mgr) return -ENOMEM;
   mgr->compat_id = compat_id;
   platform_set_drvdata(pdev, mgr);
-  ret = fpga_mgr_register(mgr);
-  if (ret) fpga_mgr_free(mgr);
-  return ret;
+  return fpga_mgr_register(mgr);
 }<sep>@@
expression mgr,e1,e2,e3,e4;
identifier ret;
type T;
@@

(
-	T ret;
	...
	mgr =
-           fpga_mgr_create
+           devm_fpga_mgr_create
		(e1,e2,e3,e4);
	... when != ret
-       ret = fpga_mgr_register(mgr);
-       if (ret)
-               fpga_mgr_free(mgr);
-
-       return ret;
+       return fpga_mgr_register(mgr);
&
	T ret;
	... when != ret
	    when strict
?       ret = fpga_mgr_register(mgr);
)