Re: [PATCH v4 2/2] iio: gyro: mpu3050: Fix runtime PM refcount leak in trigger enable path

From: Andy Shevchenko

Date: Wed Nov 04 2026 - 07:01:10 EST


On Wed, Nov 04, 2026 at 12:00:07PM +0800, Xiangwu Lai wrote:

> mpu3050_drdy_trigger_enable() calls pm_runtime_get_sync() when
> enabling the data ready trigger, but all five error returns in the
> enable path return directly without the matching
> pm_runtime_put_autosuspend(). The disable path, in contrast, drops
> the reference correctly.
>
> As a result, a failed trigger enable leaves the runtime PM usage
> counter incremented and the sensor can never runtime suspend. It also
> leaves hw_irq_trigger set to true, claiming the hardware IRQ is in
> use when it is not.
>
> Use pm_runtime_resume_and_get(), which does not leave the usage
> counter incremented when resume fails, and add an error label that
> drops the runtime PM reference and clears hw_irq_trigger so that a
> failed enable returns with the device in the same state as before
> the attempt.
>
> Also propagate the error from the IRQ status read that clears the
> data ready flag instead of only printing it, so that a failure
> anywhere in the enable path consistently rolls the trigger state
> back.

...

> static int mpu3050_drdy_trigger_enable(struct mpu3050 *mpu3050)

> unsigned int val;
> int ret;
>
> - pm_runtime_get_sync(mpu3050->dev);
> + ret = pm_runtime_resume_and_get(mpu3050->dev);
> + if (ret)
> + return ret;

Why not PM_RUNTIME_ACQUIRE*()?
Yes, to make the

mpu3050->hw_irq_trigger = false;

this needs to be wrapped (two functions, outer one uses PM_RUNTIME_ACQUIRE(),
and handles the flag).

> mpu3050->hw_irq_trigger = true;

--
With Best Regards,
Andy Shevchenko