* [PATCH] hwrng: starfive: propagate clock and reset errors
@ 2026-08-30 13:17 Pengpeng Hou
0 siblings, 0 replies; only message in thread
From: Pengpeng Hou @ 2026-08-30 13:17 UTC (permalink / raw)
To: Jia Jie Ho
Cc: Pengpeng Hou, Olivia Mackall, Herbert Xu, Philipp Zabel,
linux-crypto, linux-kernel
The StarFive TRNG probe and resume paths ignore failures from their clock
and reset operations. That lets the driver register or resume while its
hardware access prerequisites were not established.
Check each transition, unwind only the previously enabled clock on failure,
and propagate the error to the probe or PM core.
Fixes: c388f458bc34 ("hwrng: starfive - Add TRNG driver for StarFive SoC")
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
drivers/char/hw_random/jh7110-trng.c | 39 +++++++++++++++++++++++++++---------
1 file changed, 29 insertions(+), 10 deletions(-)
diff --git a/drivers/char/hw_random/jh7110-trng.c b/drivers/char/hw_random/jh7110-trng.c
index aee12caab5780..61eb4db7ac014 100644
--- a/drivers/char/hw_random/jh7110-trng.c
+++ b/drivers/char/hw_random/jh7110-trng.c
@@ -320,9 +320,17 @@ static int starfive_trng_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(trng->rst),
"Error getting hardware reset line\n");
- clk_prepare_enable(trng->hclk);
- clk_prepare_enable(trng->ahb);
- reset_control_deassert(trng->rst);
+ ret = clk_prepare_enable(trng->hclk);
+ if (ret)
+ return ret;
+
+ ret = clk_prepare_enable(trng->ahb);
+ if (ret)
+ goto disable_hclk;
+
+ ret = reset_control_deassert(trng->rst);
+ if (ret)
+ goto disable_ahb;
trng->rng.name = dev_driver_string(&pdev->dev);
trng->rng.init = starfive_trng_init;
@@ -342,13 +350,18 @@ static int starfive_trng_probe(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
reset_control_assert(trng->rst);
- clk_disable_unprepare(trng->ahb);
- clk_disable_unprepare(trng->hclk);
-
- return dev_err_probe(&pdev->dev, ret, "Failed to register hwrng\n");
+ ret = dev_err_probe(&pdev->dev, ret, "Failed to register hwrng\n");
+ goto disable_ahb;
}
return 0;
+
+disable_ahb:
+ clk_disable_unprepare(trng->ahb);
+disable_hclk:
+ clk_disable_unprepare(trng->hclk);
+
+ return ret;
}
static int __maybe_unused starfive_trng_suspend(struct device *dev)
@@ -364,11 +377,17 @@ static int __maybe_unused starfive_trng_suspend(struct device *dev)
static int __maybe_unused starfive_trng_resume(struct device *dev)
{
struct starfive_trng *trng = dev_get_drvdata(dev);
+ int ret;
+
+ ret = clk_prepare_enable(trng->hclk);
+ if (ret)
+ return ret;
- clk_prepare_enable(trng->hclk);
- clk_prepare_enable(trng->ahb);
+ ret = clk_prepare_enable(trng->ahb);
+ if (ret)
+ clk_disable_unprepare(trng->hclk);
- return 0;
+ return ret;
}
static const struct dev_pm_ops starfive_trng_pm_ops = {
base-commit: 08dbfad3f5040f5bdb6c529da20d6d4e81fefd72
--
2.50.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-08-30 13:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-30 13:17 [PATCH] hwrng: starfive: propagate clock and reset errors Pengpeng Hou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox