[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250614132150.6f4a29a3@jic23-huawei>
Date: Sat, 14 Jun 2025 13:21:50 +0100
From: Jonathan Cameron <jic23@...nel.org>
To: David Lechner <dlechner@...libre.com>
Cc: Michael Hennerich <michael.hennerich@...log.com>, Lars-Peter Clausen
<lars@...afoo.de>, Nuno Sá <nuno.sa@...log.com>, Andy
Shevchenko <andy@...nel.org>, Matthias Brugger <matthias.bgg@...il.com>,
AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>, Heiko
Stuebner <heiko@...ech.de>, Maxime Coquelin <mcoquelin.stm32@...il.com>,
Alexandre Torgue <alexandre.torgue@...s.st.com>, Francesco Dolcini
<francesco@...cini.it>, João Paulo Gonçalves <jpaulo.silvagoncalves@...il.com>, Leonard
Göhrs <l.goehrs@...gutronix.de>, kernel@...gutronix.de,
Oleksij Rempel <o.rempel@...gutronix.de>, Roan van Dijk <roan@...tonic.nl>,
Tomasz Duszynski <tomasz.duszynski@...akon.com>, Jacopo Mondi
<jacopo@...ndi.org>, Jean-Baptiste Maneyrol
<jean-baptiste.maneyrol@....com>, Mudit Sharma
<muditsharma.info@...il.com>, Javier Carrasco
<javier.carrasco.cruz@...il.com>, Ondřej Jirman
<megi@....cz>, Andreas Klinger <ak@...klinger.de>, Petre Rodan
<petre.rodan@...dimension.ro>, linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-mediatek@...ts.infradead.org, linux-rockchip@...ts.infradead.org,
linux-stm32@...md-mailman.stormreply.com
Subject: Re: [PATCH 16/28] iio: imu: inv_icm42600: use = { } instead of
memset()
On Wed, 11 Jun 2025 17:39:08 -0500
David Lechner <dlechner@...libre.com> wrote:
> Use { } instead of memset() to zero-initialize stack memory to simplify
> the code.
This one isn't as obvious as many as the zeroing was in a loop
and now it's at declaration.
It's fine because we always copy over the same elements.
I'll leave this whole series a little longer in case we are missing
subtle cases like this. (but ones where it actually does make a difference!)
Jonathan
>
> Signed-off-by: David Lechner <dlechner@...libre.com>
> ---
> drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c | 5 ++---
> drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c | 5 ++---
> 2 files changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
> index e6cd9dcb0687d19554e63a69dc60f065c58d70ee..dbd315ad3c4d2bd5085f7cd3cdc6de4391b1c896 100644
> --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
> +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
> @@ -902,7 +902,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) {
> @@ -921,8 +922,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;
> diff --git a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
> index b4d7ce1432a4f4d096599877040a89ede0625e0b..4058eca076d8b03a2290535eedffa0a74098d739 100644
> --- a/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
> +++ b/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
> @@ -806,7 +806,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) {
> @@ -825,8 +826,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;
>
Powered by blists - more mailing lists