Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Esben Haabendal <esben@geanix.com>
Cc: <sashiko-reviews@lists.linux.dev>, <robh@kernel.org>,
	<conor+dt@kernel.org>, <devicetree@vger.kernel.org>,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH v9 10/10] iio: accel: mma8452: Support interrupt sharing
Date: Mon, 21 Sep 2026 01:51:15 +0100	[thread overview]
Message-ID: <20260921015115.4c7d79f3@jic23-hlaptop> (raw)
In-Reply-To: <87se38754p.fsf@geanix.com>

On Thu, 17 Sep 2026 08:40:06 +0200
Esben Haabendal <esben@geanix.com> wrote:

> <sashiko-bot@kernel.org> writes:
> 
> > Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
> > - [Critical] iio: accel: mma8452: Interrupt storm livelock when IRQ fires during RPM_SUSPENDING
> > - [High] iio: accel: mma8452: Invalid I2C access during system suspend due to mishandled -EINVAL
> > - [Medium] iio: accel: mma8452: Race condition in probe error path due to pm_runtime_disable() before free_irq()
> > --
> >
So far we haven't enabled sashiko emails to the linux-iio list
(will probably move to that fairly soon) so fun side effect is this
reply was shouting into the void - except that b4 picks it up.

+CC linux-iio. I'm too lazy to add everyone by hand who was on original thread.

Key here is looks like you already plan a v10.


> > commit bf19c63685f6fff116a3a5358196fd66dff6090a
> > Author: Esben Haabendal <esben@geanix.com>
> >
> > iio: accel: mma8452: Support interrupt sharing
> >
> > This commit adds support for shared interrupts to the mma8452 driver. It
> > modifies the interrupt handler to check the runtime PM status and ignores
> > the interrupt if the device is suspended. It also updates the runtime
> > suspend and resume paths to properly disable and restore interrupt sources.
> >  
> >> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> >> index 5aea6bf3312af..2a980c0c2e03a 100644
> >> --- a/drivers/iio/accel/mma8452.c
> >> +++ b/drivers/iio/accel/mma8452.c  
> >
> > [ ... ]
> >  
> >> @@ -1086,15 +1088,28 @@ static irqreturn_t mma8452_interrupt(int irq, void *p)
> >>  {
> >>  	struct iio_dev *indio_dev = p;
> >>  	struct mma8452_data *data = iio_priv(indio_dev);
> >> +	struct device *dev = &data->client->dev;
> >>  	irqreturn_t ret = IRQ_NONE;
> >> +	int pm_status;
> >>  	int src;
> >>
> >> +	pm_status = pm_runtime_get_if_active(dev);
> >> +	if (pm_status == 0)
> >> +		return IRQ_NONE; /* device is powered down */  
> >
> > [Severity: Critical]
> > If the device asserts its level-triggered interrupt when the PM core is
> > transitioning the device to RPM_SUSPENDING (e.g., when the autosuspend
> > timer expires), pm_runtime_get_if_active() will return 0.
> >
> > Does returning IRQ_NONE without clearing the hardware interrupt here cause
> > a permanent interrupt storm? Since the IRQ line is shared and unmasked upon
> > return, the still-asserted hardware interrupt might immediately re-trigger
> > the handler, potentially starving the worker thread that executes
> > mma8452_runtime_suspend() and hard-locking the system.  
> 
> This should be handled by the disable of all interrupt sources (clearing
> CTRL_REG4) in mma8452_runtime_suspend().
> 
> > [Severity: High]
> > During system suspend, pm_runtime_force_suspend() disables runtime PM,
> > which increments the disable depth. If a shared interrupt fires during this
> > window, pm_runtime_get_if_active() returns -EINVAL.
> >
> > Since this check only catches pm_status == 0, does this allow the handler
> > to proceed and perform I2C reads on unpowered hardware? Per subsystem
> > guidelines, should this check for pm_status <= 0 instead?  
> 
> If we bail out on pm_status <= 0, the driver would not work on systems
> with CONFIG_PM not enabled.
> 
> In order to handle the difference betwen the different reasons for
> -EINVAL, it would seem like we would need some #ifdef CONFIG_PM in here.
> Do we really want to do that?

That if_enabled() function is a pain.  Definitely not ifdef but
how about

 if (IS_ENABLED(CONFIG_PM) && ret < 0) or something like that?

> 
> >> +
> >> +	/*
> >> +	 * pm_status is now 1 or -EINVAL. If pm_status==1, runtime PM is enabled
> >> +	 * and device is RPM_ACTIVE. If pm_status==-EINVAL, runtime PM is
> >> +	 * disabled (e.g. CONFIG_PM not enabled), and we can/must assume device
> >> +	 * is active.
> >> +	 */
> >> +
> >>  	src = i2c_smbus_read_byte_data(data->client, MMA8452_INT_SRC);  
> >
> > [ ... ]
> >  
> >> @@ -1771,11 +1790,12 @@ static void mma8452_remove(struct i2c_client *client)
> >>
> >>  	iio_device_unregister(indio_dev);
> >>
> >> -	pm_runtime_disable(dev);
> >> -	pm_runtime_set_suspended(dev);
> >> -
> >>  	if (client->irq)
> >>  		free_irq(client->irq, indio_dev);
> >> +	/* No irq will fire beyond this point */
> >> +
> >> +	pm_runtime_disable(dev);
> >> +	pm_runtime_set_suspended(dev);  
> >
> > [Severity: Medium]
> > This correctly fixes the race in mma8452_remove() by moving free_irq()
> > before pm_runtime_disable(), but does the same race still exist in the
> > mma8452_probe() error path?
> >
> > If mma8452_probe() fails after pm_runtime_enable(), it jumps to the
> > runtime_suspend label:
> >
> >   mma8452_probe() {
> >       /* ... */
> >   runtime_suspend:
> >       pm_runtime_disable(dev);
> >       pm_runtime_set_suspended(dev);
> >
> >   free_irq:
> >       if (client->irq)
> >           free_irq(client->irq, indio_dev);
> >       /* ... */
> >   }
> >
> > If a shared interrupt fires between pm_runtime_disable() and free_irq(),
> > could the handler attempt to access unpowered hardware?  
> 
> I will apply the same reordering in mma8452_probe().

Sounds good to me

Jonathan

> 
> /Esben


  parent reply	other threads:[~2026-09-21  0:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16  8:07 [PATCH v9 00/10] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-09-16  8:07 ` [PATCH v9 01/10] dt-bindings: iio: accel: mma8452: Add drive-open-drain Esben Haabendal
2026-09-16  8:07 ` [PATCH v9 02/10] iio: accel: mma8452: Fix use-after-free bug in error error path Esben Haabendal
2026-09-16  8:07 ` [PATCH v9 03/10] iio: accel: mma8452: Fix runtime PM bugs in mma8452_read() Esben Haabendal
2026-09-16  8:08 ` [PATCH v9 04/10] iio: accel: mma8452: Optimize struct mma8452_data member orders Esben Haabendal
2026-09-16  8:08 ` [PATCH v9 05/10] iio: accel: mma8452: Only apply trigger type when not set by firmware Esben Haabendal
2026-09-16  8:08 ` [PATCH v9 06/10] iio: accel: mma8452: Fix unintended comment indent Esben Haabendal
2026-09-16  8:08 ` [PATCH v9 07/10] iio: accel: mma8452: Add comment block for struct mma8452_data Esben Haabendal
2026-09-21  0:52   ` Jonathan Cameron
2026-09-21  5:30     ` Esben Haabendal
2026-09-16  8:08 ` [PATCH v9 08/10] iio: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-09-16  8:08 ` [PATCH v9 09/10] iio: accel: mma8452: Use proper error code when missing device model Esben Haabendal
2026-09-16  8:08 ` [PATCH v9 10/10] iio: accel: mma8452: Support interrupt sharing Esben Haabendal
     [not found]   ` <l9LG3al0xmawstyXcDwD8OhOBMwn13q6oz0NvCPy4kL0lA4DX5biMlUWcvt9Wwu1AiyugOvUZgQfnFJ4dvuvbA==@protonmail.internalid>
     [not found]     ` <20260916083119.03A8F1F000FF@smtp.kernel.org>
     [not found]       ` <87se38754p.fsf@geanix.com>
2026-09-21  0:51         ` Jonathan Cameron [this message]
2026-09-21  5:35           ` Esben Haabendal
2026-09-22  0:18             ` Jonathan Cameron

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=20260921015115.4c7d79f3@jic23-hlaptop \
    --to=jic23@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=esben@geanix.com \
    --cc=linux-iio@vger.kernel.org \
    --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