--- initial
+++ final
@@ -1,84 +1,82 @@
 static int mxs_lradc_probe(struct platform_device *pdev) {
   const struct of_device_id *of_id = of_match_device(mxs_lradc_dt_ids, &pdev->dev);
   const struct mxs_lradc_of_config *of_cfg = &mxs_lradc_of_config[(enum mxs_lradc_id)of_id->data];
   struct device *dev = &pdev->dev;
   struct device_node *node = dev->of_node;
   struct mxs_lradc *lradc;
   struct iio_dev *iio;
   struct resource *iores;
   uint32_t ts_wires = 0;
   int ret = 0;
   int i;
   /* Allocate the IIO device. */
-  iio = iio_device_alloc(sizeof(*lradc));
+  iio = devm_iio_device_alloc(dev, sizeof(*lradc));
   if (!iio) {
     dev_err(dev, "Failed to allocate IIO device\n");
     return -ENOMEM;
   }
   lradc = iio_priv(iio);
   /* Grab the memory area */
   iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
   lradc->dev = &pdev->dev;
   lradc->base = devm_ioremap_resource(dev, iores);
   if (IS_ERR(lradc->base)) {
     ret = PTR_ERR(lradc->base);
-    goto err_addr;
+    return ret;
   }
   INIT_WORK(&lradc->ts_work, mxs_lradc_ts_work);
   /* Check if touchscreen is enabled in DT. */
   ret = of_property_read_u32(node, "fsl,lradc-touchscreen-wires", &ts_wires);
   if (ret)
     dev_info(dev, "Touchscreen not enabled.\n");
   else if (ts_wires == 4)
     lradc->use_touchscreen = MXS_LRADC_TOUCHSCREEN_4WIRE;
   else if (ts_wires == 5)
     lradc->use_touchscreen = MXS_LRADC_TOUCHSCREEN_5WIRE;
   else
     dev_warn(dev, "Unsupported number of touchscreen wires (%d)\n", ts_wires);
   /* Grab all IRQ sources */
   for (i = 0; i < of_cfg->irq_count; i++) {
     lradc->irq[i] = platform_get_irq(pdev, i);
     if (lradc->irq[i] < 0) {
       ret = -EINVAL;
-      goto err_addr;
+      return ret;
     }
     ret = devm_request_irq(dev, lradc->irq[i], mxs_lradc_handle_irq, 0, of_cfg->irq_name[i], iio);
-    if (ret) goto err_addr;
+    if (ret) return ret;
   }
   platform_set_drvdata(pdev, iio);
   init_completion(&lradc->completion);
   mutex_init(&lradc->lock);
   iio->name = pdev->name;
   iio->dev.parent = &pdev->dev;
   iio->info = &mxs_lradc_iio_info;
   iio->modes = INDIO_DIRECT_MODE;
   iio->channels = mxs_lradc_chan_spec;
   iio->num_channels = ARRAY_SIZE(mxs_lradc_chan_spec);
   iio->masklength = LRADC_MAX_TOTAL_CHANS;
   ret = iio_triggered_buffer_setup(iio, &iio_pollfunc_store_time, &mxs_lradc_trigger_handler, &mxs_lradc_buffer_ops);
-  if (ret) goto err_addr;
+  if (ret) return ret;
   ret = mxs_lradc_trigger_init(iio);
   if (ret) goto err_trig;
   /* Configure the hardware. */
   ret = mxs_lradc_hw_init(lradc);
   if (ret) goto err_dev;
   /* Register the touchscreen input device. */
   ret = mxs_lradc_ts_register(lradc);
   if (ret) goto err_dev;
   /* Register IIO device. */
   ret = iio_device_register(iio);
   if (ret) {
     dev_err(dev, "Failed to register IIO device\n");
     goto err_ts;
   }
   return 0;
 err_ts:
   mxs_lradc_ts_unregister(lradc);
 err_dev:
   mxs_lradc_trigger_remove(iio);
 err_trig:
   iio_triggered_buffer_cleanup(iio);
-err_addr:
-  iio_device_free(iio);
   return ret;
 }<sep>@@
expression e,e1,e2,ret;
identifier l1,dev;
@@

	struct device *dev;
	...
(
-       e = iio_device_alloc(e1);
+       e = devm_iio_device_alloc(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;
)