mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
hwrng: jh7110 - fix refcount leak in starfive_trng_read()
The starfive_trng_read() function acquires a runtime PM reference
via pm_runtime_get_sync() but fails to release it on two error
paths. If starfive_trng_wait_idle() or starfive_trng_cmd() returns
an error, the function exits without calling
pm_runtime_put_sync_autosuspend(), leaving the runtime PM usage
counter permanently elevated and preventing the device from entering
runtime suspend.
Refactor the function to use a unified error path that calls
pm_runtime_put_sync_autosuspend() before returning.
Cc: stable@vger.kernel.org
Fixes: c388f458bc ("hwrng: starfive - Add TRNG driver for StarFive SoC")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
70fd646ae5
commit
8d13f7a845
|
|
@ -256,19 +256,22 @@ static int starfive_trng_read(struct hwrng *rng, void *buf, size_t max, bool wai
|
|||
|
||||
if (wait) {
|
||||
ret = starfive_trng_wait_idle(trng);
|
||||
if (ret)
|
||||
return -ETIMEDOUT;
|
||||
if (ret) {
|
||||
ret = -ETIMEDOUT;
|
||||
goto out_put;
|
||||
}
|
||||
}
|
||||
|
||||
ret = starfive_trng_cmd(trng, STARFIVE_CTRL_GENE_RANDNUM, wait);
|
||||
if (ret)
|
||||
return ret;
|
||||
goto out_put;
|
||||
|
||||
memcpy_fromio(buf, trng->base + STARFIVE_RAND0, max);
|
||||
ret = max;
|
||||
|
||||
out_put:
|
||||
pm_runtime_put_sync_autosuspend(trng->dev);
|
||||
|
||||
return max;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int starfive_trng_probe(struct platform_device *pdev)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user