Skip to contentSkip to conversation

hwrng: npcm - use pm_runtime_resume_and_get() in npcm_rng_read()

PATCH New Gu Bin 1 participant 1 message Nov 11

Subsystems (3)
lore
Share & tools
lore

Gu Bin

author
#0 lore raw

PATCH 1/1 hwrng: npcm - use pm_runtime_resume_and_get() in npcm_rng_read()

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")
---
 drivers/char/hw_random/npcm-rng.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/hw_random/npcm-rng.c +3 -1
index a85f745963be..67a35df3bf80 100644
@@ -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) {
Signature · 1 line
2.50.1.windows.1