Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: light: adjd_s311: Use iio_push_to_buffers_with_ts() to allow source size runtime check

Also move the structure used as the source to the stack as it is only 16
bytes and not the target of an DMA or similar.

Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Link: https://patch.msgid.link/20250802164436.515988-9-jic23@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

+6 -6
+6 -6
drivers/iio/light/adjd_s311.c
··· 54 54 55 55 struct adjd_s311_data { 56 56 struct i2c_client *client; 57 - struct { 58 - s16 chans[4]; 59 - aligned_s64 ts; 60 - } scan; 61 57 }; 62 58 63 59 enum adjd_s311_channel_idx { ··· 116 120 struct adjd_s311_data *data = iio_priv(indio_dev); 117 121 s64 time_ns = iio_get_time_ns(indio_dev); 118 122 int i, j = 0; 123 + struct { 124 + s16 chans[4]; 125 + aligned_s64 ts; 126 + } scan = { }; 119 127 120 128 int ret = adjd_s311_req_data(indio_dev); 121 129 if (ret < 0) ··· 131 131 if (ret < 0) 132 132 goto done; 133 133 134 - data->scan.chans[j++] = ret & ADJD_S311_DATA_MASK; 134 + scan.chans[j++] = ret & ADJD_S311_DATA_MASK; 135 135 } 136 136 137 - iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, time_ns); 137 + iio_push_to_buffers_with_ts(indio_dev, &scan, sizeof(scan), time_ns); 138 138 139 139 done: 140 140 iio_trigger_notify_done(indio_dev->trig);