From e5bf4f5b7d95ff7e6359df7845047dd9e6df6f3e Mon Sep 17 00:00:00 2001 From: Sachin Kamat Date: Sat, 31 Aug 2013 18:12:00 +0100 Subject: [PATCH] staging: iio: ad7816: Use devm_* APIs devm_* APIs are device managed and make code simpler. Signed-off-by: Sachin Kamat Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7816.c | 59 +++++++++++--------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c index 8470036a3378..9f48e5c74eed 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -356,11 +356,9 @@ static int ad7816_probe(struct spi_device *spi_dev) return -EINVAL; } - indio_dev = iio_device_alloc(sizeof(*chip)); - if (indio_dev == NULL) { - ret = -ENOMEM; - goto error_ret; - } + indio_dev = devm_iio_device_alloc(&spi_dev->dev, sizeof(*chip)); + if (!indio_dev) + return -ENOMEM; chip = iio_priv(indio_dev); /* this is only used for device removal purposes */ dev_set_drvdata(&spi_dev->dev, indio_dev); @@ -372,25 +370,28 @@ static int ad7816_probe(struct spi_device *spi_dev) chip->convert_pin = pins[1]; chip->busy_pin = pins[2]; - ret = gpio_request(chip->rdwr_pin, spi_get_device_id(spi_dev)->name); + ret = devm_gpio_request(&spi_dev->dev, chip->rdwr_pin, + spi_get_device_id(spi_dev)->name); if (ret) { dev_err(&spi_dev->dev, "Fail to request rdwr gpio PIN %d.\n", chip->rdwr_pin); - goto error_free_device; + return ret; } gpio_direction_input(chip->rdwr_pin); - ret = gpio_request(chip->convert_pin, spi_get_device_id(spi_dev)->name); + ret = devm_gpio_request(&spi_dev->dev, chip->convert_pin, + spi_get_device_id(spi_dev)->name); if (ret) { dev_err(&spi_dev->dev, "Fail to request convert gpio PIN %d.\n", chip->convert_pin); - goto error_free_gpio_rdwr; + return ret; } gpio_direction_input(chip->convert_pin); - ret = gpio_request(chip->busy_pin, spi_get_device_id(spi_dev)->name); + ret = devm_gpio_request(&spi_dev->dev, chip->busy_pin, + spi_get_device_id(spi_dev)->name); if (ret) { dev_err(&spi_dev->dev, "Fail to request busy gpio PIN %d.\n", chip->busy_pin); - goto error_free_gpio_convert; + return ret; } gpio_direction_input(chip->busy_pin); @@ -401,51 +402,31 @@ static int ad7816_probe(struct spi_device *spi_dev) if (spi_dev->irq) { /* Only low trigger is supported in ad7816/7/8 */ - ret = request_threaded_irq(spi_dev->irq, - NULL, - &ad7816_event_handler, - IRQF_TRIGGER_LOW | IRQF_ONESHOT, - indio_dev->name, - indio_dev); + ret = devm_request_threaded_irq(&spi_dev->dev, spi_dev->irq, + NULL, + &ad7816_event_handler, + IRQF_TRIGGER_LOW | IRQF_ONESHOT, + indio_dev->name, + indio_dev); if (ret) - goto error_free_gpio; + return ret; } ret = iio_device_register(indio_dev); if (ret) - goto error_free_irq; + return ret; dev_info(&spi_dev->dev, "%s temperature sensor and ADC registered.\n", indio_dev->name); return 0; -error_free_irq: - free_irq(spi_dev->irq, indio_dev); -error_free_gpio: - gpio_free(chip->busy_pin); -error_free_gpio_convert: - gpio_free(chip->convert_pin); -error_free_gpio_rdwr: - gpio_free(chip->rdwr_pin); -error_free_device: - iio_device_free(indio_dev); -error_ret: - return ret; } static int ad7816_remove(struct spi_device *spi_dev) { struct iio_dev *indio_dev = dev_get_drvdata(&spi_dev->dev); - struct ad7816_chip_info *chip = iio_priv(indio_dev); iio_device_unregister(indio_dev); - dev_set_drvdata(&spi_dev->dev, NULL); - if (spi_dev->irq) - free_irq(spi_dev->irq, indio_dev); - gpio_free(chip->busy_pin); - gpio_free(chip->convert_pin); - gpio_free(chip->rdwr_pin); - iio_device_free(indio_dev); return 0; } -- 2.20.1