Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chris Morgan" <macroalpha82@gmail.com>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH V13 6/9] iio: imu: inv_icm42607: Add Temp Support in icm42607
Date: Mon, 15 Jun 2026 17:51:30 +0000	[thread overview]
Message-ID: <20260615175130.6CEE41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260615172554.160910-7-macroalpha82@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Prematurely mutating the temperature software state before calling the power management configuration bypasses state change detection, skipping the mandatory startup delay and causing reads of uninitialized data.

Pre-existing issues:
- [High] The temperature sensor read fails (returns -EINVAL) when the gyroscope and accelerometer are off because the device is placed in Sleep mode instead of Idle mode, disabling the internal RC oscillator.
--

commit d36f0c461ef9d5076de90b75b6238be45c35148d
Author: Chris Morgan <macromorgan@hotmail.com>
Subject: iio: imu: inv_icm42607: Add Temp Support in icm42607

Add functions for reading temperature sensor data.

[ ... ]

> diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
> index 64f5d263de4f2..644cd7f821b92 100644
> --- a/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
> +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
[ ... ]
> @@ -162,6 +162,24 @@ static int inv_icm42607_set_pwr_mgmt0(struct inv_icm42607_state *st,
>  	return 0;
>  }
>  
> +int inv_icm42607_set_temp_conf(struct inv_icm42607_state *st, bool enable,
> +			       unsigned int *sleep_ms)
> +{
> +	unsigned int val;
> +	int ret;
> +
> +	val = FIELD_PREP(INV_ICM42607_TEMP_CONFIG0_FILTER_MASK,
> +			 INV_ICM42607_FILTER_BW_34HZ);
> +	ret = regmap_update_bits(st->map, INV_ICM42607_REG_TEMP_CONFIG0,
> +				 INV_ICM42607_TEMP_CONFIG0_FILTER_MASK, val);
> +	if (ret)
> +		return ret;
> +
> +	return inv_icm42607_set_pwr_mgmt0(st, st->conf.gyro.mode,
> +					  st->conf.accel.mode, enable,
> +					  sleep_ms);

[Severity: High]
This is a pre-existing issue, but will this temperature read fail with -EINVAL
if the gyroscope and accelerometer are off?

Looking at inv_icm42607_set_pwr_mgmt0(), it constructs the PWR_MGMT0 register
value using only the gyro and accel mode masks:

    val = FIELD_PREP(INV_ICM42607_PWR_MGMT0_GYRO_MODE_MASK, gyro);
    val |= FIELD_PREP(INV_ICM42607_PWR_MGMT0_ACCEL_MODE_MASK, accel);
    ret = regmap_write(st->map, INV_ICM42607_REG_PWR_MGMT0, val);

If both gyro and accel are off, val is 0, which places the device in Sleep mode
instead of Idle mode. The internal RC oscillator required for temperature reads
is disabled, causing the data register to return 0x8000
(INV_ICM42607_DATA_INVALID).

Should the IDLE bit be set when temp is true and the other sensors are
inactive?

> +}
> +
[ ... ]

> diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c
> new file mode 100644
> index 0000000000000..9a60e1a478b08
> --- /dev/null
> +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_temp.c
[ ... ]
> +static int inv_icm42607_temp_read(struct inv_icm42607_state *st, s16 *temp)
> +{
> +	struct device *dev = regmap_get_device(st->map);
> +	u8 raw[2];
> +	int ret;
> +
> +	PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev, pm);
> +	ret = PM_RUNTIME_ACQUIRE_ERR(&pm);
> +	if (ret)
> +		return ret;
> +
> +	guard(mutex)(&st->lock);
> +
> +	st->conf.temp_en = true;
> +	ret = inv_icm42607_set_temp_conf(st, st->conf.temp_en, NULL);

[Severity: High]
Does setting st->conf.temp_en to true before this call bypass the hardware
configuration and startup delay?

Because st->conf.temp_en is mutated before the call, when
inv_icm42607_set_temp_conf() calls inv_icm42607_set_pwr_mgmt0(), it will
evaluate the state transition like this:

    bool oldtemp = st->conf.temp_en;
    ...
    if (gyro == oldgyro && accel == oldaccel && temp == oldtemp)
        return 0;

Since temp and oldtemp are now both true, the function returns early without
writing to the power management register or waiting for the startup delay.
Could this lead to reading uninitialized or desynchronized data?

> +	st->conf.temp_en = false;
> +	if (ret)
> +		return ret;
> +
> +	ret = regmap_bulk_read(st->map, INV_ICM42607_REG_TEMP_DATA1,
> +			       raw, sizeof(raw));
> +	if (ret)
> +		return ret;
[ ... ]

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

  reply	other threads:[~2026-06-15 17:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-15 17:25 [PATCH V13 0/9] Add Invensense ICM42607 Chris Morgan
2026-06-15 17:25 ` [PATCH V13 1/9] dt-bindings: iio: imu: icm42600: Add mount-matrix to icm42600 Chris Morgan
2026-06-15 17:25 ` [PATCH V13 2/9] dt-bindings: iio: imu: icm42600: Add icm42607 Chris Morgan
2026-06-15 17:25 ` [PATCH V13 3/9] iio: imu: inv_icm42607: Add inv_icm42607 Core Driver Chris Morgan
2026-06-15 17:25 ` [PATCH V13 4/9] iio: imu: inv_icm42607: Add SPI For icm42607 Chris Morgan
2026-06-15 17:25 ` [PATCH V13 5/9] iio: imu: inv_icm42607: Add PM support for icm42607 Chris Morgan
2026-06-15 17:50   ` sashiko-bot
2026-06-15 17:25 ` [PATCH V13 6/9] iio: imu: inv_icm42607: Add Temp Support in icm42607 Chris Morgan
2026-06-15 17:51   ` sashiko-bot [this message]
2026-06-15 17:25 ` [PATCH V13 7/9] iio: imu: inv_icm42607: Add Accelerometer for icm42607 Chris Morgan
2026-06-15 17:25 ` [PATCH V13 8/9] iio: imu: inv_icm42607: Add Gyroscope to icm42607 Chris Morgan
2026-06-15 18:03   ` sashiko-bot
2026-06-15 17:25 ` [PATCH V13 9/9] 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=20260615175130.6CEE41F000E9@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