Re: [PATCH v2] iio: gyro: mpu3050: Fix runtime PM leak and refactor trigger state
From: Jonathan Cameron
Date: Sun Jun 21 2026 - 13:45:16 EST
On Tue, 16 Jun 2026 03:15:04 +0530
Biren Pandya <birenpandya@xxxxxxxxx> 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.
>
> To fix the error unwind clearly and avoid an asymmetric goto block inside a
> monolithic function, this patch breaks the trigger state handler into two
> distinct helpers: mpu3050_drdy_trigger_enable() and
> mpu3050_drdy_trigger_disable(). The enable helper correctly implements the
> error unwind path to drop the PM reference and clear the flag.
>
> Additionally, pm_runtime_get_sync() is replaced with
> pm_runtime_resume_and_get() for robust error checking.
>
> Fixes: 3904b28efb2c ("iio: gyro: Add core driver for the MPU-3050")
> Suggested-by: Jonathan Cameron <jic23@xxxxxxxxxx>
> Signed-off-by: Biren Pandya <birenpandya@xxxxxxxxx>
> ---
>
> drivers/iio/gyro/mpu3050-core.c | 156 ++++++++++++++++++--------------
> 1 file changed, 87 insertions(+), 69 deletions(-)
>
> diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
> index d84e04e4b431..7dea7ab6b2d6 100644
> --- a/drivers/iio/gyro/mpu3050-core.c
> +++ b/drivers/iio/gyro/mpu3050-core.c
> @@ -950,97 +950,115 @@ static irqreturn_t mpu3050_irq_thread(int irq, void *p)
> * @trig: trigger instance
> * @enable: true if trigger should be enabled, false to disable
> */
As the bot called out. There are docs here that need to move
with the function.
> -static int mpu3050_drdy_trigger_set_state(struct iio_trigger *trig,
> - bool enable)