Skip to content

Commit cae94ba

Browse files
dlechjic23
authored andcommitted
iio: imu: inv_icm42600: use = { } instead of memset()
Use { } instead of memset() to zero-initialize stack memory to simplify the code. Signed-off-by: David Lechner <dlechner@baylibre.com> Reviewed-by: Nuno Sá <nuno.sa@analog.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20250611-iio-zero-init-stack-with-instead-of-memset-v1-16-ebb2d0a24302@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 19a1d32 commit cae94ba

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,8 @@ int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev)
902902
const int8_t *temp;
903903
unsigned int odr;
904904
int64_t ts_val;
905-
struct inv_icm42600_accel_buffer buffer;
905+
/* buffer is copied to userspace, zeroing it to avoid any data leak */
906+
struct inv_icm42600_accel_buffer buffer = { };
906907

907908
/* parse all fifo packets */
908909
for (i = 0, no = 0; i < st->fifo.count; i += size, ++no) {
@@ -921,8 +922,6 @@ int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev)
921922
inv_sensors_timestamp_apply_odr(ts, st->fifo.period,
922923
st->fifo.nb.total, no);
923924

924-
/* buffer is copied to userspace, zeroing it to avoid any data leak */
925-
memset(&buffer, 0, sizeof(buffer));
926925
memcpy(&buffer.accel, accel, sizeof(buffer.accel));
927926
/* convert 8 bits FIFO temperature in high resolution format */
928927
buffer.temp = temp ? (*temp * 64) : 0;

drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@ int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev)
806806
const int8_t *temp;
807807
unsigned int odr;
808808
int64_t ts_val;
809-
struct inv_icm42600_gyro_buffer buffer;
809+
/* buffer is copied to userspace, zeroing it to avoid any data leak */
810+
struct inv_icm42600_gyro_buffer buffer = { };
810811

811812
/* parse all fifo packets */
812813
for (i = 0, no = 0; i < st->fifo.count; i += size, ++no) {
@@ -825,8 +826,6 @@ int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev)
825826
inv_sensors_timestamp_apply_odr(ts, st->fifo.period,
826827
st->fifo.nb.total, no);
827828

828-
/* buffer is copied to userspace, zeroing it to avoid any data leak */
829-
memset(&buffer, 0, sizeof(buffer));
830829
memcpy(&buffer.gyro, gyro, sizeof(buffer.gyro));
831830
/* convert 8 bits FIFO temperature in high resolution format */
832831
buffer.temp = temp ? (*temp * 64) : 0;

0 commit comments

Comments
 (0)