Skip to contentSkip to conversation

iio: amplifiers: ad8366: Use devm_* APIs

PATCH Applied Sachin Kamat 2 participants 6 messages Jul 30, 2013 – Aug 3, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 iio: amplifiers: ad8366: Use devm_* APIs

devm_* APIs are device managed and make code simpler.

Cc Michael Hennerich <[email protected]>

---
This series compile tested on togreg branch of
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git

---
 drivers/iio/amplifiers/ad8366.c |   13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/iio/amplifiers/ad8366.c +3 -10
index d354554..d0a79a4 100644
@@ -139,17 +139,17 @@ static int ad8366_probe(struct spi_device *spi)
 	struct ad8366_state *st;
 	int ret;
 
-	indio_dev = iio_device_alloc(sizeof(*st));
+	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
 	if (indio_dev == NULL)
 		return -ENOMEM;
 
 	st = iio_priv(indio_dev);
 
-	st->reg = regulator_get(&spi->dev, "vcc");
+	st->reg = devm_regulator_get(&spi->dev, "vcc");
 	if (!IS_ERR(st->reg)) {
 		ret = regulator_enable(st->reg);
 		if (ret)
-			goto error_put_reg;
+			return ret;
 	}
 
 	spi_set_drvdata(spi, indio_dev);
@@ -173,11 +173,6 @@ static int ad8366_probe(struct spi_device *spi)
 error_disable_reg:
 	if (!IS_ERR(st->reg))
 		regulator_disable(st->reg);
-error_put_reg:
-	if (!IS_ERR(st->reg))
-		regulator_put(st->reg);
-
-	iio_device_free(indio_dev);
 
 	return ret;
 }
@@ -195,8 +190,6 @@ static int ad8366_remove(struct spi_device *spi)
 		regulator_put(reg);
 	}
 
-	iio_device_free(indio_dev);
-
 	return 0;
 }
 
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 2/3 iio: frequency: ad9523: Use devm_* APIs

devm_* APIs are device managed and make code simpler.

Cc Michael Hennerich <[email protected]>
---
 drivers/iio/frequency/ad9523.c |   17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)
drivers/iio/frequency/ad9523.c +4 -13
index 92276de..7c5245d 100644
@@ -961,17 +961,17 @@ static int ad9523_probe(struct spi_device *spi)
 		return -EINVAL;
 	}
 
-	indio_dev = iio_device_alloc(sizeof(*st));
+	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
 	if (indio_dev == NULL)
 		return -ENOMEM;
 
 	st = iio_priv(indio_dev);
 
-	st->reg = regulator_get(&spi->dev, "vcc");
+	st->reg = devm_regulator_get(&spi->dev, "vcc");
 	if (!IS_ERR(st->reg)) {
 		ret = regulator_enable(st->reg);
 		if (ret)
-			goto error_put_reg;
+			return ret;
 	}
 
 	spi_set_drvdata(spi, indio_dev);
@@ -1001,11 +1001,6 @@ static int ad9523_probe(struct spi_device *spi)
 error_disable_reg:
 	if (!IS_ERR(st->reg))
 		regulator_disable(st->reg);
-error_put_reg:
-	if (!IS_ERR(st->reg))
-		regulator_put(st->reg);
-
-	iio_device_free(indio_dev);
 
 	return ret;
 }
@@ -1017,12 +1012,8 @@ static int ad9523_remove(struct spi_device *spi)
 
 	iio_device_unregister(indio_dev);
 
-	if (!IS_ERR(st->reg)) {
+	if (!IS_ERR(st->reg))
 		regulator_disable(st->reg);
-		regulator_put(st->reg);
-	}
-
-	iio_device_free(indio_dev);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
maintainer Applied
#2 lore raw

Re: [PATCH 2/3] iio: frequency: ad9523: Use devm_* APIs

Quoted 4 lines · Sachin Kamat

devm_* APIs are device managed and make code simpler.

Cc Michael Hennerich <[email protected]>

Applied to the togreg branch of iio.git

Thanks,

Quoted 56 lines
---
 drivers/iio/frequency/ad9523.c |   17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)
drivers/iio/frequency/ad9523.c +4 -13
index 92276de..7c5245d 100644
@@ -961,17 +961,17 @@ static int ad9523_probe(struct spi_device *spi)
 		return -EINVAL;
 	}
 
-	indio_dev = iio_device_alloc(sizeof(*st));
+	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
 	if (indio_dev == NULL)
 		return -ENOMEM;
 
 	st = iio_priv(indio_dev);
 
-	st->reg = regulator_get(&spi->dev, "vcc");
+	st->reg = devm_regulator_get(&spi->dev, "vcc");
 	if (!IS_ERR(st->reg)) {
 		ret = regulator_enable(st->reg);
 		if (ret)
-			goto error_put_reg;
+			return ret;
 	}
 
 	spi_set_drvdata(spi, indio_dev);
@@ -1001,11 +1001,6 @@ static int ad9523_probe(struct spi_device *spi)
 error_disable_reg:
 	if (!IS_ERR(st->reg))
 		regulator_disable(st->reg);
-error_put_reg:
-	if (!IS_ERR(st->reg))
-		regulator_put(st->reg);
-
-	iio_device_free(indio_dev);
 
 	return ret;
 }
@@ -1017,12 +1012,8 @@ static int ad9523_remove(struct spi_device *spi)
 
 	iio_device_unregister(indio_dev);
 
-	if (!IS_ERR(st->reg)) {
+	if (!IS_ERR(st->reg))
 		regulator_disable(st->reg);
-		regulator_put(st->reg);
-	}
-
-	iio_device_free(indio_dev);
 
 	return 0;
 }
#3 lore raw

PATCH 3/3 iio: pressure: st_pressure: Use devm_iio_device_alloc

In reply to Sachin Kamat

Using devm_iio_device_alloc makes code simpler.

---
 drivers/iio/pressure/st_pressure_core.c |    1 -
 drivers/iio/pressure/st_pressure_i2c.c  |   15 ++++-----------
 drivers/iio/pressure/st_pressure_spi.c  |   15 ++++-----------
 3 files changed, 8 insertions(+), 23 deletions(-)
drivers/iio/pressure/st_pressure_core.c +0 -1
index b8ecc87..093b045 100644
@@ -270,7 +270,6 @@ void st_press_common_remove(struct iio_dev *indio_dev)
 		st_sensors_deallocate_trigger(indio_dev);
 		st_press_deallocate_ring(indio_dev);
 	}
-	iio_device_free(indio_dev);
 }
 EXPORT_SYMBOL(st_press_common_remove);
 
drivers/iio/pressure/st_pressure_i2c.c +4 -11
index 3065993..08aac5e 100644
@@ -25,11 +25,9 @@ static int st_press_i2c_probe(struct i2c_client *client,
 	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(&client->dev, sizeof(*pdata));
+	if (!indio_dev)
+		return -ENOMEM;
 
 	pdata = iio_priv(indio_dev);
 	pdata->dev = &client->dev;
@@ -38,14 +36,9 @@ static int st_press_i2c_probe(struct i2c_client *client,
 
 	err = st_press_common_probe(indio_dev, client->dev.platform_data);
 	if (err < 0)
-		goto st_press_common_probe_error;
+		return err;
 
 	return 0;
-
-st_press_common_probe_error:
-	iio_device_free(indio_dev);
-iio_device_alloc_error:
-	return err;
 }
 
 static int st_press_i2c_remove(struct i2c_client *client)
drivers/iio/pressure/st_pressure_spi.c +4 -11
index b2aded6..399a29b 100644
@@ -24,11 +24,9 @@ static int st_press_spi_probe(struct spi_device *spi)
 	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(&spi->dev, sizeof(*pdata));
+	if (indio_dev == NULL)
+		return -ENOMEM;
 
 	pdata = iio_priv(indio_dev);
 	pdata->dev = &spi->dev;
@@ -37,14 +35,9 @@ static int st_press_spi_probe(struct spi_device *spi)
 
 	err = st_press_common_probe(indio_dev, spi->dev.platform_data);
 	if (err < 0)
-		goto st_press_common_probe_error;
+		return err;
 
 	return 0;
-
-st_press_common_probe_error:
-	iio_device_free(indio_dev);
-iio_device_alloc_error:
-	return err;
 }
 
 static int st_press_spi_remove(struct spi_device *spi)
Signature · 1 line
1.7.9.5
maintainer Applied
#4 lore raw

Re: [PATCH 3/3] iio: pressure: st_pressure: Use devm_iio_device_alloc

Quoted 4 lines · Sachin Kamat

Using devm_iio_device_alloc makes code simpler.

Applied to the togreg branch of iio.git

Thanks,

Quoted 89 lines
---
 drivers/iio/pressure/st_pressure_core.c |    1 -
 drivers/iio/pressure/st_pressure_i2c.c  |   15 ++++-----------
 drivers/iio/pressure/st_pressure_spi.c  |   15 ++++-----------
 3 files changed, 8 insertions(+), 23 deletions(-)
drivers/iio/pressure/st_pressure_core.c +0 -1
index b8ecc87..093b045 100644
@@ -270,7 +270,6 @@ void st_press_common_remove(struct iio_dev *indio_dev)
 		st_sensors_deallocate_trigger(indio_dev);
 		st_press_deallocate_ring(indio_dev);
 	}
-	iio_device_free(indio_dev);
 }
 EXPORT_SYMBOL(st_press_common_remove);
 
drivers/iio/pressure/st_pressure_i2c.c +4 -11
index 3065993..08aac5e 100644
@@ -25,11 +25,9 @@ static int st_press_i2c_probe(struct i2c_client *client,
 	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(&client->dev, sizeof(*pdata));
+	if (!indio_dev)
+		return -ENOMEM;
 
 	pdata = iio_priv(indio_dev);
 	pdata->dev = &client->dev;
@@ -38,14 +36,9 @@ static int st_press_i2c_probe(struct i2c_client *client,
 
 	err = st_press_common_probe(indio_dev, client->dev.platform_data);
 	if (err < 0)
-		goto st_press_common_probe_error;
+		return err;
 
 	return 0;
-
-st_press_common_probe_error:
-	iio_device_free(indio_dev);
-iio_device_alloc_error:
-	return err;
 }
 
 static int st_press_i2c_remove(struct i2c_client *client)
drivers/iio/pressure/st_pressure_spi.c +4 -11
index b2aded6..399a29b 100644
@@ -24,11 +24,9 @@ static int st_press_spi_probe(struct spi_device *spi)
 	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(&spi->dev, sizeof(*pdata));
+	if (indio_dev == NULL)
+		return -ENOMEM;
 
 	pdata = iio_priv(indio_dev);
 	pdata->dev = &spi->dev;
@@ -37,14 +35,9 @@ static int st_press_spi_probe(struct spi_device *spi)
 
 	err = st_press_common_probe(indio_dev, spi->dev.platform_data);
 	if (err < 0)
-		goto st_press_common_probe_error;
+		return err;
 
 	return 0;
-
-st_press_common_probe_error:
-	iio_device_free(indio_dev);
-iio_device_alloc_error:
-	return err;
 }
 
 static int st_press_spi_remove(struct spi_device *spi)
maintainer Applied
#5 lore raw
In reply to Sachin Kamat
Quoted 4 lines · Sachin Kamat

devm_* APIs are device managed and make code simpler.

Cc Michael Hennerich <[email protected]>

Applied to the togreg branch of iio.git

Thanks.

Quoted 54 lines

---
This series compile tested on togreg branch of
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git

---
 drivers/iio/amplifiers/ad8366.c |   13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/iio/amplifiers/ad8366.c +3 -10
index d354554..d0a79a4 100644
@@ -139,17 +139,17 @@ static int ad8366_probe(struct spi_device *spi)
 	struct ad8366_state *st;
 	int ret;
 
-	indio_dev = iio_device_alloc(sizeof(*st));
+	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
 	if (indio_dev == NULL)
 		return -ENOMEM;
 
 	st = iio_priv(indio_dev);
 
-	st->reg = regulator_get(&spi->dev, "vcc");
+	st->reg = devm_regulator_get(&spi->dev, "vcc");
 	if (!IS_ERR(st->reg)) {
 		ret = regulator_enable(st->reg);
 		if (ret)
-			goto error_put_reg;
+			return ret;
 	}
 
 	spi_set_drvdata(spi, indio_dev);
@@ -173,11 +173,6 @@ static int ad8366_probe(struct spi_device *spi)
 error_disable_reg:
 	if (!IS_ERR(st->reg))
 		regulator_disable(st->reg);
-error_put_reg:
-	if (!IS_ERR(st->reg))
-		regulator_put(st->reg);
-
-	iio_device_free(indio_dev);
 
 	return ret;
 }
@@ -195,8 +190,6 @@ static int ad8366_remove(struct spi_device *spi)
 		regulator_put(reg);
 	}
 
-	iio_device_free(indio_dev);
-
 	return 0;
 }