diff options
author | Sachin Kamat <sachin.kamat@linaro.org> | 2013-08-19 07:38:00 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2013-08-19 15:35:35 -0400 |
commit | 0d7c04d33f3e2f9e3da0a545be747731b4410e32 (patch) | |
tree | af3ac1285f1f48bcc2e9bb7c291b8b620dca4b7e /drivers/iio | |
parent | 7ff0de3faaeb0db80c2c9f03c119167e89594879 (diff) |
iio: dac: ad5791: 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>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/dac/ad5791.c | 35 |
1 files changed, 9 insertions, 26 deletions
diff --git a/drivers/iio/dac/ad5791.c b/drivers/iio/dac/ad5791.c index 97c1e5d780df..ce7458963309 100644 --- a/drivers/iio/dac/ad5791.c +++ b/drivers/iio/dac/ad5791.c | |||
@@ -349,17 +349,15 @@ static int ad5791_probe(struct spi_device *spi) | |||
349 | struct ad5791_state *st; | 349 | struct ad5791_state *st; |
350 | int ret, pos_voltage_uv = 0, neg_voltage_uv = 0; | 350 | int ret, pos_voltage_uv = 0, neg_voltage_uv = 0; |
351 | 351 | ||
352 | indio_dev = iio_device_alloc(sizeof(*st)); | 352 | indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); |
353 | if (indio_dev == NULL) { | 353 | if (!indio_dev) |
354 | ret = -ENOMEM; | 354 | return -ENOMEM; |
355 | goto error_ret; | ||
356 | } | ||
357 | st = iio_priv(indio_dev); | 355 | st = iio_priv(indio_dev); |
358 | st->reg_vdd = regulator_get(&spi->dev, "vdd"); | 356 | st->reg_vdd = devm_regulator_get(&spi->dev, "vdd"); |
359 | if (!IS_ERR(st->reg_vdd)) { | 357 | if (!IS_ERR(st->reg_vdd)) { |
360 | ret = regulator_enable(st->reg_vdd); | 358 | ret = regulator_enable(st->reg_vdd); |
361 | if (ret) | 359 | if (ret) |
362 | goto error_put_reg_pos; | 360 | return ret; |
363 | 361 | ||
364 | ret = regulator_get_voltage(st->reg_vdd); | 362 | ret = regulator_get_voltage(st->reg_vdd); |
365 | if (ret < 0) | 363 | if (ret < 0) |
@@ -368,11 +366,11 @@ static int ad5791_probe(struct spi_device *spi) | |||
368 | pos_voltage_uv = ret; | 366 | pos_voltage_uv = ret; |
369 | } | 367 | } |
370 | 368 | ||
371 | st->reg_vss = regulator_get(&spi->dev, "vss"); | 369 | st->reg_vss = devm_regulator_get(&spi->dev, "vss"); |
372 | if (!IS_ERR(st->reg_vss)) { | 370 | if (!IS_ERR(st->reg_vss)) { |
373 | ret = regulator_enable(st->reg_vss); | 371 | ret = regulator_enable(st->reg_vss); |
374 | if (ret) | 372 | if (ret) |
375 | goto error_put_reg_neg; | 373 | goto error_disable_reg_pos; |
376 | 374 | ||
377 | ret = regulator_get_voltage(st->reg_vss); | 375 | ret = regulator_get_voltage(st->reg_vss); |
378 | if (ret < 0) | 376 | if (ret < 0) |
@@ -428,19 +426,9 @@ static int ad5791_probe(struct spi_device *spi) | |||
428 | error_disable_reg_neg: | 426 | error_disable_reg_neg: |
429 | if (!IS_ERR(st->reg_vss)) | 427 | if (!IS_ERR(st->reg_vss)) |
430 | regulator_disable(st->reg_vss); | 428 | regulator_disable(st->reg_vss); |
431 | error_put_reg_neg: | ||
432 | if (!IS_ERR(st->reg_vss)) | ||
433 | regulator_put(st->reg_vss); | ||
434 | |||
435 | error_disable_reg_pos: | 429 | error_disable_reg_pos: |
436 | if (!IS_ERR(st->reg_vdd)) | 430 | if (!IS_ERR(st->reg_vdd)) |
437 | regulator_disable(st->reg_vdd); | 431 | regulator_disable(st->reg_vdd); |
438 | error_put_reg_pos: | ||
439 | if (!IS_ERR(st->reg_vdd)) | ||
440 | regulator_put(st->reg_vdd); | ||
441 | iio_device_free(indio_dev); | ||
442 | error_ret: | ||
443 | |||
444 | return ret; | 432 | return ret; |
445 | } | 433 | } |
446 | 434 | ||
@@ -450,16 +438,11 @@ static int ad5791_remove(struct spi_device *spi) | |||
450 | struct ad5791_state *st = iio_priv(indio_dev); | 438 | struct ad5791_state *st = iio_priv(indio_dev); |
451 | 439 | ||
452 | iio_device_unregister(indio_dev); | 440 | iio_device_unregister(indio_dev); |
453 | if (!IS_ERR(st->reg_vdd)) { | 441 | if (!IS_ERR(st->reg_vdd)) |
454 | regulator_disable(st->reg_vdd); | 442 | regulator_disable(st->reg_vdd); |
455 | regulator_put(st->reg_vdd); | ||
456 | } | ||
457 | 443 | ||
458 | if (!IS_ERR(st->reg_vss)) { | 444 | if (!IS_ERR(st->reg_vss)) |
459 | regulator_disable(st->reg_vss); | 445 | regulator_disable(st->reg_vss); |
460 | regulator_put(st->reg_vss); | ||
461 | } | ||
462 | iio_device_free(indio_dev); | ||
463 | 446 | ||
464 | return 0; | 447 | return 0; |
465 | } | 448 | } |