diff options
author | Sachin Kamat <sachin.kamat@linaro.org> | 2013-07-23 04:58:00 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2013-08-03 13:40:38 -0400 |
commit | 7abe9007ca671bf27799922711d8c023bac56a88 (patch) | |
tree | 233ab0ee4594589e5c70fad27751bf162222ed64 | |
parent | ded4fef934768adee9d31f15831513d7d76c360b (diff) |
iio: adc: ad7298: Use devm_* APIs
devm_* APIs are device managed and make code simpler.
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r-- | drivers/iio/adc/ad7298.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/drivers/iio/adc/ad7298.c b/drivers/iio/adc/ad7298.c index 03b77189dbfe..85d1481c312f 100644 --- a/drivers/iio/adc/ad7298.c +++ b/drivers/iio/adc/ad7298.c | |||
@@ -296,9 +296,10 @@ static int ad7298_probe(struct spi_device *spi) | |||
296 | { | 296 | { |
297 | struct ad7298_platform_data *pdata = spi->dev.platform_data; | 297 | struct ad7298_platform_data *pdata = spi->dev.platform_data; |
298 | struct ad7298_state *st; | 298 | struct ad7298_state *st; |
299 | struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st)); | 299 | struct iio_dev *indio_dev; |
300 | int ret; | 300 | int ret; |
301 | 301 | ||
302 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); | ||
302 | if (indio_dev == NULL) | 303 | if (indio_dev == NULL) |
303 | return -ENOMEM; | 304 | return -ENOMEM; |
304 | 305 | ||
@@ -308,14 +309,13 @@ static int ad7298_probe(struct spi_device *spi) | |||
308 | st->ext_ref = AD7298_EXTREF; | 309 | st->ext_ref = AD7298_EXTREF; |
309 | 310 | ||
310 | if (st->ext_ref) { | 311 | if (st->ext_ref) { |
311 | st->reg = regulator_get(&spi->dev, "vref"); | 312 | st->reg = devm_regulator_get(&spi->dev, "vref"); |
312 | if (IS_ERR(st->reg)) { | 313 | if (IS_ERR(st->reg)) |
313 | ret = PTR_ERR(st->reg); | 314 | return PTR_ERR(st->reg); |
314 | goto error_free; | 315 | |
315 | } | ||
316 | ret = regulator_enable(st->reg); | 316 | ret = regulator_enable(st->reg); |
317 | if (ret) | 317 | if (ret) |
318 | goto error_put_reg; | 318 | return ret; |
319 | } | 319 | } |
320 | 320 | ||
321 | spi_set_drvdata(spi, indio_dev); | 321 | spi_set_drvdata(spi, indio_dev); |
@@ -361,11 +361,6 @@ error_cleanup_ring: | |||
361 | error_disable_reg: | 361 | error_disable_reg: |
362 | if (st->ext_ref) | 362 | if (st->ext_ref) |
363 | regulator_disable(st->reg); | 363 | regulator_disable(st->reg); |
364 | error_put_reg: | ||
365 | if (st->ext_ref) | ||
366 | regulator_put(st->reg); | ||
367 | error_free: | ||
368 | iio_device_free(indio_dev); | ||
369 | 364 | ||
370 | return ret; | 365 | return ret; |
371 | } | 366 | } |
@@ -377,11 +372,8 @@ static int ad7298_remove(struct spi_device *spi) | |||
377 | 372 | ||
378 | iio_device_unregister(indio_dev); | 373 | iio_device_unregister(indio_dev); |
379 | iio_triggered_buffer_cleanup(indio_dev); | 374 | iio_triggered_buffer_cleanup(indio_dev); |
380 | if (st->ext_ref) { | 375 | if (st->ext_ref) |
381 | regulator_disable(st->reg); | 376 | regulator_disable(st->reg); |
382 | regulator_put(st->reg); | ||
383 | } | ||
384 | iio_device_free(indio_dev); | ||
385 | 377 | ||
386 | return 0; | 378 | return 0; |
387 | } | 379 | } |