Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chris Morgan" <macroalpha82@gmail.com>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH V9 09/11] iio: imu: inv_icm42607: Add IRQ for icm42607
Date: Sat, 30 May 2026 04:23:30 +0000	[thread overview]
Message-ID: <20260530042331.1A0691F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260530031739.109063-10-macroalpha82@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Double unlock of `st->lock` on the error path in `inv_icm42607_irq_handler()`.
- [High] The threaded interrupt handler will deadlock on the success path due to recursive locking of `st->lock`.
- [High] The shared `st->fifo` state is accessed and modified without adequate lock protection across the read-and-parse transaction.
- [Medium] Premature exposure of the IIO device to userspace before IRQ initialization is complete.
--

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

iio: imu: inv_icm42607: Add IRQ for icm42607
    
Add IRQ support for the icm42607 driver.

> diff --git a/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
> index 6b623fb679f34..3c91623dffb29 100644
> --- a/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
> +++ b/drivers/iio/imu/inv_icm42607/inv_icm42607_core.c
[ ... ]
> @@ -331,6 +331,91 @@ static int inv_icm42607_setup(struct inv_icm42607_state *st,
[ ... ]
> +static irqreturn_t inv_icm42607_irq_handler(int irq, void *_data)
> +{
> +	struct inv_icm42607_state *st = _data;
> +	struct device *dev = regmap_get_device(st->map);
> +	unsigned int status;
> +	int ret;
> +
> +	mutex_lock(&st->lock);
> +
> +	ret = regmap_read(st->map, INV_ICM42607_REG_INT_STATUS, &status);
> +	if (ret) {
> +		dev_err(dev, "Interrut status read error %d\n", ret);
> +		goto out_unlock;
> +	}
> +
> +	if (status & INV_ICM42607_INT_STATUS_FIFO_FULL)
> +		dev_warn(dev, "FIFO full data lost!\n");
> +
> +	if (status & INV_ICM42607_INT_STATUS_FIFO_THS) {
> +		mutex_unlock(&st->lock);
> +		ret = inv_icm42607_buffer_fifo_read(st, 0);
> +		if (ret) {
> +			dev_err(dev, "FIFO read error %d\n", ret);
> +			goto out_unlock;

[Severity: High]
If inv_icm42607_buffer_fifo_read() fails here, the code jumps to out_unlock
while st->lock is already unlocked. Will this cause a double unlock of the
mutex at the out_unlock label?

> +		}
> +
> +		mutex_lock(&st->lock);

[Severity: High]
Will dropping the lock between the read and parse operations expose a race
window?

If a concurrent call to inv_icm42607_buffer_hwfifo_flush() interleaves during
this unlocked window, it could issue another read and overwrite the contents
of st->fifo.data and the sample counts. When the interrupt handler regains
the lock and calls inv_icm42607_buffer_fifo_parse(), it might parse the
overwritten data instead of the data it originally read.

> +		ret = inv_icm42607_buffer_fifo_parse(st);

[Severity: High]
Can this cause a deadlock on the success path?

inv_icm42607_buffer_fifo_parse() eventually delegates to
inv_icm42607_accel_parse_fifo(), which uses guard(mutex)(&st->lock) to
acquire the exact same lock. Since the lock is already acquired here, won't
this result in recursive locking?

> +		if (ret)
> +			dev_err(dev, "FIFO parsing error %d\n", ret);
> +	}
> +
> +out_unlock:
> +	mutex_unlock(&st->lock);

[Severity: High]
As mentioned above, if we jump here after failing
inv_icm42607_buffer_fifo_read(), the lock is already unlocked, causing a
double unlock error.

> +	return IRQ_HANDLED;
> +}
[ ... ]
> @@ -433,6 +523,11 @@ int inv_icm42607_core_probe(struct regmap *regmap,
>  	if (IS_ERR(st->indio_accel))
>  		return PTR_ERR(st->indio_accel);
>  
> +	/* Initialize interrupt handling */
> +	ret = inv_icm42607_irq_init(st, irq, irq_type, open_drain);

[Severity: Medium]
Is it safe to initialize the interrupt handling after registering the IIO
device?

inv_icm42607_accel_init() registers the device, exposing it to userspace. If
userspace opens the device and attempts to interact with it before the
interrupt is configured, or if inv_icm42607_irq_init() fails causing devres
cleanup, could this lead to issues with an actively exposed device?

> +	if (ret)
> +		return ret;
> +
>  	return 0;
>  }

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

  reply	other threads:[~2026-05-30  4:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-30  3:17 [PATCH V9 00/11] Add Invensense ICM42607 Chris Morgan
2026-05-30  3:17 ` [PATCH V9 01/11] dt-bindings: iio: imu: icm42600: Add mount-matrix to icm42600 Chris Morgan
2026-05-30  3:17 ` [PATCH V9 02/11] dt-bindings: iio: imu: icm42600: Add icm42607 binding Chris Morgan
2026-05-30  7:26   ` Krzysztof Kozlowski
2026-05-30  3:17 ` [PATCH V9 03/11] iio: imu: inv_icm42607: Add inv_icm42607 Core Driver Chris Morgan
2026-05-30  3:43   ` sashiko-bot
2026-05-30  3:17 ` [PATCH V9 04/11] iio: imu: inv_icm42607: Add I2C and SPI For icm42607 Chris Morgan
2026-05-30  3:51   ` sashiko-bot
2026-05-30  3:17 ` [PATCH V9 05/11] iio: imu: inv_icm42607: Add PM support for icm42607 Chris Morgan
2026-05-30  3:57   ` sashiko-bot
2026-05-30  3:17 ` [PATCH V9 06/11] iio: imu: inv_icm42607: Add Buffer " Chris Morgan
2026-05-30  4:05   ` sashiko-bot
2026-05-30  3:17 ` [PATCH V9 07/11] iio: imu: inv_icm42607: Add Temp Support in icm42607 Chris Morgan
2026-05-30  4:13   ` sashiko-bot
2026-05-30  3:17 ` [PATCH V9 08/11] iio: imu: inv_icm42607: Add Accelerometer for icm42607 Chris Morgan
2026-05-30  4:22   ` sashiko-bot
2026-05-30  3:17 ` [PATCH V9 09/11] iio: imu: inv_icm42607: Add IRQ " Chris Morgan
2026-05-30  4:23   ` sashiko-bot [this message]
2026-05-30  3:17 ` [PATCH V9 10/11] iio: imu: inv_icm42607: Add Gyroscope to icm42607 Chris Morgan
2026-05-30  4:57   ` sashiko-bot
2026-05-30  3:17 ` [PATCH V9 11/11] 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=20260530042331.1A0691F00893@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