]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: imu: inv_icm42600: use = { } instead of memset()
authorDavid Lechner <dlechner@baylibre.com>
Mon, 20 Oct 2025 13:10:29 +0000 (09:10 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Oct 2025 13:03:13 +0000 (14:03 +0100)
[ 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: 466f7a2fef2a ("iio: imu: inv_icm42600: Avoid configuring if already pm_runtime suspended")
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 a394b667a3e5641d34884f69337292e973a0b9b9..4888a4c011c6a8670bd21004d490674078b4a107 100644 (file)
@@ -749,7 +749,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) {
@@ -768,8 +769,6 @@ int inv_icm42600_accel_parse_fifo(struct iio_dev *indio_dev)
                        inv_icm42600_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 22b7ccfa7f4f7e31d63883a31e0df99c12559a3f..c67cc20223b8b41d65288868baec0e28eb6ad20b 100644 (file)
@@ -761,7 +761,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) {
@@ -780,8 +781,6 @@ int inv_icm42600_gyro_parse_fifo(struct iio_dev *indio_dev)
                        inv_icm42600_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;