imamnurby/smpl_train_seed8 huggingface dataset:
--- initial
+++ final
@@ -1,9 +1,9 @@
 static int intel_soc_pmic_find_gpio_irq(struct device *dev) {
   struct gpio_desc *desc;
   int irq;
-  desc = devm_gpiod_get_index(dev, "intel_soc_pmic", 0);
+  desc = devm_gpiod_get_index(dev, "intel_soc_pmic", 0, GPIOD_IN);
   if (IS_ERR(desc)) return PTR_ERR(desc);
   irq = gpiod_to_irq(desc);
   if (irq < 0) dev_warn(dev, "Can't get irq: %d\n", irq);
   return irq;
 }<sep>@@
expression e,e1,e2,e3,gpio;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
	e = gpiod_to_irq(gpio)
--- initial
+++ final
@@ -1,18 +1,16 @@
 static int bmc150_accel_gpio_probe(struct i2c_client *client, struct bmc150_accel_data *data) {
   struct device *dev;
   struct gpio_desc *gpio;
   int ret;
   if (!client) return -EINVAL;
   dev = &client->dev;
   /* data ready gpio interrupt pin */
-  gpio = devm_gpiod_get_index(dev, BMC150_ACCEL_GPIO_NAME, 0);
+  gpio = devm_gpiod_get_index(dev, BMC150_ACCEL_GPIO_NAME, 0, GPIOD_IN);
   if (IS_ERR(gpio)) {
     dev_err(dev, "Failed: gpio get index\n");
     return PTR_ERR(gpio);
   }
-  ret = gpiod_direction_input(gpio);
-  if (ret) return ret;
   ret = gpiod_to_irq(gpio);
   dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
   return ret;
 }<sep>@@
expression e1,e2,e3,gpio,ret;
statement S;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
-	ret = gpiod_direction_input(gpio);
-	if (\(ret\|ret < 0\)) S
--- initial
+++ final
@@ -1,18 +1,16 @@
 static int bmg160_gpio_probe(struct i2c_client *client, struct bmg160_data *data) {
   struct device *dev;
   struct gpio_desc *gpio;
   int ret;
   if (!client) return -EINVAL;
   dev = &client->dev;
   /* data ready gpio interrupt pin */
-  gpio = devm_gpiod_get_index(dev, BMG160_GPIO_NAME, 0);
+  gpio = devm_gpiod_get_index(dev, BMG160_GPIO_NAME, 0, GPIOD_IN);
   if (IS_ERR(gpio)) {
     dev_err(dev, "acpi gpio get index failed\n");
     return PTR_ERR(gpio);
   }
-  ret = gpiod_direction_input(gpio);
-  if (ret) return ret;
   ret = gpiod_to_irq(gpio);
   dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
   return ret;
 }<sep>@@
expression e1,e2,e3,gpio,ret;
statement S;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
-	ret = gpiod_direction_input(gpio);
-	if (\(ret\|ret < 0\)) S
--- initial
+++ final
@@ -1,18 +1,16 @@
 static int kmx61_gpio_probe(struct i2c_client *client, struct kmx61_data *data) {
   struct device *dev;
   struct gpio_desc *gpio;
   int ret;
   if (!client) return -EINVAL;
   dev = &client->dev;
   /* data ready gpio interrupt pin */
-  gpio = devm_gpiod_get_index(dev, KMX61_GPIO_NAME, 0);
+  gpio = devm_gpiod_get_index(dev, KMX61_GPIO_NAME, 0, GPIOD_IN);
   if (IS_ERR(gpio)) {
     dev_err(dev, "acpi gpio get index failed\n");
     return PTR_ERR(gpio);
   }
-  ret = gpiod_direction_input(gpio);
-  if (ret) return ret;
   ret = gpiod_to_irq(gpio);
   dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
   return ret;
 }<sep>@@
expression e1,e2,e3,gpio,ret;
statement S;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
-	ret = gpiod_direction_input(gpio);
-	if (\(ret\|ret < 0\)) S
--- initial
+++ final
@@ -1,19 +1,17 @@
 static int kxcjk1013_gpio_probe(struct i2c_client *client, struct kxcjk1013_data *data) {
   struct device *dev;
   struct gpio_desc *gpio;
   int ret;
   if (!client) return -EINVAL;
   if (data->is_smo8500_device) return -ENOTSUPP;
   dev = &client->dev;
   /* data ready gpio interrupt pin */
-  gpio = devm_gpiod_get_index(dev, "kxcjk1013_int", 0);
+  gpio = devm_gpiod_get_index(dev, "kxcjk1013_int", 0, GPIOD_IN);
   if (IS_ERR(gpio)) {
     dev_err(dev, "acpi gpio get index failed\n");
     return PTR_ERR(gpio);
   }
-  ret = gpiod_direction_input(gpio);
-  if (ret) return ret;
   ret = gpiod_to_irq(gpio);
   dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
   return ret;
 }<sep>@@
expression e1,e2,e3,gpio,ret;
statement S;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
-	ret = gpiod_direction_input(gpio);
-	if (\(ret\|ret < 0\)) S
--- initial
+++ final
@@ -1,23 +1,21 @@
 static int mma9551_gpio_probe(struct iio_dev *indio_dev) {
   struct gpio_desc *gpio;
   int i, ret;
   struct mma9551_data *data = iio_priv(indio_dev);
   struct device *dev = &data->client->dev;
   for (i = 0; i < MMA9551_GPIO_COUNT; i++) {
-    gpio = devm_gpiod_get_index(dev, MMA9551_GPIO_NAME, i);
+    gpio = devm_gpiod_get_index(dev, MMA9551_GPIO_NAME, i, GPIOD_IN);
     if (IS_ERR(gpio)) {
       dev_err(dev, "acpi gpio get index failed\n");
       return PTR_ERR(gpio);
     }
-    ret = gpiod_direction_input(gpio);
-    if (ret) return ret;
     data->irqs[i] = gpiod_to_irq(gpio);
     ret = devm_request_threaded_irq(dev, data->irqs[i], NULL, mma9551_event_handler, IRQF_TRIGGER_RISING | IRQF_ONESHOT, MMA9551_IRQ_NAME, indio_dev);
     if (ret < 0) {
       dev_err(dev, "request irq %d failed\n", data->irqs[i]);
       return ret;
     }
     dev_dbg(dev, "gpio resource, no:%d irq:%d\n", desc_to_gpio(gpio), data->irqs[i]);
   }
   return 0;
 }<sep>@@
expression e1,e2,e3,gpio,ret;
statement S;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
-	ret = gpiod_direction_input(gpio);
-	if (\(ret\|ret < 0\)) S
--- initial
+++ final
@@ -1,18 +1,16 @@
 static int mma9553_gpio_probe(struct i2c_client *client) {
   struct device *dev;
   struct gpio_desc *gpio;
   int ret;
   if (!client) return -EINVAL;
   dev = &client->dev;
   /* data ready gpio interrupt pin */
-  gpio = devm_gpiod_get_index(dev, MMA9553_GPIO_NAME, 0);
+  gpio = devm_gpiod_get_index(dev, MMA9553_GPIO_NAME, 0, GPIOD_IN);
   if (IS_ERR(gpio)) {
     dev_err(dev, "acpi gpio get index failed\n");
     return PTR_ERR(gpio);
   }
-  ret = gpiod_direction_input(gpio);
-  if (ret) return ret;
   ret = gpiod_to_irq(gpio);
   dev_dbg(dev, "gpio resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
   return ret;
 }<sep>@@
expression e1,e2,e3,gpio,ret;
statement S;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
-	ret = gpiod_direction_input(gpio);
-	if (\(ret\|ret < 0\)) S
--- initial
+++ final
@@ -1,18 +1,16 @@
 static int sx9500_gpio_probe(struct i2c_client *client, struct sx9500_data *data) {
   struct device *dev;
   struct gpio_desc *gpio;
   int ret;
   if (!client) return -EINVAL;
   dev = &client->dev;
   /* data ready gpio interrupt pin */
-  gpio = devm_gpiod_get_index(dev, SX9500_GPIO_NAME, 0);
+  gpio = devm_gpiod_get_index(dev, SX9500_GPIO_NAME, 0, GPIOD_IN);
   if (IS_ERR(gpio)) {
     dev_err(dev, "acpi gpio get index failed\n");
     return PTR_ERR(gpio);
   }
-  ret = gpiod_direction_input(gpio);
-  if (ret) return ret;
   ret = gpiod_to_irq(gpio);
   dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
   return ret;
 }<sep>@@
expression e1,e2,e3,gpio,ret;
statement S;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
-	ret = gpiod_direction_input(gpio);
-	if (\(ret\|ret < 0\)) S
--- initial
+++ final
@@ -1,43 +1,43 @@
 static int usb_extcon_probe(struct platform_device *pdev) {
   struct device *dev = &pdev->dev;
   struct device_node *np = dev->of_node;
   struct usb_extcon_info *info;
   int ret;
   if (!np) return -EINVAL;
   info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
   if (!info) return -ENOMEM;
   info->dev = dev;
-  info->id_gpiod = devm_gpiod_get(&pdev->dev, "id");
+  info->id_gpiod = devm_gpiod_get(&pdev->dev, "id", GPIOD_IN);
   if (IS_ERR(info->id_gpiod)) {
     dev_err(dev, "failed to get ID GPIO\n");
     return PTR_ERR(info->id_gpiod);
   }
   info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable);
   if (IS_ERR(info->edev)) {
     dev_err(dev, "failed to allocate extcon device\n");
     return -ENOMEM;
   }
   ret = devm_extcon_dev_register(dev, info->edev);
   if (ret < 0) {
     dev_err(dev, "failed to register extcon device\n");
     return ret;
   }
   ret = gpiod_set_debounce(info->id_gpiod, USB_GPIO_DEBOUNCE_MS * 1000);
   if (ret < 0) info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS);
   INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable);
   info->id_irq = gpiod_to_irq(info->id_gpiod);
   if (info->id_irq < 0) {
     dev_err(dev, "failed to get ID IRQ\n");
     return info->id_irq;
   }
   ret = devm_request_threaded_irq(dev, info->id_irq, NULL, usb_irq_handler, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, pdev->name, info);
   if (ret < 0) {
     dev_err(dev, "failed to request handler for ID IRQ\n");
     return ret;
   }
   platform_set_drvdata(pdev, info);
   device_init_wakeup(dev, 1);
   /* Perform initial detection */
   usb_extcon_detect_cable(&info->wq_detcable.work);
   return 0;
 }<sep>@@
expression e,e1,e2,gpio;
@@

-	gpio = devm_gpiod_get(e1, e2);
+	gpio = devm_gpiod_get(e1, e2, GPIOD_IN);
	...
	e = gpiod_to_irq(gpio)
--- initial
+++ final
@@ -1,23 +1,20 @@
 static int nxp_nci_i2c_acpi_config(struct nxp_nci_i2c_phy *phy) {
   struct i2c_client *client = phy->i2c_dev;
   struct gpio_desc *gpiod_en, *gpiod_fw, *gpiod_irq;
-  gpiod_en = devm_gpiod_get_index(&client->dev, NULL, 2);
-  gpiod_fw = devm_gpiod_get_index(&client->dev, NULL, 1);
-  gpiod_irq = devm_gpiod_get_index(&client->dev, NULL, 0);
+  gpiod_en = devm_gpiod_get_index(&client->dev, NULL, 2, GPIOD_OUT_LOW);
+  gpiod_fw = devm_gpiod_get_index(&client->dev, NULL, 1, GPIOD_OUT_LOW);
+  gpiod_irq = devm_gpiod_get_index(&client->dev, NULL, 0, GPIOD_IN);
   if (IS_ERR(gpiod_en) || IS_ERR(gpiod_fw) || IS_ERR(gpiod_irq)) {
     nfc_err(&client->dev, "No GPIOs\n");
     return -EINVAL;
   }
-  gpiod_direction_output(gpiod_en, 0);
-  gpiod_direction_output(gpiod_fw, 0);
-  gpiod_direction_input(gpiod_irq);
   client->irq = gpiod_to_irq(gpiod_irq);
   if (client->irq < 0) {
     nfc_err(&client->dev, "No IRQ\n");
     return -EINVAL;
   }
   phy->gpio_en = desc_to_gpio(gpiod_en);
   phy->gpio_fw = desc_to_gpio(gpiod_fw);
   phy->gpio_irq = desc_to_gpio(gpiod_irq);
   return 0;
 }<sep>@@
expression e1,e2,e3,gpio;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
-	gpiod_direction_input(gpio);

@@
expression e1,e2,e3,gpio;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_OUT_LOW);
	...
-	gpiod_direction_output(gpio, 0);
--- initial
+++ final
@@ -1,18 +1,16 @@
 static int stk3310_gpio_probe(struct i2c_client *client) {
   struct device *dev;
   struct gpio_desc *gpio;
   int ret;
   if (!client) return -EINVAL;
   dev = &client->dev;
   /* gpio interrupt pin */
-  gpio = devm_gpiod_get_index(dev, STK3310_GPIO, 0);
+  gpio = devm_gpiod_get_index(dev, STK3310_GPIO, 0, GPIOD_IN);
   if (IS_ERR(gpio)) {
     dev_err(dev, "acpi gpio get index failed\n");
     return PTR_ERR(gpio);
   }
-  ret = gpiod_direction_input(gpio);
-  if (ret) return ret;
   ret = gpiod_to_irq(gpio);
   dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
   return ret;
 }<sep>@@
expression e1,e2,e3,gpio,ret;
statement S;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
-	ret = gpiod_direction_input(gpio);
-	if (\(ret\|ret < 0\)) S
--- initial
+++ final
@@ -1,18 +1,16 @@
 static int bmc150_magn_gpio_probe(struct i2c_client *client) {
   struct device *dev;
   struct gpio_desc *gpio;
   int ret;
   if (!client) return -EINVAL;
   dev = &client->dev;
   /* data ready GPIO interrupt pin */
-  gpio = devm_gpiod_get_index(dev, BMC150_MAGN_GPIO_INT, 0);
+  gpio = devm_gpiod_get_index(dev, BMC150_MAGN_GPIO_INT, 0, GPIOD_IN);
   if (IS_ERR(gpio)) {
     dev_err(dev, "ACPI GPIO get index failed\n");
     return PTR_ERR(gpio);
   }
-  ret = gpiod_direction_input(gpio);
-  if (ret) return ret;
   ret = gpiod_to_irq(gpio);
   dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
   return ret;
 }<sep>@@
expression e1,e2,e3,gpio,ret;
statement S;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
-	ret = gpiod_direction_input(gpio);
-	if (\(ret\|ret < 0\)) S
--- initial
+++ final
@@ -1,12 +1,9 @@
 static int bq25890_irq_probe(struct bq25890_device *bq) {
-  int ret;
   struct gpio_desc *irq;
-  irq = devm_gpiod_get_index(bq->dev, BQ25890_IRQ_PIN, 0);
+  irq = devm_gpiod_get_index(bq->dev, BQ25890_IRQ_PIN, 0, GPIOD_IN);
   if (IS_ERR(irq)) {
     dev_err(bq->dev, "Could not probe irq pin.\n");
     return PTR_ERR(irq);
   }
-  ret = gpiod_direction_input(irq);
-  if (ret < 0) return ret;
   return gpiod_to_irq(irq);
 }<sep>@@
expression e1,e2,e3,gpio,ret;
statement S;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
-	ret = gpiod_direction_input(gpio);
-	if (\(ret\|ret < 0\)) S

@@
identifier ret;
@@

(
- int ret;
  ... when exists
  devm_gpiod_get_index(...)
  ... when any
&
  int ret;
  ... when != ret
      when strict
)
--- initial
+++ final
@@ -1,12 +1,9 @@
 static int bq24257_irq_probe(struct bq24257_device *bq) {
-  int ret;
   struct gpio_desc *stat_irq;
-  stat_irq = devm_gpiod_get_index(bq->dev, BQ24257_STAT_IRQ, 0);
+  stat_irq = devm_gpiod_get_index(bq->dev, BQ24257_STAT_IRQ, 0, GPIOD_IN);
   if (IS_ERR(stat_irq)) {
     dev_err(bq->dev, "could not probe stat_irq pin\n");
     return PTR_ERR(stat_irq);
   }
-  ret = gpiod_direction_input(stat_irq);
-  if (ret < 0) return ret;
   return gpiod_to_irq(stat_irq);
 }<sep>@@
expression e1,e2,e3,gpio,ret;
statement S;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
-	ret = gpiod_direction_input(gpio);
-	if (\(ret\|ret < 0\)) S

@@
identifier ret;
@@

(
- int ret;
  ... when exists
  devm_gpiod_get_index(...)
  ... when any
&
  int ret;
  ... when != ret
      when strict
)
--- initial
+++ final
@@ -1,8 +1,8 @@
 static int bq24257_pg_gpio_probe(struct bq24257_device *bq) {
-  bq->pg = devm_gpiod_get_index(bq->dev, BQ24257_PG_GPIO, 0);
+  bq->pg = devm_gpiod_get_index(bq->dev, BQ24257_PG_GPIO, 0, GPIOD_IN);
   if (IS_ERR(bq->pg)) {
     dev_err(bq->dev, "could not probe PG pin\n");
     return PTR_ERR(bq->pg);
   }
-  return gpiod_direction_input(bq->pg);
+  return 0;
 }<sep>@@
expression e1,e2,e3,gpio;
@@

-	gpio = devm_gpiod_get_index(e1, e2, e3);
+	gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
	...
-	return gpiod_direction_input(gpio);
+	return 0;
--- initial
+++ final
@@ -1,30 +1,20 @@
 static int edp_gpio_config(struct edp_ctrl *ctrl) {
   struct device *dev = &ctrl->pdev->dev;
   int ret;
-  ctrl->panel_hpd_gpio = devm_gpiod_get(dev, "panel-hpd");
+  ctrl->panel_hpd_gpio = devm_gpiod_get(dev, "panel-hpd", GPIOD_IN);
   if (IS_ERR(ctrl->panel_hpd_gpio)) {
     ret = PTR_ERR(ctrl->panel_hpd_gpio);
     ctrl->panel_hpd_gpio = NULL;
     pr_err("%s: cannot get panel-hpd-gpios, %d\n", __func__, ret);
     return ret;
   }
-  ret = gpiod_direction_input(ctrl->panel_hpd_gpio);
-  if (ret) {
-    pr_err("%s: Set direction for hpd failed, %d\n", __func__, ret);
-    return ret;
-  }
-  ctrl->panel_en_gpio = devm_gpiod_get(dev, "panel-en");
+  ctrl->panel_en_gpio = devm_gpiod_get(dev, "panel-en", GPIOD_OUT_LOW);
   if (IS_ERR(ctrl->panel_en_gpio)) {
     ret = PTR_ERR(ctrl->panel_en_gpio);
     ctrl->panel_en_gpio = NULL;
     pr_err("%s: cannot get panel-en-gpios, %d\n", __func__, ret);
     return ret;
   }
-  ret = gpiod_direction_output(ctrl->panel_en_gpio, 0);
-  if (ret) {
-    pr_err("%s: Set direction for panel_en failed, %d\n", __func__, ret);
-    return ret;
-  }
   DBG("gpio on");
   return 0;
 }<sep>@@
expression e1,e2,gpio,ret;
statement S;
@@

-	gpio = devm_gpiod_get(e1, e2);
+	gpio = devm_gpiod_get(e1, e2, GPIOD_IN);
	...
-	ret = gpiod_direction_input(gpio);
-	if (\(ret\|ret < 0\)) S

@@
expression e1,e2,gpio,ret;
statement S;
@@

-	gpio = devm_gpiod_get(e1, e2);
+	gpio = devm_gpiod_get(e1, e2, GPIOD_OUT_LOW);
	...
-	ret = gpiod_direction_output(gpio, 0);
-	if (\(ret\|ret < 0\)) S
--- initial
+++ final
@@ -1,30 +1,24 @@
 static int kxsd9_probe(struct spi_device *spi) {
   struct iio_dev *indio_dev;
   struct kxsd9_state *st;
   int ret;
-  indio_dev = iio_device_alloc(sizeof(*st));
-  if (indio_dev == NULL) {
-    ret = -ENOMEM;
-    goto error_ret;
-  }
+  indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+  if (indio_dev == NULL) return -ENOMEM;
   st = iio_priv(indio_dev);
   spi_set_drvdata(spi, indio_dev);
   st->us = spi;
   mutex_init(&st->buf_lock);
   indio_dev->channels = kxsd9_channels;
   indio_dev->num_channels = ARRAY_SIZE(kxsd9_channels);
   indio_dev->name = spi_get_device_id(spi)->name;
   indio_dev->dev.parent = &spi->dev;
   indio_dev->info = &kxsd9_info;
   indio_dev->modes = INDIO_DIRECT_MODE;
   spi->mode = SPI_MODE_0;
   spi_setup(spi);
   kxsd9_power_up(st);
   ret = iio_device_register(indio_dev);
-  if (ret) goto error_free_dev;
+  if (ret) return ret;
   return 0;
-error_free_dev:
-  iio_device_free(indio_dev);
-error_ret:
   return ret;
 }<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
	... when != l2
(
-       e = iio_device_alloc(e1);
+       e = devm_iio_device_alloc(dev, e1);
        if (e == NULL)
(
-	{
-               ret = e2;
-               goto l2;
+               return e2;
-       }
|
	{
		...
-               ret = e2;
		...
-               goto l2;
+               return e2;
       }
)
<...
-	goto l1;
+	return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
-       iio_device_free(e);
-l2:
        return ret;
)
}
--- initial
+++ final
@@ -1,20 +1,14 @@
 static int st_accel_spi_probe(struct spi_device *spi) {
   struct iio_dev *indio_dev;
   struct st_sensor_data *adata;
   int err;
-  indio_dev = iio_device_alloc(sizeof(*adata));
-  if (indio_dev == NULL) {
-    err = -ENOMEM;
-    goto iio_device_alloc_error;
-  }
+  indio_dev = devm_iio_device_alloc(dev, sizeof(*adata));
+  if (indio_dev == NULL) return -ENOMEM;
   adata = iio_priv(indio_dev);
   adata->dev = &spi->dev;
   st_sensors_spi_configure(indio_dev, spi, adata);
   err = st_accel_common_probe(indio_dev, spi->dev.platform_data);
-  if (err < 0) goto st_accel_common_probe_error;
+  if (err < 0) return err;
   return 0;
-st_accel_common_probe_error:
-  iio_device_free(indio_dev);
-iio_device_alloc_error:
   return err;
 }<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
	... when != l2
(
-       e = iio_device_alloc(e1);
+       e = devm_iio_device_alloc(dev, e1);
        if (e == NULL)
(
-	{
-               ret = e2;
-               goto l2;
+               return e2;
-       }
|
	{
		...
-               ret = e2;
		...
-               goto l2;
+               return e2;
       }
)
<...
-	goto l1;
+	return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
-       iio_device_free(e);
-l2:
        return ret;
)
}
--- initial
+++ final
@@ -1,44 +1,40 @@
 static int tiadc_probe(struct platform_device *pdev) {
   struct iio_dev *indio_dev;
   struct tiadc_device *adc_dev;
   struct device_node *node = pdev->dev.of_node;
   struct property *prop;
   const __be32 *cur;
   int err;
   u32 val;
   int channels = 0;
   if (!node) {
     dev_err(&pdev->dev, "Could not find valid DT data.\n");
     return -EINVAL;
   }
-  indio_dev = iio_device_alloc(sizeof(struct tiadc_device));
+  indio_dev = devm_iio_device_alloc(dev, sizeof(struct tiadc_device));
   if (indio_dev == NULL) {
     dev_err(&pdev->dev, "failed to allocate iio device\n");
-    err = -ENOMEM;
-    goto err_ret;
+    return -ENOMEM;
   }
   adc_dev = iio_priv(indio_dev);
   adc_dev->mfd_tscadc = ti_tscadc_dev_get(pdev);
   of_property_for_each_u32(node, "ti,adc-channels", prop, cur, val) {
     adc_dev->channel_line[channels] = val;
     channels++;
   }
   adc_dev->channels = channels;
   indio_dev->dev.parent = &pdev->dev;
   indio_dev->name = dev_name(&pdev->dev);
   indio_dev->modes = INDIO_DIRECT_MODE;
   indio_dev->info = &tiadc_info;
   tiadc_step_config(adc_dev);
   err = tiadc_channel_init(indio_dev, adc_dev->channels);
-  if (err < 0) goto err_free_device;
+  if (err < 0) return err;
   err = iio_device_register(indio_dev);
   if (err) goto err_free_channels;
   platform_set_drvdata(pdev, indio_dev);
   return 0;
 err_free_channels:
   tiadc_channels_remove(indio_dev);
-err_free_device:
-  iio_device_free(indio_dev);
-err_ret:
   return err;
 }<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
	... when != l2
(
-       e = iio_device_alloc(e1);
+       e = devm_iio_device_alloc(dev, e1);
        if (e == NULL)
(
-	{
-               ret = e2;
-               goto l2;
+               return e2;
-       }
|
	{
		...
-               ret = e2;
		...
-               goto l2;
+               return e2;
       }
)
<...
-	goto l1;
+	return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
-       iio_device_free(e);
-l2:
        return ret;
)
}
--- initial
+++ final
@@ -1,30 +1,28 @@
 static int vprbrd_adc_probe(struct platform_device *pdev) {
   struct vprbrd *vb = dev_get_drvdata(pdev->dev.parent);
   struct vprbrd_adc *adc;
   struct iio_dev *indio_dev;
   int ret;
   /* registering iio */
-  indio_dev = iio_device_alloc(sizeof(*adc));
+  indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc));
   if (!indio_dev) {
     dev_err(&pdev->dev, "failed allocating iio device\n");
     return -ENOMEM;
   }
   adc = iio_priv(indio_dev);
   adc->vb = vb;
   indio_dev->name = "viperboard adc";
   indio_dev->dev.parent = &pdev->dev;
   indio_dev->info = &vprbrd_adc_iio_info;
   indio_dev->modes = INDIO_DIRECT_MODE;
   indio_dev->channels = vprbrd_adc_iio_channels;
   indio_dev->num_channels = ARRAY_SIZE(vprbrd_adc_iio_channels);
   ret = iio_device_register(indio_dev);
   if (ret) {
     dev_err(&pdev->dev, "could not register iio (adc)");
-    goto error;
+    return ret;
   }
   platform_set_drvdata(pdev, indio_dev);
   return 0;
-error:
-  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;
)
}
--- initial
+++ final
@@ -1,20 +1,14 @@
 static int st_press_spi_probe(struct spi_device *spi) {
   struct iio_dev *indio_dev;
   struct st_sensor_data *pdata;
   int err;
-  indio_dev = iio_device_alloc(sizeof(*pdata));
-  if (indio_dev == NULL) {
-    err = -ENOMEM;
-    goto iio_device_alloc_error;
-  }
+  indio_dev = devm_iio_device_alloc(dev, sizeof(*pdata));
+  if (indio_dev == NULL) return -ENOMEM;
   pdata = iio_priv(indio_dev);
   pdata->dev = &spi->dev;
   st_sensors_spi_configure(indio_dev, spi, pdata);
   err = st_press_common_probe(indio_dev, spi->dev.platform_data);
-  if (err < 0) goto st_press_common_probe_error;
+  if (err < 0) return err;
   return 0;
-st_press_common_probe_error:
-  iio_device_free(indio_dev);
-iio_device_alloc_error:
   return err;
 }<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
	... when != l2
(
-       e = iio_device_alloc(e1);
+       e = devm_iio_device_alloc(dev, e1);
        if (e == NULL)
(
-	{
-               ret = e2;
-               goto l2;
+               return e2;
-       }
|
	{
		...
-               ret = e2;
		...
-               goto l2;
+               return e2;
       }
)
<...
-	goto l1;
+	return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
-       iio_device_free(e);
-l2:
        return ret;
)
}