iio: st_sensors: remove st_sensors_power_disable() function
authorAlexandru Ardelean <aardelean@deviqon.com>
Mon, 23 Aug 2021 11:22:02 +0000 (14:22 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 14 Sep 2021 11:00:31 +0000 (12:00 +0100)
This change converts the st_sensors_power_enable() function to use
devm_add_action_or_reset() handlers to register regulator_disable hooks for
when the drivers get unloaded.

The parent device of the IIO device object is used. This is based on the
assumption that all other devm_ calls in the ST sensors use this reference.

This makes the st_sensors_power_disable() un-needed.
Removing this also changes unload order a bit, as all ST drivers would call
st_sensors_power_disable() first and iio_device_unregister() after that.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20210823112204.243255-4-aardelean@deviqon.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/accel/st_accel_i2c.c
drivers/iio/accel/st_accel_spi.c
drivers/iio/common/st_sensors/st_sensors_core.c
drivers/iio/gyro/st_gyro_i2c.c
drivers/iio/gyro/st_gyro_spi.c
drivers/iio/magnetometer/st_magn_i2c.c
drivers/iio/magnetometer/st_magn_spi.c
drivers/iio/pressure/st_pressure_i2c.c
drivers/iio/pressure/st_pressure_spi.c
include/linux/iio/common/st_sensors.h

index cba5745..b377575 100644 (file)
@@ -177,16 +177,7 @@ static int st_accel_i2c_probe(struct i2c_client *client)
        if (ret)
                return ret;
 
-       ret = st_accel_common_probe(indio_dev);
-       if (ret < 0)
-               goto st_accel_power_off;
-
-       return 0;
-
-st_accel_power_off:
-       st_sensors_power_disable(indio_dev);
-
-       return ret;
+       return st_accel_common_probe(indio_dev);
 }
 
 static int st_accel_i2c_remove(struct i2c_client *client)
@@ -195,8 +186,6 @@ static int st_accel_i2c_remove(struct i2c_client *client)
 
        st_accel_common_remove(indio_dev);
 
-       st_sensors_power_disable(indio_dev);
-
        return 0;
 }
 
index 5167fae..4ca87e7 100644 (file)
@@ -127,16 +127,7 @@ static int st_accel_spi_probe(struct spi_device *spi)
        if (err)
                return err;
 
-       err = st_accel_common_probe(indio_dev);
-       if (err < 0)
-               goto st_accel_power_off;
-
-       return 0;
-
-st_accel_power_off:
-       st_sensors_power_disable(indio_dev);
-
-       return err;
+       return st_accel_common_probe(indio_dev);
 }
 
 static int st_accel_spi_remove(struct spi_device *spi)
@@ -145,8 +136,6 @@ static int st_accel_spi_remove(struct spi_device *spi)
 
        st_accel_common_remove(indio_dev);
 
-       st_sensors_power_disable(indio_dev);
-
        return 0;
 }
 
index 0bbb090..a5a140d 100644 (file)
@@ -215,13 +215,19 @@ int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable)
 }
 EXPORT_SYMBOL(st_sensors_set_axis_enable);
 
+static void st_reg_disable(void *reg)
+{
+       regulator_disable(reg);
+}
+
 int st_sensors_power_enable(struct iio_dev *indio_dev)
 {
        struct st_sensor_data *pdata = iio_priv(indio_dev);
+       struct device *parent = indio_dev->dev.parent;
        int err;
 
        /* Regulators not mandatory, but if requested we should enable them. */
-       pdata->vdd = devm_regulator_get(indio_dev->dev.parent, "vdd");
+       pdata->vdd = devm_regulator_get(parent, "vdd");
        if (IS_ERR(pdata->vdd)) {
                dev_err(&indio_dev->dev, "unable to get Vdd supply\n");
                return PTR_ERR(pdata->vdd);
@@ -233,36 +239,26 @@ int st_sensors_power_enable(struct iio_dev *indio_dev)
                return err;
        }
 
-       pdata->vdd_io = devm_regulator_get(indio_dev->dev.parent, "vddio");
+       err = devm_add_action_or_reset(parent, st_reg_disable, pdata->vdd);
+       if (err)
+               return err;
+
+       pdata->vdd_io = devm_regulator_get(parent, "vddio");
        if (IS_ERR(pdata->vdd_io)) {
                dev_err(&indio_dev->dev, "unable to get Vdd_IO supply\n");
-               err = PTR_ERR(pdata->vdd_io);
-               goto st_sensors_disable_vdd;
+               return PTR_ERR(pdata->vdd_io);
        }
        err = regulator_enable(pdata->vdd_io);
        if (err != 0) {
                dev_warn(&indio_dev->dev,
                         "Failed to enable specified Vdd_IO supply\n");
-               goto st_sensors_disable_vdd;
+               return err;
        }
 
-       return 0;
-
-st_sensors_disable_vdd:
-       regulator_disable(pdata->vdd);
-       return err;
+       return devm_add_action_or_reset(parent, st_reg_disable, pdata->vdd_io);
 }
 EXPORT_SYMBOL(st_sensors_power_enable);
 
-void st_sensors_power_disable(struct iio_dev *indio_dev)
-{
-       struct st_sensor_data *pdata = iio_priv(indio_dev);
-
-       regulator_disable(pdata->vdd);
-       regulator_disable(pdata->vdd_io);
-}
-EXPORT_SYMBOL(st_sensors_power_disable);
-
 static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev,
                                        struct st_sensors_platform_data *pdata)
 {
index a8164fe..0bd80df 100644 (file)
@@ -90,16 +90,7 @@ static int st_gyro_i2c_probe(struct i2c_client *client,
        if (err)
                return err;
 
-       err = st_gyro_common_probe(indio_dev);
-       if (err < 0)
-               goto st_gyro_power_off;
-
-       return 0;
-
-st_gyro_power_off:
-       st_sensors_power_disable(indio_dev);
-
-       return err;
+       return st_gyro_common_probe(indio_dev);
 }
 
 static int st_gyro_i2c_remove(struct i2c_client *client)
@@ -108,8 +99,6 @@ static int st_gyro_i2c_remove(struct i2c_client *client)
 
        st_gyro_common_remove(indio_dev);
 
-       st_sensors_power_disable(indio_dev);
-
        return 0;
 }
 
index 9d89168..f74b09f 100644 (file)
@@ -94,16 +94,7 @@ static int st_gyro_spi_probe(struct spi_device *spi)
        if (err)
                return err;
 
-       err = st_gyro_common_probe(indio_dev);
-       if (err < 0)
-               goto st_gyro_power_off;
-
-       return 0;
-
-st_gyro_power_off:
-       st_sensors_power_disable(indio_dev);
-
-       return err;
+       return st_gyro_common_probe(indio_dev);
 }
 
 static int st_gyro_spi_remove(struct spi_device *spi)
@@ -112,8 +103,6 @@ static int st_gyro_spi_remove(struct spi_device *spi)
 
        st_gyro_common_remove(indio_dev);
 
-       st_sensors_power_disable(indio_dev);
-
        return 0;
 }
 
index fa78f0a..0a5117d 100644 (file)
@@ -86,16 +86,7 @@ static int st_magn_i2c_probe(struct i2c_client *client,
        if (err)
                return err;
 
-       err = st_magn_common_probe(indio_dev);
-       if (err < 0)
-               goto st_magn_power_off;
-
-       return 0;
-
-st_magn_power_off:
-       st_sensors_power_disable(indio_dev);
-
-       return err;
+       return st_magn_common_probe(indio_dev);
 }
 
 static int st_magn_i2c_remove(struct i2c_client *client)
@@ -104,8 +95,6 @@ static int st_magn_i2c_remove(struct i2c_client *client)
 
        st_magn_common_remove(indio_dev);
 
-       st_sensors_power_disable(indio_dev);
-
        return 0;
 }
 
index ff43cbf..1f3bf02 100644 (file)
@@ -80,16 +80,7 @@ static int st_magn_spi_probe(struct spi_device *spi)
        if (err)
                return err;
 
-       err = st_magn_common_probe(indio_dev);
-       if (err < 0)
-               goto st_magn_power_off;
-
-       return 0;
-
-st_magn_power_off:
-       st_sensors_power_disable(indio_dev);
-
-       return err;
+       return st_magn_common_probe(indio_dev);
 }
 
 static int st_magn_spi_remove(struct spi_device *spi)
@@ -98,8 +89,6 @@ static int st_magn_spi_remove(struct spi_device *spi)
 
        st_magn_common_remove(indio_dev);
 
-       st_sensors_power_disable(indio_dev);
-
        return 0;
 }
 
index 6215de6..afeeab4 100644 (file)
@@ -103,16 +103,7 @@ static int st_press_i2c_probe(struct i2c_client *client,
        if (ret)
                return ret;
 
-       ret = st_press_common_probe(indio_dev);
-       if (ret < 0)
-               goto st_press_power_off;
-
-       return 0;
-
-st_press_power_off:
-       st_sensors_power_disable(indio_dev);
-
-       return ret;
+       return st_press_common_probe(indio_dev);
 }
 
 static int st_press_i2c_remove(struct i2c_client *client)
@@ -121,8 +112,6 @@ static int st_press_i2c_remove(struct i2c_client *client)
 
        st_press_common_remove(indio_dev);
 
-       st_sensors_power_disable(indio_dev);
-
        return 0;
 }
 
index 5001aae..834ad6d 100644 (file)
@@ -86,16 +86,7 @@ static int st_press_spi_probe(struct spi_device *spi)
        if (err)
                return err;
 
-       err = st_press_common_probe(indio_dev);
-       if (err < 0)
-               goto st_press_power_off;
-
-       return 0;
-
-st_press_power_off:
-       st_sensors_power_disable(indio_dev);
-
-       return err;
+       return st_press_common_probe(indio_dev);
 }
 
 static int st_press_spi_remove(struct spi_device *spi)
@@ -104,8 +95,6 @@ static int st_press_spi_remove(struct spi_device *spi)
 
        st_press_common_remove(indio_dev);
 
-       st_sensors_power_disable(indio_dev);
-
        return 0;
 }
 
index e74b552..fc90c20 100644 (file)
@@ -293,8 +293,6 @@ int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable);
 
 int st_sensors_power_enable(struct iio_dev *indio_dev);
 
-void st_sensors_power_disable(struct iio_dev *indio_dev);
-
 int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev,
                                  unsigned reg, unsigned writeval,
                                  unsigned *readval);