Commit 4f6b38c8 authored by Sachin Kamat's avatar Sachin Kamat Committed by Jonathan Cameron

staging: iio: ad7780: Use devm_* APIs

devm_* APIs are device managed and make code simpler.
Signed-off-by: default avatarSachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 3727245a
...@@ -171,7 +171,7 @@ static int ad7780_probe(struct spi_device *spi) ...@@ -171,7 +171,7 @@ static int ad7780_probe(struct spi_device *spi)
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
int ret, voltage_uv = 0; 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) if (indio_dev == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -180,11 +180,11 @@ static int ad7780_probe(struct spi_device *spi) ...@@ -180,11 +180,11 @@ static int ad7780_probe(struct spi_device *spi)
ad_sd_init(&st->sd, indio_dev, spi, &ad7780_sigma_delta_info); 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)) { if (!IS_ERR(st->reg)) {
ret = regulator_enable(st->reg); ret = regulator_enable(st->reg);
if (ret) if (ret)
goto error_put_reg; return ret;
voltage_uv = regulator_get_voltage(st->reg); voltage_uv = regulator_get_voltage(st->reg);
} }
...@@ -210,8 +210,8 @@ static int ad7780_probe(struct spi_device *spi) ...@@ -210,8 +210,8 @@ static int ad7780_probe(struct spi_device *spi)
if (pdata && gpio_is_valid(pdata->gpio_pdrst)) { if (pdata && gpio_is_valid(pdata->gpio_pdrst)) {
ret = gpio_request_one(pdata->gpio_pdrst, GPIOF_OUT_INIT_LOW, ret = devm_gpio_request_one(&spi->dev, pdata->gpio_pdrst,
"AD7780 /PDRST"); GPIOF_OUT_INIT_LOW, "AD7780 /PDRST");
if (ret) { if (ret) {
dev_err(&spi->dev, "failed to request GPIO PDRST\n"); dev_err(&spi->dev, "failed to request GPIO PDRST\n");
goto error_disable_reg; goto error_disable_reg;
...@@ -223,7 +223,7 @@ static int ad7780_probe(struct spi_device *spi) ...@@ -223,7 +223,7 @@ static int ad7780_probe(struct spi_device *spi)
ret = ad_sd_setup_buffer_and_trigger(indio_dev); ret = ad_sd_setup_buffer_and_trigger(indio_dev);
if (ret) if (ret)
goto error_free_gpio; goto error_disable_reg;
ret = iio_device_register(indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
...@@ -233,17 +233,9 @@ static int ad7780_probe(struct spi_device *spi) ...@@ -233,17 +233,9 @@ static int ad7780_probe(struct spi_device *spi)
error_cleanup_buffer_and_trigger: error_cleanup_buffer_and_trigger:
ad_sd_cleanup_buffer_and_trigger(indio_dev); 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: error_disable_reg:
if (!IS_ERR(st->reg)) if (!IS_ERR(st->reg))
regulator_disable(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; return ret;
} }
...@@ -256,14 +248,8 @@ static int ad7780_remove(struct spi_device *spi) ...@@ -256,14 +248,8 @@ static int ad7780_remove(struct spi_device *spi)
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
ad_sd_cleanup_buffer_and_trigger(indio_dev); ad_sd_cleanup_buffer_and_trigger(indio_dev);
if (gpio_is_valid(st->powerdown_gpio)) if (!IS_ERR(st->reg))
gpio_free(st->powerdown_gpio);
if (!IS_ERR(st->reg)) {
regulator_disable(st->reg); regulator_disable(st->reg);
regulator_put(st->reg);
}
iio_device_free(indio_dev);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment