iio: light: isl29125: fix iio_triggered_buffer_{predisable,postenable} positions
authorAlexandru Ardelean <alexandru.ardelean@analog.com>
Wed, 4 Mar 2020 08:24:25 +0000 (10:24 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 19 Apr 2020 15:56:41 +0000 (16:56 +0100)
The iio_triggered_buffer_{predisable,postenable} functions attach/detach
the poll functions.

For the predisable hook, the disable code should occur before detaching
the poll func, and for the postenable hook, the poll func should be
attached before the enable code.

This change reworks the predisable/postenable hooks so that the pollfunc is
attached/detached in the correct position.
It also balances the calls a bit, by grouping the preenable and the
iio_triggered_buffer_postenable() into a single
isl29125_buffer_postenable() function.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/light/isl29125.c

index e37894f0ae0b6ac8748f1479c657c9fbf8c00e87..95611f5eff01a892d7c66d2fef5ebaaa6bca9117 100644 (file)
@@ -213,13 +213,24 @@ static const struct iio_info isl29125_info = {
        .attrs = &isl29125_attribute_group,
 };
 
-static int isl29125_buffer_preenable(struct iio_dev *indio_dev)
+static int isl29125_buffer_postenable(struct iio_dev *indio_dev)
 {
        struct isl29125_data *data = iio_priv(indio_dev);
+       int err;
+
+       err = iio_triggered_buffer_postenable(indio_dev);
+       if (err)
+               return err;
 
        data->conf1 |= ISL29125_MODE_RGB;
-       return i2c_smbus_write_byte_data(data->client, ISL29125_CONF1,
+       err = i2c_smbus_write_byte_data(data->client, ISL29125_CONF1,
                data->conf1);
+       if (err) {
+               iio_triggered_buffer_predisable(indio_dev);
+               return err;
+       }
+
+       return 0;
 }
 
 static int isl29125_buffer_predisable(struct iio_dev *indio_dev)
@@ -227,19 +238,18 @@ static int isl29125_buffer_predisable(struct iio_dev *indio_dev)
        struct isl29125_data *data = iio_priv(indio_dev);
        int ret;
 
-       ret = iio_triggered_buffer_predisable(indio_dev);
-       if (ret < 0)
-               return ret;
-
        data->conf1 &= ~ISL29125_MODE_MASK;
        data->conf1 |= ISL29125_MODE_PD;
-       return i2c_smbus_write_byte_data(data->client, ISL29125_CONF1,
+       ret = i2c_smbus_write_byte_data(data->client, ISL29125_CONF1,
                data->conf1);
+
+       iio_triggered_buffer_predisable(indio_dev);
+
+       return ret;
 }
 
 static const struct iio_buffer_setup_ops isl29125_buffer_setup_ops = {
-       .preenable = isl29125_buffer_preenable,
-       .postenable = &iio_triggered_buffer_postenable,
+       .postenable = isl29125_buffer_postenable,
        .predisable = isl29125_buffer_predisable,
 };