* [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs
@ 2013-08-31 17:12 Sachin Kamat
2013-08-31 17:12 ` [PATCH 2/9] staging: iio: ad7280a: Use devm_iio_device_alloc Sachin Kamat
` (8 more replies)
0 siblings, 9 replies; 12+ messages in thread
From: Sachin Kamat @ 2013-08-31 17:12 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, lars, sachin.kamat
devm_* APIs are device managed and make code simpler.
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
This series is compile tested and based on togreg branch
of iio tree.
---
drivers/staging/iio/adc/ad7192.c | 15 ++++-----------
1 files changed, 4 insertions(+), 11 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index 3283e28..83bb44b 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -623,17 +623,17 @@ static int ad7192_probe(struct spi_device *spi)
return -ENODEV;
}
- 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;
voltage_uv = regulator_get_voltage(st->reg);
}
@@ -677,11 +677,6 @@ error_remove_trigger:
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;
}
@@ -694,10 +689,8 @@ static int ad7192_remove(struct spi_device *spi)
iio_device_unregister(indio_dev);
ad_sd_cleanup_buffer_and_trigger(indio_dev);
- if (!IS_ERR(st->reg)) {
+ if (!IS_ERR(st->reg))
regulator_disable(st->reg);
- regulator_put(st->reg);
- }
return 0;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/9] staging: iio: ad7280a: Use devm_iio_device_alloc
2013-08-31 17:12 [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs Sachin Kamat
@ 2013-08-31 17:12 ` Sachin Kamat
2013-08-31 17:12 ` [PATCH 3/9] staging: iio: ad7291: Use devm_* APIs Sachin Kamat
` (7 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Sachin Kamat @ 2013-08-31 17:12 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, lars, sachin.kamat
devm_iio_device_alloc makes code simpler.
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
drivers/staging/iio/adc/ad7280a.c | 11 ++++-------
1 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
index c19618b..e7191e4 100644
--- a/drivers/staging/iio/adc/ad7280a.c
+++ b/drivers/staging/iio/adc/ad7280a.c
@@ -835,8 +835,9 @@ static int ad7280_probe(struct spi_device *spi)
int ret;
const unsigned short tACQ_ns[4] = {465, 1010, 1460, 1890};
const unsigned short nAVG[4] = {1, 2, 4, 8};
- struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
+ struct iio_dev *indio_dev;
+ indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
if (indio_dev == NULL)
return -ENOMEM;
@@ -860,7 +861,7 @@ static int ad7280_probe(struct spi_device *spi)
ret = ad7280_chain_setup(st);
if (ret < 0)
- goto error_free_device;
+ return ret;
st->slave_num = ret;
st->scan_cnt = (st->slave_num + 1) * AD7280A_NUM_CH;
@@ -891,7 +892,7 @@ static int ad7280_probe(struct spi_device *spi)
ret = ad7280_channel_init(st);
if (ret < 0)
- goto error_free_device;
+ return ret;
indio_dev->num_channels = ret;
indio_dev->channels = st->channels;
@@ -940,9 +941,6 @@ error_free_attr:
error_free_channels:
kfree(st->channels);
-error_free_device:
- iio_device_free(indio_dev);
-
return ret;
}
@@ -960,7 +958,6 @@ static int ad7280_remove(struct spi_device *spi)
kfree(st->channels);
kfree(st->iio_attr);
- iio_device_free(indio_dev);
return 0;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/9] staging: iio: ad7291: Use devm_* APIs
2013-08-31 17:12 [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs Sachin Kamat
2013-08-31 17:12 ` [PATCH 2/9] staging: iio: ad7280a: Use devm_iio_device_alloc Sachin Kamat
@ 2013-08-31 17:12 ` Sachin Kamat
2013-08-31 17:12 ` [PATCH 4/9] staging: iio: ad7606_core: " Sachin Kamat
` (6 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Sachin Kamat @ 2013-08-31 17:12 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, lars, sachin.kamat
devm_* APIs are device managed and make code simpler.
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
drivers/staging/iio/adc/ad7291.c | 27 ++++++++-------------------
1 files changed, 8 insertions(+), 19 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
index a2e61c2..1dae1ef 100644
--- a/drivers/staging/iio/adc/ad7291.c
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -528,21 +528,19 @@ static int ad7291_probe(struct i2c_client *client,
struct iio_dev *indio_dev;
int ret = 0;
- indio_dev = iio_device_alloc(sizeof(*chip));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip));
+ if (!indio_dev)
+ return -ENOMEM;
chip = iio_priv(indio_dev);
if (pdata && pdata->use_external_ref) {
- chip->reg = regulator_get(&client->dev, "vref");
+ chip->reg = devm_regulator_get(&client->dev, "vref");
if (IS_ERR(chip->reg))
- goto error_free;
+ return ret;
ret = regulator_enable(chip->reg);
if (ret)
- goto error_put_reg;
+ return ret;
}
mutex_init(&chip->state_lock);
@@ -601,12 +599,7 @@ error_unreg_irq:
error_disable_reg:
if (chip->reg)
regulator_disable(chip->reg);
-error_put_reg:
- if (chip->reg)
- regulator_put(chip->reg);
-error_free:
- iio_device_free(indio_dev);
-error_ret:
+
return ret;
}
@@ -620,12 +613,8 @@ static int ad7291_remove(struct i2c_client *client)
if (client->irq)
free_irq(client->irq, indio_dev);
- if (chip->reg) {
+ if (chip->reg)
regulator_disable(chip->reg);
- regulator_put(chip->reg);
- }
-
- iio_device_free(indio_dev);
return 0;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 4/9] staging: iio: ad7606_core: Use devm_* APIs
2013-08-31 17:12 [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs Sachin Kamat
2013-08-31 17:12 ` [PATCH 2/9] staging: iio: ad7280a: Use devm_iio_device_alloc Sachin Kamat
2013-08-31 17:12 ` [PATCH 3/9] staging: iio: ad7291: Use devm_* APIs Sachin Kamat
@ 2013-08-31 17:12 ` Sachin Kamat
2013-08-31 17:12 ` [PATCH 5/9] staging: iio: ad7780: " Sachin Kamat
` (5 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Sachin Kamat @ 2013-08-31 17:12 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, lars, sachin.kamat
devm_* APIs are device managed and make code simpler.
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
drivers/staging/iio/adc/ad7606_core.c | 23 +++++++----------------
1 files changed, 7 insertions(+), 16 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7606_core.c b/drivers/staging/iio/adc/ad7606_core.c
index 72868ce..0eb5ed0 100644
--- a/drivers/staging/iio/adc/ad7606_core.c
+++ b/drivers/staging/iio/adc/ad7606_core.c
@@ -466,12 +466,11 @@ struct iio_dev *ad7606_probe(struct device *dev, int irq,
struct ad7606_platform_data *pdata = dev->platform_data;
struct ad7606_state *st;
int ret;
- struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
+ struct iio_dev *indio_dev;
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (!indio_dev)
+ return ERR_PTR(-ENOMEM);
st = iio_priv(indio_dev);
@@ -489,11 +488,11 @@ struct iio_dev *ad7606_probe(struct device *dev, int irq,
st->oversampling = pdata->default_os;
}
- st->reg = regulator_get(dev, "vcc");
+ st->reg = devm_regulator_get(dev, "vcc");
if (!IS_ERR(st->reg)) {
ret = regulator_enable(st->reg);
if (ret)
- goto error_put_reg;
+ return ERR_PTR(ret);
}
st->pdata = pdata;
@@ -554,11 +553,6 @@ error_free_gpios:
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);
-error_ret:
return ERR_PTR(ret);
}
@@ -570,13 +564,10 @@ int ad7606_remove(struct iio_dev *indio_dev, int irq)
ad7606_ring_cleanup(indio_dev);
free_irq(irq, indio_dev);
- if (!IS_ERR(st->reg)) {
+ if (!IS_ERR(st->reg))
regulator_disable(st->reg);
- regulator_put(st->reg);
- }
ad7606_free_gpios(st);
- iio_device_free(indio_dev);
return 0;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 5/9] staging: iio: ad7780: Use devm_* APIs
2013-08-31 17:12 [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs Sachin Kamat
` (2 preceding siblings ...)
2013-08-31 17:12 ` [PATCH 4/9] staging: iio: ad7606_core: " Sachin Kamat
@ 2013-08-31 17:12 ` Sachin Kamat
2013-08-31 17:12 ` [PATCH 6/9] staging: iio: ad7816: " Sachin Kamat
` (4 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Sachin Kamat @ 2013-08-31 17:12 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, lars, sachin.kamat
devm_* APIs are device managed and make code simpler.
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
drivers/staging/iio/adc/ad7780.c | 28 +++++++---------------------
1 files changed, 7 insertions(+), 21 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c
index e1f8860..4f2522a 100644
--- a/drivers/staging/iio/adc/ad7780.c
+++ b/drivers/staging/iio/adc/ad7780.c
@@ -171,7 +171,7 @@ static int ad7780_probe(struct spi_device *spi)
struct iio_dev *indio_dev;
int ret, voltage_uv = 0;
- indio_dev = iio_device_alloc(sizeof(*st));
+ indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
if (indio_dev == NULL)
return -ENOMEM;
@@ -180,11 +180,11 @@ static int ad7780_probe(struct spi_device *spi)
ad_sd_init(&st->sd, indio_dev, spi, &ad7780_sigma_delta_info);
- 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;
voltage_uv = regulator_get_voltage(st->reg);
}
@@ -210,8 +210,8 @@ static int ad7780_probe(struct spi_device *spi)
if (pdata && gpio_is_valid(pdata->gpio_pdrst)) {
- ret = gpio_request_one(pdata->gpio_pdrst, GPIOF_OUT_INIT_LOW,
- "AD7780 /PDRST");
+ ret = devm_gpio_request_one(&spi->dev, pdata->gpio_pdrst,
+ GPIOF_OUT_INIT_LOW, "AD7780 /PDRST");
if (ret) {
dev_err(&spi->dev, "failed to request GPIO PDRST\n");
goto error_disable_reg;
@@ -223,7 +223,7 @@ static int ad7780_probe(struct spi_device *spi)
ret = ad_sd_setup_buffer_and_trigger(indio_dev);
if (ret)
- goto error_free_gpio;
+ goto error_disable_reg;
ret = iio_device_register(indio_dev);
if (ret)
@@ -233,17 +233,9 @@ static int ad7780_probe(struct spi_device *spi)
error_cleanup_buffer_and_trigger:
ad_sd_cleanup_buffer_and_trigger(indio_dev);
-error_free_gpio:
- if (pdata && gpio_is_valid(pdata->gpio_pdrst))
- gpio_free(pdata->gpio_pdrst);
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;
}
@@ -256,14 +248,8 @@ static int ad7780_remove(struct spi_device *spi)
iio_device_unregister(indio_dev);
ad_sd_cleanup_buffer_and_trigger(indio_dev);
- if (gpio_is_valid(st->powerdown_gpio))
- gpio_free(st->powerdown_gpio);
-
- 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;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 6/9] staging: iio: ad7816: Use devm_* APIs
2013-08-31 17:12 [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs Sachin Kamat
` (3 preceding siblings ...)
2013-08-31 17:12 ` [PATCH 5/9] staging: iio: ad7780: " Sachin Kamat
@ 2013-08-31 17:12 ` Sachin Kamat
2013-08-31 17:12 ` [PATCH 7/9] staging: iio: ad799x_core: " Sachin Kamat
` (3 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Sachin Kamat @ 2013-08-31 17:12 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, lars, sachin.kamat
devm_* APIs are device managed and make code simpler.
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
drivers/staging/iio/adc/ad7816.c | 59 +++++++++++++-------------------------
1 files changed, 20 insertions(+), 39 deletions(-)
diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index 8470036..9f48e5c 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -356,11 +356,9 @@ static int ad7816_probe(struct spi_device *spi_dev)
return -EINVAL;
}
- indio_dev = iio_device_alloc(sizeof(*chip));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(&spi_dev->dev, sizeof(*chip));
+ if (!indio_dev)
+ return -ENOMEM;
chip = iio_priv(indio_dev);
/* this is only used for device removal purposes */
dev_set_drvdata(&spi_dev->dev, indio_dev);
@@ -372,25 +370,28 @@ static int ad7816_probe(struct spi_device *spi_dev)
chip->convert_pin = pins[1];
chip->busy_pin = pins[2];
- ret = gpio_request(chip->rdwr_pin, spi_get_device_id(spi_dev)->name);
+ ret = devm_gpio_request(&spi_dev->dev, chip->rdwr_pin,
+ spi_get_device_id(spi_dev)->name);
if (ret) {
dev_err(&spi_dev->dev, "Fail to request rdwr gpio PIN %d.\n",
chip->rdwr_pin);
- goto error_free_device;
+ return ret;
}
gpio_direction_input(chip->rdwr_pin);
- ret = gpio_request(chip->convert_pin, spi_get_device_id(spi_dev)->name);
+ ret = devm_gpio_request(&spi_dev->dev, chip->convert_pin,
+ spi_get_device_id(spi_dev)->name);
if (ret) {
dev_err(&spi_dev->dev, "Fail to request convert gpio PIN %d.\n",
chip->convert_pin);
- goto error_free_gpio_rdwr;
+ return ret;
}
gpio_direction_input(chip->convert_pin);
- ret = gpio_request(chip->busy_pin, spi_get_device_id(spi_dev)->name);
+ ret = devm_gpio_request(&spi_dev->dev, chip->busy_pin,
+ spi_get_device_id(spi_dev)->name);
if (ret) {
dev_err(&spi_dev->dev, "Fail to request busy gpio PIN %d.\n",
chip->busy_pin);
- goto error_free_gpio_convert;
+ return ret;
}
gpio_direction_input(chip->busy_pin);
@@ -401,51 +402,31 @@ static int ad7816_probe(struct spi_device *spi_dev)
if (spi_dev->irq) {
/* Only low trigger is supported in ad7816/7/8 */
- ret = request_threaded_irq(spi_dev->irq,
- NULL,
- &ad7816_event_handler,
- IRQF_TRIGGER_LOW | IRQF_ONESHOT,
- indio_dev->name,
- indio_dev);
+ ret = devm_request_threaded_irq(&spi_dev->dev, spi_dev->irq,
+ NULL,
+ &ad7816_event_handler,
+ IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+ indio_dev->name,
+ indio_dev);
if (ret)
- goto error_free_gpio;
+ return ret;
}
ret = iio_device_register(indio_dev);
if (ret)
- goto error_free_irq;
+ return ret;
dev_info(&spi_dev->dev, "%s temperature sensor and ADC registered.\n",
indio_dev->name);
return 0;
-error_free_irq:
- free_irq(spi_dev->irq, indio_dev);
-error_free_gpio:
- gpio_free(chip->busy_pin);
-error_free_gpio_convert:
- gpio_free(chip->convert_pin);
-error_free_gpio_rdwr:
- gpio_free(chip->rdwr_pin);
-error_free_device:
- iio_device_free(indio_dev);
-error_ret:
- return ret;
}
static int ad7816_remove(struct spi_device *spi_dev)
{
struct iio_dev *indio_dev = dev_get_drvdata(&spi_dev->dev);
- struct ad7816_chip_info *chip = iio_priv(indio_dev);
iio_device_unregister(indio_dev);
- dev_set_drvdata(&spi_dev->dev, NULL);
- if (spi_dev->irq)
- free_irq(spi_dev->irq, indio_dev);
- gpio_free(chip->busy_pin);
- gpio_free(chip->convert_pin);
- gpio_free(chip->rdwr_pin);
- iio_device_free(indio_dev);
return 0;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 7/9] staging: iio: ad799x_core: Use devm_* APIs
2013-08-31 17:12 [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs Sachin Kamat
` (4 preceding siblings ...)
2013-08-31 17:12 ` [PATCH 6/9] staging: iio: ad7816: " Sachin Kamat
@ 2013-08-31 17:12 ` Sachin Kamat
2013-08-31 17:12 ` [PATCH 8/9] staging: iio: lpc32xx_adc: " Sachin Kamat
` (2 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Sachin Kamat @ 2013-08-31 17:12 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, lars, sachin.kamat
devm_* APIs are device managed and make code simpler.
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
drivers/staging/iio/adc/ad799x_core.c | 16 +++++-----------
1 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
index 2b2049c..3f5142b 100644
--- a/drivers/staging/iio/adc/ad799x_core.c
+++ b/drivers/staging/iio/adc/ad799x_core.c
@@ -586,8 +586,9 @@ static int ad799x_probe(struct i2c_client *client,
int ret;
struct ad799x_platform_data *pdata = client->dev.platform_data;
struct ad799x_state *st;
- struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
+ struct iio_dev *indio_dev;
+ indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st));
if (indio_dev == NULL)
return -ENOMEM;
@@ -606,11 +607,11 @@ static int ad799x_probe(struct i2c_client *client,
st->int_vref_mv = pdata->vref_mv;
- st->reg = regulator_get(&client->dev, "vcc");
+ st->reg = devm_regulator_get(&client->dev, "vcc");
if (!IS_ERR(st->reg)) {
ret = regulator_enable(st->reg);
if (ret)
- goto error_put_reg;
+ return ret;
}
st->client = client;
@@ -650,10 +651,6 @@ error_cleanup_ring:
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;
}
@@ -668,12 +665,9 @@ static int ad799x_remove(struct i2c_client *client)
free_irq(client->irq, indio_dev);
ad799x_ring_cleanup(indio_dev);
- if (!IS_ERR(st->reg)) {
+ if (!IS_ERR(st->reg))
regulator_disable(st->reg);
- regulator_put(st->reg);
- }
kfree(st->rx_buf);
- iio_device_free(indio_dev);
return 0;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 8/9] staging: iio: lpc32xx_adc: Use devm_* APIs
2013-08-31 17:12 [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs Sachin Kamat
` (5 preceding siblings ...)
2013-08-31 17:12 ` [PATCH 7/9] staging: iio: ad799x_core: " Sachin Kamat
@ 2013-08-31 17:12 ` Sachin Kamat
2013-08-31 17:12 ` [PATCH 9/9] staging: iio: adt7316: " Sachin Kamat
2013-08-31 18:31 ` [PATCH 1/9] staging: iio: ad7192: " Jonathan Cameron
8 siblings, 0 replies; 12+ messages in thread
From: Sachin Kamat @ 2013-08-31 17:12 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, lars, sachin.kamat, Roland Stigge
devm_* APIs are device managed and make code simpler.
This also fixes an error in return type during clk_get
failure.
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Cc: Roland Stigge <stigge@antcom.de>
---
drivers/staging/iio/adc/lpc32xx_adc.c | 49 +++++++++-----------------------
1 files changed, 14 insertions(+), 35 deletions(-)
diff --git a/drivers/staging/iio/adc/lpc32xx_adc.c b/drivers/staging/iio/adc/lpc32xx_adc.c
index 9a4bb09..ce7ff3e 100644
--- a/drivers/staging/iio/adc/lpc32xx_adc.c
+++ b/drivers/staging/iio/adc/lpc32xx_adc.c
@@ -137,43 +137,39 @@ static int lpc32xx_adc_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "failed to get platform I/O memory\n");
- retval = -EBUSY;
- goto errout1;
+ return -EBUSY;
}
- iodev = iio_device_alloc(sizeof(struct lpc32xx_adc_info));
- if (!iodev) {
- dev_err(&pdev->dev, "failed allocating iio device\n");
- retval = -ENOMEM;
- goto errout1;
- }
+ iodev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
+ if (!iodev)
+ return -ENOMEM;
info = iio_priv(iodev);
- info->adc_base = ioremap(res->start, resource_size(res));
+ info->adc_base = devm_ioremap(&pdev->dev, res->start,
+ resource_size(res));
if (!info->adc_base) {
dev_err(&pdev->dev, "failed mapping memory\n");
- retval = -EBUSY;
- goto errout2;
+ return -EBUSY;
}
- info->clk = clk_get(&pdev->dev, NULL);
+ info->clk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(info->clk)) {
dev_err(&pdev->dev, "failed getting clock\n");
- goto errout3;
+ return PTR_ERR(info->clk);
}
irq = platform_get_irq(pdev, 0);
if ((irq < 0) || (irq >= NR_IRQS)) {
dev_err(&pdev->dev, "failed getting interrupt resource\n");
- retval = -EINVAL;
- goto errout4;
+ return -EINVAL;
}
- retval = request_irq(irq, lpc32xx_adc_isr, 0, MOD_NAME, info);
+ retval = devm_request_irq(&pdev->dev, irq, lpc32xx_adc_isr, 0,
+ MOD_NAME, info);
if (retval < 0) {
dev_err(&pdev->dev, "failed requesting interrupt\n");
- goto errout4;
+ return retval;
}
platform_set_drvdata(pdev, iodev);
@@ -189,35 +185,18 @@ static int lpc32xx_adc_probe(struct platform_device *pdev)
retval = iio_device_register(iodev);
if (retval)
- goto errout5;
+ return retval;
dev_info(&pdev->dev, "LPC32XX ADC driver loaded, IRQ %d\n", irq);
return 0;
-
-errout5:
- free_irq(irq, info);
-errout4:
- clk_put(info->clk);
-errout3:
- iounmap(info->adc_base);
-errout2:
- iio_device_free(iodev);
-errout1:
- return retval;
}
static int lpc32xx_adc_remove(struct platform_device *pdev)
{
struct iio_dev *iodev = platform_get_drvdata(pdev);
- struct lpc32xx_adc_info *info = iio_priv(iodev);
- int irq = platform_get_irq(pdev, 0);
iio_device_unregister(iodev);
- free_irq(irq, info);
- clk_put(info->clk);
- iounmap(info->adc_base);
- iio_device_free(iodev);
return 0;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 9/9] staging: iio: adt7316: Use devm_* APIs
2013-08-31 17:12 [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs Sachin Kamat
` (6 preceding siblings ...)
2013-08-31 17:12 ` [PATCH 8/9] staging: iio: lpc32xx_adc: " Sachin Kamat
@ 2013-08-31 17:12 ` Sachin Kamat
2013-08-31 18:31 ` [PATCH 1/9] staging: iio: ad7192: " Jonathan Cameron
8 siblings, 0 replies; 12+ messages in thread
From: Sachin Kamat @ 2013-08-31 17:12 UTC (permalink / raw)
To: linux-iio; +Cc: jic23, lars, sachin.kamat
devm_* APIs are device managed and make code simpler.
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
drivers/staging/iio/addac/adt7316.c | 48 +++++++++++-----------------------
1 files changed, 16 insertions(+), 32 deletions(-)
diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c
index 1e13568..514ddcc 100644
--- a/drivers/staging/iio/addac/adt7316.c
+++ b/drivers/staging/iio/addac/adt7316.c
@@ -2106,11 +2106,9 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
unsigned short *adt7316_platform_data = dev->platform_data;
int ret = 0;
- indio_dev = iio_device_alloc(sizeof(*chip));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*chip));
+ if (!indio_dev)
+ return -ENOMEM;
chip = iio_priv(indio_dev);
/* this is only used for device removal purposes */
dev_set_drvdata(dev, indio_dev);
@@ -2146,58 +2144,44 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
if (adt7316_platform_data[0])
chip->bus.irq_flags = adt7316_platform_data[0];
- ret = request_threaded_irq(chip->bus.irq,
- NULL,
- &adt7316_event_handler,
- chip->bus.irq_flags | IRQF_ONESHOT,
- indio_dev->name,
- indio_dev);
+ ret = devm_request_threaded_irq(dev, chip->bus.irq,
+ NULL,
+ &adt7316_event_handler,
+ chip->bus.irq_flags |
+ IRQF_ONESHOT,
+ indio_dev->name,
+ indio_dev);
if (ret)
- goto error_free_dev;
+ return ret;
if (chip->bus.irq_flags & IRQF_TRIGGER_HIGH)
chip->config1 |= ADT7316_INT_POLARITY;
}
ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, chip->config1);
- if (ret) {
- ret = -EIO;
- goto error_unreg_irq;
- }
+ if (ret)
+ return -EIO;
ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, chip->config3);
- if (ret) {
- ret = -EIO;
- goto error_unreg_irq;
- }
+ if (ret)
+ return -EIO;
ret = iio_device_register(indio_dev);
if (ret)
- goto error_unreg_irq;
+ return ret;
dev_info(dev, "%s temperature sensor, ADC and DAC registered.\n",
indio_dev->name);
return 0;
-
-error_unreg_irq:
- free_irq(chip->bus.irq, indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
- return ret;
}
EXPORT_SYMBOL(adt7316_probe);
int adt7316_remove(struct device *dev)
{
struct iio_dev *indio_dev = dev_get_drvdata(dev);
- struct adt7316_chip_info *chip = iio_priv(indio_dev);
iio_device_unregister(indio_dev);
- if (chip->bus.irq)
- free_irq(chip->bus.irq, indio_dev);
- iio_device_free(indio_dev);
return 0;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs
2013-08-31 17:12 [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs Sachin Kamat
` (7 preceding siblings ...)
2013-08-31 17:12 ` [PATCH 9/9] staging: iio: adt7316: " Sachin Kamat
@ 2013-08-31 18:31 ` Jonathan Cameron
2013-09-01 5:51 ` Sachin Kamat
8 siblings, 1 reply; 12+ messages in thread
From: Jonathan Cameron @ 2013-08-31 18:31 UTC (permalink / raw)
To: Sachin Kamat; +Cc: linux-iio, lars
On 08/31/13 18:12, Sachin Kamat wrote:
> devm_* APIs are device managed and make code simpler.
>
> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
> ---
> This series is compile tested and based on togreg branch
> of iio tree.
Just to note, there is a memory leak fixed by this patch as well
as the remove function didn't free the struct iio_dev before.
Thanks for these Sachin. All look good to me.
I won't take them today as effectively IIO for 3.12 is now
closed, as I doubt we'll see more than one more rc on
3.11, and others may want to have time to look through these.
I'll pick them up in a few days and queue up for 3.13 assuming
no one spots anything I have missed.
Jonathan
> ---
> drivers/staging/iio/adc/ad7192.c | 15 ++++-----------
> 1 files changed, 4 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
> index 3283e28..83bb44b 100644
> --- a/drivers/staging/iio/adc/ad7192.c
> +++ b/drivers/staging/iio/adc/ad7192.c
> @@ -623,17 +623,17 @@ static int ad7192_probe(struct spi_device *spi)
> return -ENODEV;
> }
>
> - 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;
>
> voltage_uv = regulator_get_voltage(st->reg);
> }
> @@ -677,11 +677,6 @@ error_remove_trigger:
> 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;
> }
> @@ -694,10 +689,8 @@ static int ad7192_remove(struct spi_device *spi)
> iio_device_unregister(indio_dev);
> ad_sd_cleanup_buffer_and_trigger(indio_dev);
>
> - if (!IS_ERR(st->reg)) {
> + if (!IS_ERR(st->reg))
> regulator_disable(st->reg);
> - regulator_put(st->reg);
> - }
>
> return 0;
> }
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs
2013-08-31 18:31 ` [PATCH 1/9] staging: iio: ad7192: " Jonathan Cameron
@ 2013-09-01 5:51 ` Sachin Kamat
2013-09-07 20:51 ` Jonathan Cameron
0 siblings, 1 reply; 12+ messages in thread
From: Sachin Kamat @ 2013-09-01 5:51 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen
On 1 September 2013 00:01, Jonathan Cameron <jic23@kernel.org> wrote:
> On 08/31/13 18:12, Sachin Kamat wrote:
>> devm_* APIs are device managed and make code simpler.
>>
>> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
>> ---
>> This series is compile tested and based on togreg branch
>> of iio tree.
>
> Just to note, there is a memory leak fixed by this patch as well
> as the remove function didn't free the struct iio_dev before.
Yes. I forgot to mention that in the commit log. Thanks for noticing.
>
> Thanks for these Sachin. All look good to me.
> I won't take them today as effectively IIO for 3.12 is now
> closed, as I doubt we'll see more than one more rc on
> 3.11, and others may want to have time to look through these.
I wasn't aware of it, sorry.
>
> I'll pick them up in a few days and queue up for 3.13 assuming
> no one spots anything I have missed.
Sure. Thanks.
--
With warm regards,
Sachin
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs
2013-09-01 5:51 ` Sachin Kamat
@ 2013-09-07 20:51 ` Jonathan Cameron
0 siblings, 0 replies; 12+ messages in thread
From: Jonathan Cameron @ 2013-09-07 20:51 UTC (permalink / raw)
To: Sachin Kamat; +Cc: linux-iio, Lars-Peter Clausen
On 09/01/13 06:51, Sachin Kamat wrote:
> On 1 September 2013 00:01, Jonathan Cameron <jic23@kernel.org> wrote:
>> On 08/31/13 18:12, Sachin Kamat wrote:
>>> devm_* APIs are device managed and make code simpler.
>>>
>>> Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
>>> ---
>>> This series is compile tested and based on togreg branch
>>> of iio tree.
>>
>> Just to note, there is a memory leak fixed by this patch as well
>> as the remove function didn't free the struct iio_dev before.
>
> Yes. I forgot to mention that in the commit log. Thanks for noticing.
>
>>
>> Thanks for these Sachin. All look good to me.
>> I won't take them today as effectively IIO for 3.12 is now
>> closed, as I doubt we'll see more than one more rc on
>> 3.11, and others may want to have time to look through these.
>
> I wasn't aware of it, sorry.
>
>>
>> I'll pick them up in a few days and queue up for 3.13 assuming
>> no one spots anything I have missed.
>
> Sure. Thanks.
All applied to the togreg branch of iio.git.
Thanks as ever for your work on these!
Jonathan
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2013-09-07 19:51 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-31 17:12 [PATCH 1/9] staging: iio: ad7192: Use devm_* APIs Sachin Kamat
2013-08-31 17:12 ` [PATCH 2/9] staging: iio: ad7280a: Use devm_iio_device_alloc Sachin Kamat
2013-08-31 17:12 ` [PATCH 3/9] staging: iio: ad7291: Use devm_* APIs Sachin Kamat
2013-08-31 17:12 ` [PATCH 4/9] staging: iio: ad7606_core: " Sachin Kamat
2013-08-31 17:12 ` [PATCH 5/9] staging: iio: ad7780: " Sachin Kamat
2013-08-31 17:12 ` [PATCH 6/9] staging: iio: ad7816: " Sachin Kamat
2013-08-31 17:12 ` [PATCH 7/9] staging: iio: ad799x_core: " Sachin Kamat
2013-08-31 17:12 ` [PATCH 8/9] staging: iio: lpc32xx_adc: " Sachin Kamat
2013-08-31 17:12 ` [PATCH 9/9] staging: iio: adt7316: " Sachin Kamat
2013-08-31 18:31 ` [PATCH 1/9] staging: iio: ad7192: " Jonathan Cameron
2013-09-01 5:51 ` Sachin Kamat
2013-09-07 20:51 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).