* [PATCH] hwrng: npcm - use pm_runtime_resume_and_get() in npcm_rng_read()
@ 2026-11-11 7:33 Gu Bin
2026-11-20 9:50 ` Herbert Xu
0 siblings, 1 reply; 2+ messages in thread
From: Gu Bin @ 2026-11-11 7:33 UTC (permalink / raw)
To: andrew, avifishman70, tmaimon77, tali.perry1, herbert
Cc: venture, yuenn, linux-crypto, linux-kernel
npcm_rng_read() calls pm_runtime_get_sync() without checking the return
value and then polls and reads the RNG registers: when resuming the
device fails (negative return), the loop reads a device that never
resumed and the failure is lost - the function returns the (zero) byte
count instead of an error.
Use pm_runtime_resume_and_get() instead and bail out on the error: the
helper reports the resume failure and drops the usage counter reference
it took, which a failed pm_runtime_get_sync() leaves behind (the usage
counter is incremented before the resume attempt, so returning
directly after a failed get_sync() would leak the reference and the
device could never autosuspend again). The tail
pm_runtime_put_sync_autosuspend() must not be used for this bailout:
the device never resumed, so balancing the counter is all that is
needed. On success the helper returns 0, which is exactly what the
read counter expects at that point.
Fixes: c98429297d8b ("hwrng: npcm - add NPCM RNG driver")
Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com>
---
drivers/char/hw_random/npcm-rng.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/char/hw_random/npcm-rng.c b/drivers/char/hw_random/npcm-rng.c
index a85f745963be..67a35df3bf80 100644
--- a/drivers/char/hw_random/npcm-rng.c
+++ b/drivers/char/hw_random/npcm-rng.c
@@ -58,7 +58,9 @@ static int npcm_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
int retval = 0;
int ready;
- pm_runtime_get_sync(priv->dev);
+ retval = pm_runtime_resume_and_get(priv->dev);
+ if (retval < 0)
+ return retval;
while (max) {
if (wait) {
--
2.50.1.windows.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] hwrng: npcm - use pm_runtime_resume_and_get() in npcm_rng_read()
2026-11-11 7:33 [PATCH] hwrng: npcm - use pm_runtime_resume_and_get() in npcm_rng_read() Gu Bin
@ 2026-11-20 9:50 ` Herbert Xu
0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2026-11-20 9:50 UTC (permalink / raw)
To: Gu Bin
Cc: andrew, avifishman70, tmaimon77, tali.perry1, venture, yuenn,
linux-crypto, linux-kernel
On Wed, Nov 11, 2026 at 03:33:08PM +0800, Gu Bin wrote:
> npcm_rng_read() calls pm_runtime_get_sync() without checking the return
> value and then polls and reads the RNG registers: when resuming the
> device fails (negative return), the loop reads a device that never
> resumed and the failure is lost - the function returns the (zero) byte
> count instead of an error.
>
> Use pm_runtime_resume_and_get() instead and bail out on the error: the
> helper reports the resume failure and drops the usage counter reference
> it took, which a failed pm_runtime_get_sync() leaves behind (the usage
> counter is incremented before the resume attempt, so returning
> directly after a failed get_sync() would leak the reference and the
> device could never autosuspend again). The tail
> pm_runtime_put_sync_autosuspend() must not be used for this bailout:
> the device never resumed, so balancing the counter is all that is
> needed. On success the helper returns 0, which is exactly what the
> read counter expects at that point.
>
> Fixes: c98429297d8b ("hwrng: npcm - add NPCM RNG driver")
> Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com>
> ---
> drivers/char/hw_random/npcm-rng.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-20 9:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 7:33 [PATCH] hwrng: npcm - use pm_runtime_resume_and_get() in npcm_rng_read() Gu Bin
2026-11-20 9:50 ` Herbert Xu
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®