--- initial
+++ final
@@ -1,88 +1,86 @@
 static int exynos_adc_probe(struct platform_device *pdev) {
   struct exynos_adc *info = NULL;
   struct device_node *np = pdev->dev.of_node;
   struct iio_dev *indio_dev = NULL;
   struct resource *mem;
   int ret = -ENODEV;
   int irq;
   if (!np) return ret;
-  indio_dev = iio_device_alloc(sizeof(struct exynos_adc));
+  indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct exynos_adc));
   if (!indio_dev) {
     dev_err(&pdev->dev, "failed allocating iio device\n");
     return -ENOMEM;
   }
   info = iio_priv(indio_dev);
   mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   info->regs = devm_ioremap_resource(&pdev->dev, mem);
   if (IS_ERR(info->regs)) {
     ret = PTR_ERR(info->regs);
-    goto err_iio;
+    return ret;
   }
   mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
   info->enable_reg = devm_ioremap_resource(&pdev->dev, mem);
   if (IS_ERR(info->enable_reg)) {
     ret = PTR_ERR(info->enable_reg);
-    goto err_iio;
+    return ret;
   }
   irq = platform_get_irq(pdev, 0);
   if (irq < 0) {
     dev_err(&pdev->dev, "no irq resource?\n");
     ret = irq;
-    goto err_iio;
+    return ret;
   }
   info->irq = irq;
   init_completion(&info->completion);
   ret = request_irq(info->irq, exynos_adc_isr, 0, dev_name(&pdev->dev), info);
   if (ret < 0) {
     dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", info->irq);
-    goto err_iio;
+    return ret;
   }
   writel(1, info->enable_reg);
   info->clk = devm_clk_get(&pdev->dev, "adc");
   if (IS_ERR(info->clk)) {
     dev_err(&pdev->dev, "failed getting clock, err = %ld\n", PTR_ERR(info->clk));
     ret = PTR_ERR(info->clk);
     goto err_irq;
   }
   info->vdd = devm_regulator_get(&pdev->dev, "vdd");
   if (IS_ERR(info->vdd)) {
     dev_err(&pdev->dev, "failed getting regulator, err = %ld\n", PTR_ERR(info->vdd));
     ret = PTR_ERR(info->vdd);
     goto err_irq;
   }
   info->version = exynos_adc_get_version(pdev);
   platform_set_drvdata(pdev, indio_dev);
   indio_dev->name = dev_name(&pdev->dev);
   indio_dev->dev.parent = &pdev->dev;
   indio_dev->dev.of_node = pdev->dev.of_node;
   indio_dev->info = &exynos_adc_iio_info;
   indio_dev->modes = INDIO_DIRECT_MODE;
   indio_dev->channels = exynos_adc_iio_channels;
   if (info->version == ADC_V1)
     indio_dev->num_channels = MAX_ADC_V1_CHANNELS;
   else
     indio_dev->num_channels = MAX_ADC_V2_CHANNELS;
   ret = iio_device_register(indio_dev);
   if (ret) goto err_irq;
   ret = regulator_enable(info->vdd);
   if (ret) goto err_iio_dev;
   clk_prepare_enable(info->clk);
   exynos_adc_hw_init(info);
   ret = of_platform_populate(np, exynos_adc_match, NULL, &pdev->dev);
   if (ret < 0) {
     dev_err(&pdev->dev, "failed adding child nodes\n");
     goto err_of_populate;
   }
   return 0;
 err_of_populate:
   device_for_each_child(&pdev->dev, NULL, exynos_adc_remove_devices);
   regulator_disable(info->vdd);
   clk_disable_unprepare(info->clk);
 err_iio_dev:
   iio_device_unregister(indio_dev);
 err_irq:
   free_irq(info->irq, info);
-err_iio:
-  iio_device_free(indio_dev);
   return ret;
 }<sep>@@
expression e,e1,e2,ret;
identifier l1,x,f;
type T;
@@

f(T x) {
	...
(
-       e = iio_device_alloc(e1);
+       e = devm_iio_device_alloc(&x->dev, e1);
        if (e == NULL) {
	       ...
               return e2;
        }
<...
-	goto l1;
+	return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
-       iio_device_free(e);
        return ret;
)
}