Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chris Morgan" <macroalpha82@gmail.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH V8 06/10] iio: imu: inv_icm42607: Add Buffer support for icm42607
Date: Mon, 18 May 2026 20:56:20 +0000	[thread overview]
Message-ID: <20260518205620.C802CC2BCB7@smtp.kernel.org> (raw)
In-Reply-To: <20260518200526.458421-7-macroalpha82@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] inv_icm42607_buffer_set_fifo_en() writes an invalid state to the FIFO mode register when disabling the last sensor, clobbering the bypass mode.
- [High] Unaligned memory accesses when dereferencing packed struct members trigger kernel panics on strict-alignment architectures.
- [Medium] Teardown state variables are not unconditionally cleared on error paths, causing permanent buffer desynchronization.
--

commit 741f353925a2f661ebf37513ef1196056f86f563
Author: Chris Morgan <macromorgan@hotmail.com>

iio: imu: inv_icm42607: Add Buffer support for icm42607

This commit adds FIFO parsing and reading functions to support the
buffer in the inv_icm42607 driver.

> diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_buffer.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_buffer.c
> new file mode 100644
> index 0000000000000..a011f1f728b98
> --- /dev/null
> +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_buffer.c

[ ... ]

> +struct inv_icm42607_fifo_1sensor_packet {
> +	u8 header;
> +	struct inv_icm42607_fifo_sensor_data data;
> +	s8 temp;
> +} __packed;

[ ... ]

> +ssize_t inv_icm42607_fifo_decode_packet(const void *packet, const void **accel,
> +					const void **gyro, const int8_t **temp,
> +					const void **timestamp)
> +{
> +	const struct inv_icm42607_fifo_1sensor_packet *pack1 = packet;

[ ... ]

> +	/* accel only */
> +	if (header & INV_ICM42607_FIFO_HEADER_ACCEL) {
> +		*accel = &pack1->data;

Could this pointer assignment lead to an alignment fault on strict-alignment
architectures?

Because struct inv_icm42607_fifo_1sensor_packet is marked __packed and
starts with a u8, the data member sits at an odd byte offset. This unaligned
address is assigned to accel, which is later passed to
inv_icm42607_fifo_is_data_valid() where it expects a naturally aligned
struct inv_icm42607_fifo_sensor_data pointer.

Dereferencing this pointer could trigger kernel panics on architectures
that strictly enforce alignment.

> +		*gyro = NULL;
> +		*temp = &pack1->temp;
> +		*timestamp = NULL;
> +		return INV_ICM42607_FIFO_1SENSOR_PACKET_SIZE;
> +	}

[ ... ]

> +int inv_icm42607_buffer_set_fifo_en(struct inv_icm42607_state *st,
> +				    unsigned int fifo_en)
> +{
> +	unsigned int val;
> +	int ret;
> +
> +	/* update FIFO EN bits for accel and gyro */
> +	val = 0;
> +	if (fifo_en & INV_ICM42607_SENSOR_GYRO)
> +		val |= INV_ICM42607_FIFO_CONFIG1_MODE;
> +	if (fifo_en & INV_ICM42607_SENSOR_ACCEL)
> +		val |= INV_ICM42607_FIFO_CONFIG1_MODE;
> +	if (fifo_en & INV_ICM42607_SENSOR_TEMP)
> +		val |= INV_ICM42607_FIFO_CONFIG1_MODE;
> +
> +	ret = regmap_write(st->map, INV_ICM42607_REG_FIFO_CONFIG1, val);

Could this write an invalid state when disabling the last sensor?

If fifo_en is 0, val evaluates to 0 and is directly written to the FIFO
mode register. However, the correct disabled state for this register appears
to be INV_ICM42607_FIFO_CONFIG1_BYPASS.

Writing 0 might overwrite the bypass mode and leave the FIFO in an unspecified
state. It also looks like INV_ICM42607_FIFO_CONFIG1_MODE is redundantly ORed
multiple times for each active sensor.

> +	if (ret)
> +		return ret;
> +
> +	st->fifo.en = fifo_en;
> +	inv_icm42607_buffer_update_fifo_period(st);
> +
> +	return 0;
> +}

[ ... ]

> +static int inv_icm42607_buffer_predisable(struct iio_dev *indio_dev)
> +{
> +	struct inv_icm42607_state *st = iio_device_get_drvdata(indio_dev);
> +	int ret;
> +
> +	guard(mutex)(&st->lock);
> +
> +	if (st->fifo.on > 1) {
> +		st->fifo.on--;
> +		return 0;
> +	}
> +
> +	/* set FIFO in bypass mode */
> +	ret = regmap_write(st->map, INV_ICM42607_REG_FIFO_CONFIG1,
> +			   INV_ICM42607_FIFO_CONFIG1_BYPASS);
> +	if (ret)
> +		return ret;

Could returning early here leave the driver state permanently desynchronized?

If this or the subsequent operations fail, the function returns early and
st->fifo.on is never reset to 0. Since the IIO core ignores teardown
errors and considers the buffer disabled anyway, a subsequent call to
inv_icm42607_buffer_postenable() will see st->fifo.on > 0, assume the
hardware is already fully initialized, and skip programming the hardware.

This would leave the hardware permanently disabled while the software thinks
it is streaming, leading to silent data loss.

> +
> +	/* flush FIFO data */
> +	ret = regmap_write(st->map, INV_ICM42607_REG_SIGNAL_PATH_RESET,
> +			   INV_ICM42607_SIGNAL_PATH_RESET_FIFO_FLUSH);
> +	if (ret)
> +		return ret;

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260518200526.458421-1-macroalpha82@gmail.com?part=6

  reply	other threads:[~2026-05-18 20:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-18 20:05 [PATCH V8 00/10] Add Invensense ICM42607 Chris Morgan
2026-05-18 20:05 ` [PATCH V8 01/10] dt-bindings: iio: imu: icm42600: Add mount-matrix to icm42600 Chris Morgan
2026-05-18 20:05 ` [PATCH V8 02/10] dt-bindings: iio: imu: icm42600: Add icm42607 binding Chris Morgan
2026-05-18 20:05 ` [PATCH V8 03/10] iio: imu: inv_icm42607: Add inv_icm42607 Core Driver Chris Morgan
2026-05-18 20:25   ` sashiko-bot
2026-05-18 20:05 ` [PATCH V8 04/10] iio: imu: inv_icm42607: Add I2C and SPI For icm42607 Chris Morgan
2026-05-18 20:54   ` sashiko-bot
2026-05-18 20:05 ` [PATCH V8 05/10] iio: imu: inv_icm42607: Add PM support for icm42607 Chris Morgan
2026-05-18 20:05 ` [PATCH V8 06/10] iio: imu: inv_icm42607: Add Buffer " Chris Morgan
2026-05-18 20:56   ` sashiko-bot [this message]
2026-05-18 20:05 ` [PATCH V8 07/10] iio: imu: inv_icm42607: Add Temp Support in icm42607 Chris Morgan
2026-05-18 20:45   ` sashiko-bot
2026-05-18 20:05 ` [PATCH V8 08/10] iio: imu: inv_icm42607: Add Accelerometer for icm42607 Chris Morgan
2026-05-18 20:53   ` sashiko-bot
2026-05-18 20:05 ` [PATCH V8 09/10] iio: imu: inv_icm42607: Add Gyroscope to icm42607 Chris Morgan
2026-05-18 21:05   ` sashiko-bot
2026-05-18 20:05 ` [PATCH V8 10/10] arm64: dts: rockchip: Add icm42607p IMU for RG-DS Chris Morgan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260518205620.C802CC2BCB7@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=macroalpha82@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox