iio: proximity: Use iio_push_to_buffers_with_ts() to provide length for runtime checks.
authorJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 13 Apr 2025 10:34:40 +0000 (11:34 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 21 May 2025 13:20:26 +0000 (14:20 +0100)
This new function allows us to perform debug checks in the helper to ensure
that the overrun does not occur. Use it in all the simple cases where
either a static buffer or a structure is used in the drivers.

Reviewed-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20250413103443.2420727-18-jic23@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/proximity/as3935.c
drivers/iio/proximity/hx9023s.c
drivers/iio/proximity/mb1232.c
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
drivers/iio/proximity/srf08.c
drivers/iio/proximity/sx_common.c
drivers/iio/proximity/vl53l0x-i2c.c

index d48d7b57287829f67950fc3551f6c8e410eff56a..f1018b14aecfd92497fe7b20eb4df2129529736d 100644 (file)
@@ -231,8 +231,8 @@ static irqreturn_t as3935_trigger_handler(int irq, void *private)
                goto err_read;
 
        st->scan.chan = val & AS3935_DATA_MASK;
-       iio_push_to_buffers_with_timestamp(indio_dev, &st->scan,
-                                          iio_get_time_ns(indio_dev));
+       iio_push_to_buffers_with_ts(indio_dev, &st->scan, sizeof(st->scan),
+                                   iio_get_time_ns(indio_dev));
 err_read:
        iio_trigger_notify_done(indio_dev->trig);
 
index f2037fd99a8d886f6bd780863c8236a919746f7e..33781c3147286fb3e2f022201ccf7e908d0b6b12 100644 (file)
@@ -953,8 +953,8 @@ static irqreturn_t hx9023s_trigger_handler(int irq, void *private)
                data->buffer.channels[i++] = cpu_to_le16(data->ch_data[index].diff);
        }
 
-       iio_push_to_buffers_with_timestamp(indio_dev, &data->buffer,
-                                          pf->timestamp);
+       iio_push_to_buffers_with_ts(indio_dev, &data->buffer,
+                                   sizeof(data->buffer), pf->timestamp);
 
 out:
        iio_trigger_notify_done(indio_dev->trig);
index 24524edae0b4adf9ef0f060605b922eb5e9097a0..01783486bc7df34ec3b38b1d0ad5f52e3eae6c92 100644 (file)
@@ -125,8 +125,8 @@ static irqreturn_t mb1232_trigger_handler(int irq, void *p)
        if (data->scan.distance < 0)
                goto err;
 
-       iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
-                                          pf->timestamp);
+       iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan),
+                                   pf->timestamp);
 
 err:
        iio_trigger_notify_done(indio_dev->trig);
index fbf9f851305599886d1434e923ef9d85fd02b54c..1deaf70e92ceb788ad8a5b82ea0bd1c28faadf1a 100644 (file)
@@ -238,8 +238,9 @@ static irqreturn_t lidar_trigger_handler(int irq, void *private)
 
        ret = lidar_get_measurement(data, &data->scan.chan);
        if (!ret) {
-               iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
-                                                  iio_get_time_ns(indio_dev));
+               iio_push_to_buffers_with_ts(indio_dev, &data->scan,
+                                           sizeof(data->scan),
+                                           iio_get_time_ns(indio_dev));
        } else if (ret != -EINVAL) {
                dev_err(&data->client->dev, "cannot read LIDAR measurement");
        }
index 940fad6aeaa4b4d714e2cc3c44ba0e1216633397..6e32fdfd161b93a5624f757d5b7de579415b1055 100644 (file)
@@ -191,8 +191,8 @@ static irqreturn_t srf08_trigger_handler(int irq, void *p)
        mutex_lock(&data->lock);
 
        data->scan.chan = sensor_data;
-       iio_push_to_buffers_with_timestamp(indio_dev,
-                                          &data->scan, pf->timestamp);
+       iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan),
+                                   pf->timestamp);
 
        mutex_unlock(&data->lock);
 err:
index f70198a1f0d1452b5ff210e35d5703beabd08799..59b35e40739b0d931dbac076ca5c83ba421ba766 100644 (file)
@@ -379,8 +379,8 @@ static irqreturn_t sx_common_trigger_handler(int irq, void *private)
                data->buffer.channels[i++] = val;
        }
 
-       iio_push_to_buffers_with_timestamp(indio_dev, &data->buffer,
-                                          pf->timestamp);
+       iio_push_to_buffers_with_ts(indio_dev, &data->buffer,
+                                   sizeof(data->buffer), pf->timestamp);
 
 out:
        mutex_unlock(&data->mutex);
index 87d10faaff9b11eb37d22a9372187425072976a7..ef4aa7b2835e3c9e177f3e03b24a141ac45c3825 100644 (file)
@@ -94,8 +94,8 @@ static irqreturn_t vl53l0x_trigger_handler(int irq, void *priv)
                return -EREMOTEIO;
 
        data->scan.chan = get_unaligned_be16(&buffer[10]);
-       iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
-                                       iio_get_time_ns(indio_dev));
+       iio_push_to_buffers_with_ts(indio_dev, &data->scan, sizeof(data->scan),
+                                   iio_get_time_ns(indio_dev));
 
        iio_trigger_notify_done(indio_dev->trig);
        vl53l0x_clear_irq(data);