]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: imu: inv_icm42600: use = { } instead of memset()
authorDavid Lechner <dlechner@baylibre.com>
Sun, 24 Aug 2025 13:53:25 +0000 (09:53 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:28:47 +0000 (16:28 +0200)
[ Upstream commit 352112e2d9aab6a156c2803ae14eb89a9fd93b7d ]

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>
Stable-dep-of: dfdc31e7ccf3 ("iio: imu: inv_icm42600: change invalid data error to -EBUSY")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c

index 6f44c03bbe5ae15303039b0047f1792ce84cc50c..5b6b6cb996f7a8ff3e5f55132faa174ca0771c3f 100644 (file)
@@ -755,7 +755,8 @@ int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev)
        const int8_t *temp;
        unsigned int odr;
        int64_t ts_val;
-       struct inv_icm42600_accel_buffer buffer;
+       /* buffer is copied to userspace, zeroing it to avoid any data leak */
+       struct inv_icm42600_accel_buffer buffer = { };
 
        /* parse all fifo packets */
        for (i = 0, no = 0; i < st->fifo.count; i += size, ++no) {
@@ -774,8 +775,6 @@ int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev)
                        inv_sensors_timestamp_apply_odr(ts, st->fifo.period,
                                                        st->fifo.nb.total, no);
 
-               /* buffer is copied to userspace, zeroing it to avoid any data leak */
-               memset(&buffer, 0, sizeof(buffer));
                memcpy(&buffer.accel, accel, sizeof(buffer.accel));
                /* convert 8 bits FIFO temperature in high resolution format */
                buffer.temp = temp ? (*temp * 64) : 0;
index 94f712c306087dddf622d3684e9dedb6976b9399..3e9bfa73a4f35954ced8d0ad1bef005b0f39ffce 100644 (file)
@@ -767,7 +767,8 @@ int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev)
        const int8_t *temp;
        unsigned int odr;
        int64_t ts_val;
-       struct inv_icm42600_gyro_buffer buffer;
+       /* buffer is copied to userspace, zeroing it to avoid any data leak */
+       struct inv_icm42600_gyro_buffer buffer = { };
 
        /* parse all fifo packets */
        for (i = 0, no = 0; i < st->fifo.count; i += size, ++no) {
@@ -786,8 +787,6 @@ int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev)
                        inv_sensors_timestamp_apply_odr(ts, st->fifo.period,
                                                        st->fifo.nb.total, no);
 
-               /* buffer is copied to userspace, zeroing it to avoid any data leak */
-               memset(&buffer, 0, sizeof(buffer));
                memcpy(&buffer.gyro, gyro, sizeof(buffer.gyro));
                /* convert 8 bits FIFO temperature in high resolution format */
                buffer.temp = temp ? (*temp * 64) : 0;