forked from Minki/linux
staging: iio: ad7780: Use devm_* APIs
devm_* APIs are device managed and make code simpler. Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
3727245a78
commit
4f6b38c8bf
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user