Re: [PATCH v2] iio: gyro: mpu3050: Fix runtime PM leak on trigger errors
From: Andy Shevchenko
Date: Tue Aug 18 2026 - 10:09:59 EST
On Tue, Aug 18, 2026 at 09:30:46PM +0800, Ruoyu Wang wrote:
> The first user of the MPU-3050 data-ready trigger takes a runtime PM
> reference before configuring the FIFO, sample engine and interrupt. If
> any of those operations fails, iio_trigger_attach_poll_func() tears down
> its IRQ resources without calling set_trigger_state(false). The buffer
> error path then releases only its preenable reference, leaving the
> trigger's reference held and preventing runtime suspend.
>
> Use PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND() so a failed resume does
> not leave a usage count behind and later setup failures automatically
> release the acquired reference. Disarm the scoped cleanup after the
> interrupt has been enabled, leaving the disable path to release the
> trigger's reference. Keep hw_irq_trigger clear unless interrupt setup
> succeeds.
>
> This issue was found by a static analysis checker and confirmed by manual
> source review.
...
> Suggested-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
I'm not sure I suggested the solution as targeted by this patch.
...
> + retain_and_null_ptr(pm);
Ah, I see, in such a case it might be better to leave the bare runtime PM
calls. Sorry for the suboptimal proposal.
--
With Best Regards,
Andy Shevchenko