Re: [PATCH] hwrng: stm32: fix usage_count leak when autosuspend_delay is negative

Guangshuo Li <[email protected]>
Newsgroups org.kernel.vger.linux-crypto,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <CANUHTR9QBUtKJ8f5JAhRGPWw4ca2QpuzMB=F9ZC3Q38RoGMqkQ@mail.gmail.com>
Hi Daniel,

Thanks for the suggestion.

On Mon, 10 Aug 2026 at 18:24, Daniel Thompson <[email protected]> wrote:
>
> On Sat, Aug 08, 2026 at 03:45:10PM +0800, Guangshuo Li wrote:
> > stm32_rng_probe() calls pm_runtime_use_autosuspend(), but neither the
> > probe failure path nor stm32_rng_remove() calls the matching
> > pm_runtime_dont_use_autosuspend() before disabling runtime PM.
> >
> > If the autosuspend delay is set to a negative value while autosuspend
> > is enabled, the runtime PM core increments usage_count to prevent
> > runtime suspend. Without calling pm_runtime_dont_use_autosuspend()
> > during teardown, this reference is not dropped and usage_count remains
> > unbalanced.
>
> If calls to pm_runtime_use_autosuspend() must be paired with
> pm_runtime_dont_use_autosuspend() then I wonder if having a
> devm_pm_runtime_use_autosuspend() would be worthwhile?
>
> That way stm32_rng_remove() could be entirely replaced with devres
> cleanup.
>
>
> Daniel.

There is already devm_pm_runtime_enable(), whose devres cleanup calls
pm_runtime_dont_use_autosuspend() followed by pm_runtime_disable().

So I think this driver can simply switch from pm_runtime_enable() to
devm_pm_runtime_enable(), and stm32_rng_remove() can then be removed
entirely.

I'll rework the patch accordingly.

Thanks,
Guangshuo
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.