]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: mpl3115: add separate function for triggered buffer data collection
authorAntoni Pokusinski <apokusinski01@gmail.com>
Thu, 2 Oct 2025 20:02:03 +0000 (22:02 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 19 Oct 2025 10:59:16 +0000 (11:59 +0100)
Factor out the code responsible for collecting data for the triggered
buffer from the trigger handler into a separate function.

Signed-off-by: Antoni Pokusinski <apokusinski01@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/pressure/mpl3115.c

index 579da60ef441482a82f3bdf4f67436a13ab3e09d..1da78081ca7eb4f3732f020de5d59194e8f81324 100644 (file)
@@ -148,47 +148,53 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
        return -EINVAL;
 }
 
-static irqreturn_t mpl3115_trigger_handler(int irq, void *p)
+static int mpl3115_fill_trig_buffer(struct iio_dev *indio_dev, u8 *buffer)
 {
-       struct iio_poll_func *pf = p;
-       struct iio_dev *indio_dev = pf->indio_dev;
        struct mpl3115_data *data = iio_priv(indio_dev);
-       /*
-        * 32-bit channel + 16-bit channel + padding + ts
-        * Note that it is possible for only one of the first 2
-        * channels to be enabled. If that happens, the first element
-        * of the buffer may be either 16 or 32-bits.  As such we cannot
-        * use a simple structure definition to express this data layout.
-        */
-       u8 buffer[16] __aligned(8) = { };
        int ret, pos = 0;
 
-       mutex_lock(&data->lock);
        ret = mpl3115_request(data);
-       if (ret < 0) {
-               mutex_unlock(&data->lock);
-               goto done;
-       }
+       if (ret < 0)
+               return ret;
 
        if (test_bit(0, indio_dev->active_scan_mask)) {
                ret = i2c_smbus_read_i2c_block_data(data->client,
                        MPL3115_OUT_PRESS, 3, &buffer[pos]);
-               if (ret < 0) {
-                       mutex_unlock(&data->lock);
-                       goto done;
-               }
+               if (ret < 0)
+                       return ret;
                pos += 4;
        }
 
        if (test_bit(1, indio_dev->active_scan_mask)) {
                ret = i2c_smbus_read_i2c_block_data(data->client,
                        MPL3115_OUT_TEMP, 2, &buffer[pos]);
-               if (ret < 0) {
-                       mutex_unlock(&data->lock);
-                       goto done;
-               }
+               if (ret < 0)
+                       return ret;
        }
+
+       return 0;
+}
+
+static irqreturn_t mpl3115_trigger_handler(int irq, void *p)
+{
+       struct iio_poll_func *pf = p;
+       struct iio_dev *indio_dev = pf->indio_dev;
+       struct mpl3115_data *data = iio_priv(indio_dev);
+       /*
+        * 32-bit channel + 16-bit channel + padding + ts
+        * Note that it is possible for only one of the first 2
+        * channels to be enabled. If that happens, the first element
+        * of the buffer may be either 16 or 32-bits.  As such we cannot
+        * use a simple structure definition to express this data layout.
+        */
+       u8 buffer[16] __aligned(8) = { };
+       int ret;
+
+       mutex_lock(&data->lock);
+       ret = mpl3115_fill_trig_buffer(indio_dev, buffer);
        mutex_unlock(&data->lock);
+       if (ret)
+               goto done;
 
        iio_push_to_buffers_with_ts(indio_dev, buffer, sizeof(buffer),
                                    iio_get_time_ns(indio_dev));