From: Jonathan Cameron Date: Sun, 13 Apr 2025 10:34:39 +0000 (+0100) Subject: iio: proximity: irsd200: Use a struct for scan and iio_push_to_buffers_with_ts() X-Git-Tag: v6.16-rc1~30^2~4^2~76 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=175c3f72154e4ef64ba56b0ee35110082ea475b4;p=linux-block.git iio: proximity: irsd200: Use a struct for scan and iio_push_to_buffers_with_ts() The driver previously used an array of two s64, then type cast the pointer to write an s16 to the start. The code is made more readable using a structure. At the same time switch to the new iio_push_to_buffers_with_ts() helper to enable runtime checking of the size of the source buffer. Note that this approach uses a structure with holes, so use memset() to ensure those do not contain old kernel data as this data is passed to userspace. Reviewed-by: David Lechner Link: https://patch.msgid.link/20250413103443.2420727-17-jic23@kernel.org Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/proximity/irsd200.c b/drivers/iio/proximity/irsd200.c index 1b1b6dfdfa78..0d30b91dbcbc 100644 --- a/drivers/iio/proximity/irsd200.c +++ b/drivers/iio/proximity/irsd200.c @@ -760,15 +760,19 @@ static irqreturn_t irsd200_trigger_handler(int irq, void *pollf) { struct iio_dev *indio_dev = ((struct iio_poll_func *)pollf)->indio_dev; struct irsd200_data *data = iio_priv(indio_dev); - s64 buf[2] = {}; + struct { + s16 channel; + aligned_s64 ts; + } scan; int ret; - ret = irsd200_read_data(data, (s16 *)buf); + memset(&scan, 0, sizeof(scan)); + ret = irsd200_read_data(data, &scan.channel); if (ret) goto end; - iio_push_to_buffers_with_timestamp(indio_dev, buf, - iio_get_time_ns(indio_dev)); + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), + iio_get_time_ns(indio_dev)); end: iio_trigger_notify_done(indio_dev->trig);