Commit 0d7c04d3 authored by Sachin Kamat's avatar Sachin Kamat Committed by Jonathan Cameron

iio: dac: ad5791: 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 7ff0de3f
...@@ -349,17 +349,15 @@ static int ad5791_probe(struct spi_device *spi) ...@@ -349,17 +349,15 @@ static int ad5791_probe(struct spi_device *spi)
struct ad5791_state *st; struct ad5791_state *st;
int ret, pos_voltage_uv = 0, neg_voltage_uv = 0; int ret, pos_voltage_uv = 0, neg_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)
ret = -ENOMEM; return -ENOMEM;
goto error_ret;
}
st = iio_priv(indio_dev); st = iio_priv(indio_dev);
st->reg_vdd = regulator_get(&spi->dev, "vdd"); st->reg_vdd = devm_regulator_get(&spi->dev, "vdd");
if (!IS_ERR(st->reg_vdd)) { if (!IS_ERR(st->reg_vdd)) {
ret = regulator_enable(st->reg_vdd); ret = regulator_enable(st->reg_vdd);
if (ret) if (ret)
goto error_put_reg_pos; return ret;
ret = regulator_get_voltage(st->reg_vdd); ret = regulator_get_voltage(st->reg_vdd);
if (ret < 0) if (ret < 0)
...@@ -368,11 +366,11 @@ static int ad5791_probe(struct spi_device *spi) ...@@ -368,11 +366,11 @@ static int ad5791_probe(struct spi_device *spi)
pos_voltage_uv = ret; pos_voltage_uv = ret;
} }
st->reg_vss = regulator_get(&spi->dev, "vss"); st->reg_vss = devm_regulator_get(&spi->dev, "vss");
if (!IS_ERR(st->reg_vss)) { if (!IS_ERR(st->reg_vss)) {
ret = regulator_enable(st->reg_vss); ret = regulator_enable(st->reg_vss);
if (ret) if (ret)
goto error_put_reg_neg; goto error_disable_reg_pos;
ret = regulator_get_voltage(st->reg_vss); ret = regulator_get_voltage(st->reg_vss);
if (ret < 0) if (ret < 0)
...@@ -428,19 +426,9 @@ static int ad5791_probe(struct spi_device *spi) ...@@ -428,19 +426,9 @@ static int ad5791_probe(struct spi_device *spi)
error_disable_reg_neg: error_disable_reg_neg:
if (!IS_ERR(st->reg_vss)) if (!IS_ERR(st->reg_vss))
regulator_disable(st->reg_vss); regulator_disable(st->reg_vss);
error_put_reg_neg:
if (!IS_ERR(st->reg_vss))
regulator_put(st->reg_vss);
error_disable_reg_pos: error_disable_reg_pos:
if (!IS_ERR(st->reg_vdd)) if (!IS_ERR(st->reg_vdd))
regulator_disable(st->reg_vdd); regulator_disable(st->reg_vdd);
error_put_reg_pos:
if (!IS_ERR(st->reg_vdd))
regulator_put(st->reg_vdd);
iio_device_free(indio_dev);
error_ret:
return ret; return ret;
} }
...@@ -450,16 +438,11 @@ static int ad5791_remove(struct spi_device *spi) ...@@ -450,16 +438,11 @@ static int ad5791_remove(struct spi_device *spi)
struct ad5791_state *st = iio_priv(indio_dev); struct ad5791_state *st = iio_priv(indio_dev);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
if (!IS_ERR(st->reg_vdd)) { if (!IS_ERR(st->reg_vdd))
regulator_disable(st->reg_vdd); regulator_disable(st->reg_vdd);
regulator_put(st->reg_vdd);
}
if (!IS_ERR(st->reg_vss)) { if (!IS_ERR(st->reg_vss))
regulator_disable(st->reg_vss); regulator_disable(st->reg_vss);
regulator_put(st->reg_vss);
}
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