From: Maxime MERE <maxime.mere@foss.st.com>
To: Guangshuo Li <lgs201920130244@gmail.com>,
Olivia Mackall <olivia@selenic.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Daniel Thompson <danielt@kernel.org>,
"Linus Walleij" <linusw@kernel.org>,
<linux-crypto@vger.kernel.org>,
<linux-stm32@st-md-mailman.stormreply.com>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Cc: <stable@vger.kernel.org>
Subject: Re: [PATCH v2] hwrng: stm32: fix usage_count leak when autosuspend_delay is negative
Date: Wed, 12 Aug 2026 10:25:15 +0200 [thread overview]
Message-ID: <6565654b-8516-4878-b617-7cd65992c2a6@foss.st.com> (raw)
In-Reply-To: <20260811063442.3058074-1-lgs201920130244@gmail.com>
On 8/11/26 08:34, Guangshuo Li wrote:
> stm32_rng_probe() calls pm_runtime_use_autosuspend(), but runtime PM is
> enabled with pm_runtime_enable() and the matching
> pm_runtime_dont_use_autosuspend() is not called on driver teardown.
>
> 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.
>
> Use devm_pm_runtime_enable() so that pm_runtime_dont_use_autosuspend()
> and pm_runtime_disable() are automatically called on probe failure and
> driver teardown. With runtime PM cleanup handled by devres,
> stm32_rng_remove() is no longer needed.
>
> This issue was found by manual code inspection.
>
> Fixes: c6a97c42e399 ("hwrng: stm32 - add support for STM32 HW RNG")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
Hi Guangshuo,
Thanks for your investigation. You've found one problem, but I think
you've solved three issues with your patch, and the one you describe is
the most minor of them.
The usage_count imbalance is real, but the driver never sets a negative
autosuspend_delay_ms itself, and the count is rebalanced on the next
probe anyway.
For the two others: when stm32_rng_read() arms a 100 ms autosuspend
timer, if we unbind within this 100 ms window, stm32_rng_remove()
cancels the pending suspend and leaves the device RPM_ACTIVE:
stm32_rng_runtime_suspend() never runs, so the RNG is left enabled with
its clocks prepared and its power domain held forever. Moreover, the
remove operation runs before devres released the hwrng registration, so
reads could still land on a device whose runtime PM was already disabled
and fail with -EACCES.
Your patch fixes both, because devm_pm_runtime_enable() registered
before devm_hwrng_register() unwinds in the right order and
pm_runtime_dont_use_autosuspend() forces a synchronous suspend before
the disable.
So I recommend adapting your commit message around those points, as I
think the Cc: stable is justified by those two.
Reviewed-by: Maxime Méré <maxime.mere@foss.st.com>
Cheers,
Maxime
prev parent reply other threads:[~2026-08-12 8:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 6:34 Guangshuo Li
2026-08-11 6:44 ` Linus Walleij
2026-08-11 10:53 ` Daniel Thompson
2026-08-12 8:25 ` Maxime MERE [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6565654b-8516-4878-b617-7cd65992c2a6@foss.st.com \
--to=maxime.mere@foss.st.com \
--cc=alexandre.torgue@foss.st.com \
--cc=danielt@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=lgs201920130244@gmail.com \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=olivia@selenic.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®