Re: [PATCH v2] iio: gyro: mpu3050: Fix runtime PM leak on trigger errors

Andy Shevchenko <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Organization Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo
Message-ID <[email protected]>
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 <[email protected]>

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.