Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH] hwrng: mtk - use pm_runtime_resume_and_get() in mtk_rng_read()
@ 2026-11-11  7:32 Gu Bin
  2026-11-11  7:44 ` sashiko-bot
  2026-11-11  9:06 ` [PATCH v2 0/2] hwrng: mtk - runtime PM fixes Gu Bin
  0 siblings, 2 replies; 5+ messages in thread
From: Gu Bin @ 2026-11-11  7:32 UTC (permalink / raw)
  To: sean.wang, olivia, herbert
  Cc: matthias.bgg, angelogioacchino.delregno, linux-crypto,
	linux-kernel

mtk_rng_read() calls pm_runtime_get_sync() without checking the return
value and immediately starts polling and reading the RNG registers:
when resuming the device fails (negative return), the reads hit a
device that never resumed, and the failure is only surfaced indirectly
(if at all) through the -EIO fallback of the final return.

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: 81d2b34508c6 ("hwrng: mtk - add runtime PM support")
Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com>
---
 drivers/char/hw_random/mtk-rng.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/char/hw_random/mtk-rng.c b/drivers/char/hw_random/mtk-rng.c
index 127b82d979e8..1e8e458dab25 100644
--- a/drivers/char/hw_random/mtk-rng.c
+++ b/drivers/char/hw_random/mtk-rng.c
@@ -95,7 +95,9 @@ static int mtk_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
 	struct mtk_rng *priv = to_mtk_rng(rng);
 	int retval = 0;
 
-	pm_runtime_get_sync(priv->dev);
+	retval = pm_runtime_resume_and_get(priv->dev);
+	if (retval < 0)
+		return retval;
 
 	while (max >= sizeof(u32)) {
 		if (!mtk_rng_wait_ready(rng, wait))
-- 
2.50.1.windows.1




^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-11  9:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11  7:32 [PATCH] hwrng: mtk - use pm_runtime_resume_and_get() in mtk_rng_read() Gu Bin
2026-11-11  7:44 ` sashiko-bot
2026-11-11  9:06 ` [PATCH v2 0/2] hwrng: mtk - runtime PM fixes Gu Bin
2026-11-11  9:06   ` [PATCH v2 1/2] hwrng: mtk - use pm_runtime_resume_and_get() in mtk_rng_read() Gu Bin
2026-11-11  9:06   ` [PATCH v2 2/2] hwrng: mtk - enable runtime PM before registering the RNG Gu Bin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox