staging: iio: ad7816: Use devm_* APIs
authorSachin Kamat <sachin.kamat@linaro.org>
Sat, 31 Aug 2013 17:12:00 +0000 (18:12 +0100)
committerJonathan Cameron <jic23@kernel.org>
Sat, 7 Sep 2013 20:50:32 +0000 (21:50 +0100)
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>
drivers/staging/iio/adc/ad7816.c

index 8470036a3378cba40d787f1e45fcb0410bd5d676..9f48e5c74eed85c8f164208d4ddbaf4ed108dfb8 100644 (file)
@@ -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;
 }