]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
iio:pressure:ms5611: fix missing regulator_disable
authorGregor Boirie <gregor.boirie@parrot.com>
Thu, 17 Mar 2016 11:55:03 +0000 (12:55 +0100)
committerJonathan Cameron <jic23@kernel.org>
Sun, 20 Mar 2016 11:02:40 +0000 (11:02 +0000)
Ensure optional regulator is properly disabled when present.

Fixes: 3145229f9191 ("iio:pressure:ms5611: power regulator support")
Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/pressure/ms5611.h
drivers/iio/pressure/ms5611_core.c

index d725a3077a178a49f181738fe5d8685d2770ea6e..ccda63c5b3c34191a3e8dc65e505ff3d11af7a64 100644 (file)
@@ -16,6 +16,8 @@
 #include <linux/iio/iio.h>
 #include <linux/mutex.h>
 
+struct regulator;
+
 #define MS5611_RESET                   0x1e
 #define MS5611_READ_ADC                        0x00
 #define MS5611_READ_PROM_WORD          0xA0
@@ -57,6 +59,7 @@ struct ms5611_state {
                                          s32 *temp, s32 *pressure);
 
        struct ms5611_chip_info *chip_info;
+       struct regulator *vdd;
 };
 
 int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
index 37dbc0401599848e67e5e40e25dd714bcd0178cd..c4e65868bc28409418a5bf29d3adc4af5713d98c 100644 (file)
@@ -387,24 +387,45 @@ static const struct iio_info ms5611_info = {
 static int ms5611_init(struct iio_dev *indio_dev)
 {
        int ret;
-       struct regulator *vdd = devm_regulator_get(indio_dev->dev.parent,
-                                                  "vdd");
+       struct ms5611_state *st = iio_priv(indio_dev);
 
        /* Enable attached regulator if any. */
-       if (!IS_ERR(vdd)) {
-               ret = regulator_enable(vdd);
+       st->vdd = devm_regulator_get(indio_dev->dev.parent, "vdd");
+       if (!IS_ERR(st->vdd)) {
+               ret = regulator_enable(st->vdd);
                if (ret) {
                        dev_err(indio_dev->dev.parent,
-                               "failed to enable Vdd supply: %d\n", ret);
+                               "failed to enable Vdd supply: %d\n", ret);
                        return ret;
                }
+       } else {
+               ret = PTR_ERR(st->vdd);
+               if (ret != -ENODEV)
+                       return ret;
        }
 
        ret = ms5611_reset(indio_dev);
        if (ret < 0)
-               return ret;
+               goto err_regulator_disable;
+
+       ret = ms5611_read_prom(indio_dev);
+       if (ret < 0)
+               goto err_regulator_disable;
+
+       return 0;
 
-       return ms5611_read_prom(indio_dev);
+err_regulator_disable:
+       if (!IS_ERR_OR_NULL(st->vdd))
+               regulator_disable(st->vdd);
+       return ret;
+}
+
+static void ms5611_fini(const struct iio_dev *indio_dev)
+{
+       const struct ms5611_state *st = iio_priv(indio_dev);
+
+       if (!IS_ERR_OR_NULL(st->vdd))
+               regulator_disable(st->vdd);
 }
 
 int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
@@ -436,7 +457,7 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
                                         ms5611_trigger_handler, NULL);
        if (ret < 0) {
                dev_err(dev, "iio triggered buffer setup failed\n");
-               return ret;
+               goto err_fini;
        }
 
        ret = iio_device_register(indio_dev);
@@ -449,7 +470,8 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
 
 err_buffer_cleanup:
        iio_triggered_buffer_cleanup(indio_dev);
-
+err_fini:
+       ms5611_fini(indio_dev);
        return ret;
 }
 EXPORT_SYMBOL(ms5611_probe);
@@ -458,6 +480,7 @@ int ms5611_remove(struct iio_dev *indio_dev)
 {
        iio_device_unregister(indio_dev);
        iio_triggered_buffer_cleanup(indio_dev);
+       ms5611_fini(indio_dev);
 
        return 0;
 }