From: Jonathan Cameron <jic23@kernel.org>
To: Biren Pandya <birenpandya@gmail.com>
Cc: "Linus Walleij" <linusw@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/4] iio: gyro: mpu3050: fix runtime PM leak when enabling trigger fails
Date: Sun, 14 Jun 2026 14:22:31 +0100 [thread overview]
Message-ID: <20260614142231.736476db@jic23-huawei> (raw)
In-Reply-To: <20260614071549.81920-3-birenpandya@gmail.com>
On Sun, 14 Jun 2026 12:45:47 +0530
Biren Pandya <birenpandya@gmail.com> wrote:
> mpu3050_drdy_trigger_set_state() calls pm_runtime_get_sync() when the
> trigger is enabled, but several error paths in the enable branch return
> directly without dropping the usage counter again. pm_runtime_get_sync()
> increments the usage counter, so every failed enable leaks a runtime PM
> reference and the device can no longer autosuspend. The driver state flag
> hw_irq_trigger is also left set after a failed enable.
>
> Jump to a common error label that drops the reference and clears
> hw_irq_trigger, mirroring the disable path. The success path deliberately
> keeps the reference, as the device must stay resumed while the trigger is
> active.
>
> Signed-off-by: Biren Pandya <birenpandya@gmail.com>
> Assisted-by: Claude:claude-opus-4-8 coccinelle
This looks more or less fine to me, but I'd like to leave it on list
for a little while so hopefully someone who is more familiar with the device
can take a look.
A suggestion below for a less minimal but perhaps nicer way of doing this.
> ---
> drivers/iio/gyro/mpu3050-core.c | 16 +++++++++++-----
> 1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
> index d84e04e4b431..783be9a786df 100644
> --- a/drivers/iio/gyro/mpu3050-core.c
> +++ b/drivers/iio/gyro/mpu3050-core.c
> @@ -994,14 +994,14 @@ static int mpu3050_drdy_trigger_set_state(struct iio_trigger *trig,
> /* Disable all things in the FIFO */
> ret = regmap_write(mpu3050->map, MPU3050_FIFO_EN, 0);
> if (ret)
> - return ret;
> + goto err_power_down;
>
> /* Reset and enable the FIFO */
> ret = regmap_set_bits(mpu3050->map, MPU3050_USR_CTRL,
> MPU3050_USR_CTRL_FIFO_EN |
> MPU3050_USR_CTRL_FIFO_RST);
> if (ret)
> - return ret;
> + goto err_power_down;
>
> mpu3050->pending_fifo_footer = false;
>
> @@ -1013,12 +1013,12 @@ static int mpu3050_drdy_trigger_set_state(struct iio_trigger *trig,
> MPU3050_FIFO_EN_GYRO_ZOUT |
> MPU3050_FIFO_EN_FOOTER);
> if (ret)
> - return ret;
> + goto err_power_down;
>
> /* Configure the sample engine */
> ret = mpu3050_start_sampling(mpu3050);
> if (ret)
> - return ret;
> + goto err_power_down;
>
> /* Clear IRQ flag */
> ret = regmap_read(mpu3050->map, MPU3050_INT_STATUS, &val);
> @@ -1037,10 +1037,16 @@ static int mpu3050_drdy_trigger_set_state(struct iio_trigger *trig,
>
> ret = regmap_write(mpu3050->map, MPU3050_INT_CFG, val);
> if (ret)
> - return ret;
> + goto err_power_down;
> }
>
> return 0;
> +
> +err_power_down:
I'm not particularly keen on a goto error block that only applies to one
leg of an if / else. Given there is effectively not sharing of code between the enable
and disable paths, I'd rather see this whole thing broken into two helpers.
mpu3050_drdy_trigger_enable() and mpu3050_drdy_trigger_disable()
Then the error unwind would not have the issue of only applying to some code
paths as it would be in the helper. Obviously it is a more invasive change
but I think it is worth doing rather that having a minimal fix then sweeping around
later to replace all that code.
> + pm_runtime_put_autosuspend(mpu3050->dev);
> + mpu3050->hw_irq_trigger = false;
> +
> + return ret;
> }
>
> static const struct iio_trigger_ops mpu3050_trigger_ops = {
next prev parent reply other threads:[~2026-06-14 13:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-14 7:15 [PATCH v1 0/4] iio: Fix runtime PM leaks across multiple drivers Biren Pandya
2026-06-14 7:15 ` [PATCH v1 1/4] iio: accel: kxsd9: fix runtime PM imbalance on write_raw() error Biren Pandya
2026-06-14 13:14 ` Jonathan Cameron
2026-06-14 7:15 ` [PATCH v1 2/4] iio: gyro: mpu3050: fix runtime PM leak when enabling trigger fails Biren Pandya
2026-06-14 13:22 ` Jonathan Cameron [this message]
2026-07-17 17:50 ` [PATCH v3] " Biren Pandya
2026-07-17 18:01 ` Andy Shevchenko
2026-07-17 18:10 ` [PATCH v4] " Biren Pandya
2026-07-20 2:01 ` Jonathan Cameron
2026-06-14 7:15 ` [PATCH v1 3/4] iio: pressure: mpl115: fix runtime PM leak on read error Biren Pandya
2026-06-14 13:24 ` Jonathan Cameron
2026-06-14 7:15 ` [PATCH v1 4/4] iio: light: gp2ap002: " Biren Pandya
2026-06-14 13:25 ` Jonathan Cameron
2026-06-14 13:31 ` [PATCH v1 0/4] iio: Fix runtime PM leaks across multiple drivers 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=20260614142231.736476db@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=birenpandya@gmail.com \
--cc=dlechner@baylibre.com \
--cc=linusw@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.