Skip to contentSkip to conversation

Add trng driver to JHB100

PATCH In review lianfeng.ouyang 3 participants 9 messages May 18 – May 19

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover Add trng driver to JHB100

From: Lianfeng Ouyang <[email protected]>

for jhb100, While IP assert async reset, it may generate glitch and propagate to downstream IP. In order to solve RDC issue, conduct clock gating before asserting reset to prevent generating glitch.

Optimization-driven PM logic. The original driver did not declare PM as active in the probe, resulting in the count not being able to drop to 0

Lianfeng Ouyang (2):
dt-bindings: Add bindings for StarFive JHB100 SoC trng controller
hwrng: starfive: Update clk and reset sequence

 .../bindings/rng/starfive,jh7110-trng.yaml    | 10 +--
 MAINTAINERS                                   |  2 +-
 drivers/char/hw_random/jh7110-trng.c          | 83 ++++++++++++++-----
 3 files changed, 65 insertions(+), 30 deletions(-)

--
2.43.0

#1 lore raw

PATCH v2 1/2 dt-bindings: Add bindings for StarFive JHB100 SoC trng controller

From: Lianfeng Ouyang <[email protected]>

jh8100 is no longer supported
Jia Jie Ho has resigned

---
 .../devicetree/bindings/rng/starfive,jh7110-trng.yaml  | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/rng/starfive,jh7110-trng.yaml +4 -6
index 4639247e9e51..d21769b7d54e 100644
@@ -7,15 +7,13 @@ $schema: http://devicetree.org/meta-schemas/core.yaml#
 title: StarFive SoC TRNG Module
 
 maintainers:
-  - Jia Jie Ho <[email protected]>
+  - Lianfeng Ouyang <[email protected]>
 
 properties:
   compatible:
-    oneOf:
-      - items:
-          - const: starfive,jh8100-trng
-          - const: starfive,jh7110-trng
-      - const: starfive,jh7110-trng
+    enum:
+      - starfive,jh7110-trng
+      - starfive,jhb100-trng
 
   reg:
     maxItems: 1

--
2.43.0

#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: Add bindings for StarFive JHB100 SoC trng controller

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Removing the existing 'starfive,jh8100-trng' compatible string breaks backwards compatibility. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Removing the existing 'starfive,jh8100-trng' compatible string breaks backwards compatibility. --

commit 847e83dc6a2024f6cb7a70fd0453035b2808bedb
Author: Lianfeng Ouyang <[email protected]>

dt-bindings: Add bindings for StarFive JHB100 SoC trng controller

This commit adds device tree bindings for the StarFive JHB100 SoC TRNG controller, updates the maintainer, and removes the JH8100 compatible string.

Quoted 4 lines
Documentation/devicetree/bindings/rng/starfive,jh7110-trng.yaml +0 -0
index 4639247e9e510..d21769b7d54e6 100644

[ ... ]

Documentation/devicetree/bindings/rng/starfive,jh7110-trng.yaml $schema: http://devicetree.org/meta-schemas/core.yaml# · line 16

Quoted 10 lines

properties:
compatible:

Documentation/devicetree/bindings/rng/starfive,jh7110-trng.yaml +3 -5
-    oneOf:
-      - items:
-          - const: starfive,jh8100-trng
-          - const: starfive,jh7110-trng
-      - const: starfive,jh7110-trng
+    enum:
+      - starfive,jh7110-trng
+      - starfive,jhb100-trng

Does removing the existing "starfive,jh8100-trng" compatible string break backwards compatibility?

Device tree bindings represent a stable ABI, and removing the previously merged "starfive,jh8100-trng" string breaks dt-schema validation for any existing or downstream device trees that used it. Even if the hardware is no longer supported, the standard practice is to retain such strings, perhaps optionally adding "deprecated: true", rather than deleting them outright.

Quoted 3 lines

reg:
maxItems: 1

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH v2 1/2] dt-bindings: Add bindings for StarFive JHB100 SoC trng controller

Sashiko devs,

Quoted 31 lines · On Mon, May 18, 2026 at 07:06:21AM +0000, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Removing the existing 'starfive,jh8100-trng' compatible string breaks backwards compatibility. --

commit 847e83dc6a2024f6cb7a70fd0453035b2808bedb
Author: Lianfeng Ouyang <[email protected]>

dt-bindings: Add bindings for StarFive JHB100 SoC trng controller

This commit adds device tree bindings for the StarFive JHB100 SoC TRNG controller, updates the maintainer, and removes the JH8100 compatible string.

Quoted 4 lines
Documentation/devicetree/bindings/rng/starfive,jh7110-trng.yaml +0 -0
index 4639247e9e510..d21769b7d54e6 100644

[ ... ]

Documentation/devicetree/bindings/rng/starfive,jh7110-trng.yaml $schema: http://devicetree.org/meta-schemas/core.yaml# · line 16

Quoted 10 lines

properties:
compatible:

Documentation/devicetree/bindings/rng/starfive,jh7110-trng.yaml +3 -5
-    oneOf:
-      - items:
-          - const: starfive,jh8100-trng
-          - const: starfive,jh7110-trng
-      - const: starfive,jh7110-trng
+    enum:
+      - starfive,jh7110-trng
+      - starfive,jhb100-trng
Quoted 2 lines

Does removing the existing "starfive,jh8100-trng" compatible string break backwards compatibility?

The commit message is perfunctory but does attempt to explains this. Since the bot reply fails to retain the commit message as quoted text, it's annoying to go figure that out.

It's really annoying that this happens, especially when the LLM text references the commit message. Can you please change the email response settings to retain the commit messages?

Cheers,
Conor.

Quoted 14 lines

Device tree bindings represent a stable ABI, and removing the previously merged "starfive,jh8100-trng" string breaks dt-schema validation for any existing or downstream device trees that used it. Even if the hardware is no longer supported, the standard practice is to retain such strings, perhaps optionally adding "deprecated: true", rather than deleting them outright.

Quoted 3 lines

reg:
maxItems: 1

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#4 lore raw

Re: [PATCH v2 1/2] dt-bindings: Add bindings for StarFive JHB100 SoC trng controller

In reply to lianfeng.ouyang
Quoted 4 lines · lianfeng.ouyang

From: Lianfeng Ouyang <[email protected]>

jh8100 is no longer supported
Jia Jie Ho has resigned

Please put some effort into your commit messages. Look around on LKML, where do you ever seen commit messages as perfunctory as this? Please speak to the other developers at Starfive about what the commit messages should look like.

The first "sentence" here isn't even really accurate, is it? The jh8100 was never even released to customers, right?

pw-bot: changes-requested

Thanks,
Conor.

Quoted 34 lines
---
 .../devicetree/bindings/rng/starfive,jh7110-trng.yaml  | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/rng/starfive,jh7110-trng.yaml +4 -7
index 4639247e9e51..d21769b7d54e 100644
@@ -7,15 +7,13 @@ $schema: http://devicetree.org/meta-schemas/core.yaml#
 title: StarFive SoC TRNG Module
 
 maintainers:
-  - Jia Jie Ho <[email protected]>
+  - Lianfeng Ouyang <[email protected]>
 
 properties:
   compatible:
-    oneOf:
-      - items:
-          - const: starfive,jh8100-trng
-          - const: starfive,jh7110-trng
-      - const: starfive,jh7110-trng
+    enum:
+      - starfive,jh7110-trng
+      - starfive,jhb100-trng
 
   reg:
     maxItems: 1
--

2.43.0

#5 lore raw

回复: [PATCH v2 1/2] dt-bindings: Add bindings for StarFive JHB100 SoC trng controller

Quoted 25 lines

-----邮件原件-----
发件人: Conor Dooley <[email protected]>
发送时间: 2026年5月19日 0:42
收件人: Lianfeng Ouyang <[email protected]>
抄送: Olivia Mackall <[email protected]>; Herbert Xu <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Philipp Zabel <[email protected]>; [email protected]; [email protected]; [email protected]
主题: Re: [PATCH v2 1/2] dt-bindings: Add bindings for StarFive JHB100 SoC trng controller

Quoted 4 lines · lianfeng.ouyang

From: Lianfeng Ouyang <[email protected]>

jh8100 is no longer supported
Jia Jie Ho has resigned

Please put some effort into your commit messages. Look around on LKML, where do you ever seen commit messages as perfunctory as this? Please speak to the other developers at Starfive about what the commit messages should look like.

Quoted 7 lines

The first "sentence" here isn't even really accurate, is it? The jh8100 was never even released to customers, right?

pw-bot: changes-requested

Thanks,
Conor.

I'm very sorry, I will provide more information for commit messages Thanks,
Lianfeng.

Quoted 39 lines
Quoted 39 lines
---
 .../devicetree/bindings/rng/starfive,jh7110-trng.yaml  | 10
++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/Documentation/devicetree/bindings/rng/starfive,jh7110-trng.yaml b/Documentation/devicetree/bindings/rng/starfive,jh7110-trng.yaml index 4639247e9e51..d21769b7d54e 100644

Documentation/devicetree/bindings/rng/starfive,jh7110-trng.yaml +0 -0
@@ -7,15 +7,13 @@ $schema:

http://devicetree.org/meta-schemas/core.yaml#
title: StarFive SoC TRNG Module

maintainers:

Documentation/devicetree/bindings/rng/starfive,jh7110-trng.yaml +4 -7
-  - Jia Jie Ho <[email protected]>
+  - Lianfeng Ouyang <[email protected]>
 
 properties:
   compatible:
-    oneOf:
-      - items:
-          - const: starfive,jh8100-trng
-          - const: starfive,jh7110-trng
-      - const: starfive,jh7110-trng
+    enum:
+      - starfive,jh7110-trng
+      - starfive,jhb100-trng
 
   reg:
     maxItems: 1
--

2.43.0

#6 lore raw

PATCH v2 2/2 hwrng: starfive: Update clk and reset sequence

In reply to lianfeng.ouyang

From: Lianfeng Ouyang <[email protected]>

for jhb100, While IP assert async reset, it may generate glitch and propagate to downstream IP. In order to solve RDC issue, conduct clock gating before asserting reset to prevent generating glitch.

Jia Jie Ho has resigned

---
 MAINTAINERS                          |  2 +-
 drivers/char/hw_random/jh7110-trng.c | 83 ++++++++++++++++++++--------
 2 files changed, 61 insertions(+), 24 deletions(-)
MAINTAINERS +1 -1
index d3a6b3f6b6a0..729b20ecc697 100644
@@ -25280,7 +25280,7 @@ F:	Documentation/devicetree/bindings/perf/starfive,jh8100-starlink-pmu.yaml
 F:	drivers/perf/starfive_starlink_pmu.c
 
 STARFIVE TRNG DRIVER
-M:	Jia Jie Ho <[email protected]>
+M:	Lianfeng Ouyang <[email protected]>
 S:	Supported
 F:	Documentation/devicetree/bindings/rng/starfive*
 F:	drivers/char/hw_random/jh7110-trng.c
drivers/char/hw_random/jh7110-trng.c +60 -23

192 lines not on this page · raw message

--
2.43.0

#7 lore raw

Re: [PATCH v2 2/2] hwrng: starfive: Update clk and reset sequence

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider: - [High] Unhandled error from `pm_runtime_get_sync()` leads to unsafe register access. - [High]…

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Unhandled error from pm_runtime_get_sync() leads to unsafe register access.
- [High] starfive_trng_release() causes a clock double-disable and hardware sequence violation if the device is suspended.
- [High] Devres ordering creates a race condition where the IRQ handler remains active after clocks are disabled.
- [High] The IRQ handler accesses hardware registers without verifying the device's PM state.
- [High] The IRQ handler is registered before hardware clocks are enabled, creating a window for a fatal crash.
- [High] A stale IRQ completion race allows starfive_trng_read() to return non-random bytes prematurely. --

commit 9fe8263576b446ca8c08d308b365ff7601cef468
Author: Lianfeng Ouyang <[email protected]>
Subject: hwrng: starfive: Update clk and reset sequence

This commit updates the clock and reset sequencing for the StarFive TRNG driver to prevent glitches on the jhb100 platform. It introduces a specific release function and integrates runtime PM across initialization, reading, and cleanup.

Quoted 9 lines
drivers/char/hw_random/jh7110-trng.c +2 -0
@@ -138,6 +143,23 @@ static inline void starfive_trng_irq_mask_clear(struct starfive_trng *trng)
 	writel(data, trng->base + STARFIVE_ISTAT);
 }
 
+static void starfive_trng_release(void *data)
+{

drivers/char/hw_random/jh7110-trng.c static inline void starfive_trng_irq_mask_clear(struct starfive_trng *trng) · line 157

Quoted 10 lines
drivers/char/hw_random/jh7110-trng.c +10 -0
+	struct starfive_trng *trng = data;
+
+	pm_runtime_disable(trng->dev);
+	pm_runtime_dont_use_autosuspend(trng->dev);
+
+	if (trng->hw_seq == HW_SEQ_RESET_FIRST_THEN_CLK)
+		reset_control_assert(trng->rst);
+
+	clk_disable_unprepare(trng->ahb);
+	clk_disable_unprepare(trng->hclk);

If the device is already runtime-suspended (e.g., autosuspend timer expired), starfive_trng_suspend() would have already disabled these clocks. Since pm_runtime_disable() does not wake up a suspended device, will calling clk_disable_unprepare() here result in a clock enable count underflow?

Also, for the HW_SEQ_RESET_FIRST_THEN_CLK variant, could this assert the hardware reset on a clock-gated IP block? Should the release function wake the device (via pm_runtime_get_sync) before performing hardware teardown?

[ ... ]

drivers/char/hw_random/jh7110-trng.c static int starfive_trng_init(struct hwrng *rng) · line 201

Quoted 7 lines
drivers/char/hw_random/jh7110-trng.c +3 -0
@@ -174,13 +196,16 @@ static int starfive_trng_init(struct hwrng *rng)
 {
 	struct starfive_trng *trng = to_trng(rng);
 	u32 mode, intr = 0;
+	int ret;
+
+	pm_runtime_get_sync(trng->dev);

Is it safe to ignore the return value of pm_runtime_get_sync() here? If the device fails to resume, it returns a negative error code. Would the subsequent register accesses (like writel/readl) occur on a device with disabled clocks, potentially causing a synchronous external abort?

Does this same unhandled return value issue apply to the pm_runtime_get_sync() calls added in starfive_trng_read() and starfive_trng_cleanup() as well?

[ ... ]

drivers/char/hw_random/jh7110-trng.c static int starfive_trng_read(struct hwrng *rng, void *buf, size_t max, bool wai · line 298

Quoted 9 lines
drivers/char/hw_random/jh7110-trng.c +1 -1
@@ -257,24 +292,26 @@ 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;
+			goto end;
 	}
 
 	ret = starfive_trng_cmd(trng, STARFIVE_CTRL_GENE_RANDNUM, wait);

Even though starfive_trng_wait_idle() polls until the hardware is idle, could there still be a pending IRQ from a previous operation that hasn't been processed by the CPU yet?

If that pending IRQ is handled right after reinit_completion() is called inside starfive_trng_cmd(), would it complete the random_done completion early, causing this function to read from STARFIVE_RAND0 while the hardware is still actively generating the new random number?

[ ... ]

Quoted 1 line
drivers/char/hw_random/jh7110-trng.c +0 -0
@@ -283,21 +320,22 @@ static int starfive_trng_probe(struct platform_device *pdev)

[ ... ]

drivers/char/hw_random/jh7110-trng.c static int starfive_trng_probe(struct platform_device *pdev) · line 339

Quoted 7 lines
drivers/char/hw_random/jh7110-trng.c +1 -1
 	init_completion(&trng->random_done);
 	init_completion(&trng->reseed_done);
 	spin_lock_init(&trng->write_lock);
 
-	ret = devm_request_irq(&pdev->dev, irq, starfive_trng_irq, 0, pdev->name,
+	ret = devm_request_irq(&pdev->dev, trng->irq, starfive_trng_irq, 0, pdev->name,
 			       (void *)trng);

This registers the IRQ before the hardware clocks are enabled below. If an interrupt is pending from a prior boot stage, will starfive_trng_irq() fire immediately and attempt to read STARFIVE_ISTAT while clocks are still gated off, potentially triggering a bus fault?

Additionally, does starfive_trng_irq() need to check the PM state using pm_runtime_get_if_active() before accessing registers? If a spurious or delayed interrupt fires while the device is runtime suspended, the handler currently reads registers unconditionally.

[ ... ]

drivers/char/hw_random/jh7110-trng.c static int starfive_trng_probe(struct platform_device *pdev) · line 377

Quoted 13 lines
drivers/char/hw_random/jh7110-trng.c +2 -7
 	pm_runtime_use_autosuspend(&pdev->dev);
 	pm_runtime_set_autosuspend_delay(&pdev->dev, 100);
+	pm_runtime_set_active(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);
 
-	ret = devm_hwrng_register(&pdev->dev, &trng->rng);
-	if (ret) {
-		pm_runtime_disable(&pdev->dev);
-
-		reset_control_assert(trng->rst);
-		clk_disable_unprepare(trng->ahb);
-		clk_disable_unprepare(trng->hclk);
+	ret = devm_add_action_or_reset(&pdev->dev, starfive_trng_release, trng);

Devres actions execute in reverse order of creation. Since devm_request_irq() is called before devm_add_action_or_reset(), won't starfive_trng_release() run first during device unbind and disable the clocks, leaving the IRQ active?

If an interrupt fires during this window, wouldn't it cause a bus fault when the handler reads from a clock-gated IP?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#8 lore raw

回复: [PATCH v2 2/2] hwrng: starfive: Update clk and reset sequence

Hi, Conor

Thanks for the review.

Quoted 56 lines

-----邮件原件-----
发件人: [email protected] <[email protected]>
发送时间: 2026年5月18日 15:40
收件人: Lianfeng Ouyang <[email protected]> 抄送: [email protected]; [email protected]; [email protected] 主题: Re: [PATCH v2 2/2] hwrng: starfive: Update clk and reset sequence

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] Unhandled error from pm_runtime_get_sync() leads to unsafe register access.
- [High] starfive_trng_release() causes a clock double-disable and hardware sequence violation if the device is suspended.
- [High] Devres ordering creates a race condition where the IRQ handler remains active after clocks are disabled.
- [High] The IRQ handler accesses hardware registers without verifying the device's PM state.
- [High] The IRQ handler is registered before hardware clocks are enabled, creating a window for a fatal crash.
- [High] A stale IRQ completion race allows starfive_trng_read() to return non-random bytes prematurely.
--

commit 9fe8263576b446ca8c08d308b365ff7601cef468
Author: Lianfeng Ouyang <[email protected]>
Subject: hwrng: starfive: Update clk and reset sequence

This commit updates the clock and reset sequencing for the StarFive TRNG driver to prevent glitches on the jhb100 platform. It introduces a specific release function and integrates runtime PM across initialization, reading, and cleanup.

drivers/char/hw_random/jh7110-trng.c static inline void

Quoted 5 lines
drivers/char/hw_random/jh7110-trng.c +0 -0
@@ -138,6 +143,23 @@ static inline void

starfive_trng_irq_mask_clear(struct starfive_trng *trng)

drivers/char/hw_random/jh7110-trng.c static inline void starfive_trng_irq_mask_clear(struct starfive_trng *trng) · line 157

Quoted 13 lines
drivers/char/hw_random/jh7110-trng.c +11 -0
 	writel(data, trng->base + STARFIVE_ISTAT);  }
 
+static void starfive_trng_release(void *data) {
+	struct starfive_trng *trng = data;
+
+	pm_runtime_disable(trng->dev);
+	pm_runtime_dont_use_autosuspend(trng->dev);
+
+	if (trng->hw_seq == HW_SEQ_RESET_FIRST_THEN_CLK)
+		reset_control_assert(trng->rst);
+
+	clk_disable_unprepare(trng->ahb);
+	clk_disable_unprepare(trng->hclk);

If the device is already runtime-suspended (e.g., autosuspend timer expired), starfive_trng_suspend() would have already disabled these clocks. Since pm_runtime_disable() does not wake up a suspended device, will calling clk_disable_unprepare() here result in a clock enable count underflow?

Quoted 3 lines

Also, for the HW_SEQ_RESET_FIRST_THEN_CLK variant, could this assert the hardware reset on a clock-gated IP block? Should the release function wake the device (via pm_runtime_get_sync) before performing hardware teardown?

Thank you for pointing it out. There is indeed a hidden danger here, and I have fixed it in the code using pm_runtime_get-sync and pm_runtime_put_noide

Quoted 15 lines

[ ... ]

drivers/char/hw_random/jh7110-trng.c static int starfive_trng_init(struct hwrng *rng) · line 201

Quoted 7 lines
drivers/char/hw_random/jh7110-trng.c +3 -0
@@ -174,13 +196,16 @@ static int starfive_trng_init(struct hwrng *rng)
 {
 	struct starfive_trng *trng = to_trng(rng);
 	u32 mode, intr = 0;
+	int ret;
+
+	pm_runtime_get_sync(trng->dev);

Is it safe to ignore the return value of pm_runtime_get_sync() here? If the device fails to resume, it returns a negative error code. Would the subsequent register accesses (like writel/readl) occur on a device with disabled clocks, potentially causing a synchronous external abort?

Quoted 3 lines

Does this same unhandled return value issue apply to the pm_runtime_get_sync() calls added in starfive_trng_read() and starfive_trng_cleanup() as well?

Yes, return value verification is required for all calls to pm_runtime_get-sync in the entire driver. I will fix this in the code. Thank you

Quoted 17 lines

[ ... ]

drivers/char/hw_random/jh7110-trng.c static int starfive_trng_read(struct hwrng *rng,

Quoted 1 line
drivers/char/hw_random/jh7110-trng.c +0 -0
@@ -257,24 +292,26 @@ static int starfive_trng_read(struct hwrng *rng,

void *buf, size_t max, bool wai

drivers/char/hw_random/jh7110-trng.c static int starfive_trng_read(struct hwrng *rng, void *buf, size_t max, bool wai · line 298

Quoted 8 lines
drivers/char/hw_random/jh7110-trng.c +1 -1
 	if (wait) {
 		ret = starfive_trng_wait_idle(trng);
 		if (ret)
-			return -ETIMEDOUT;
+			goto end;
 	}
 
 	ret = starfive_trng_cmd(trng, STARFIVE_CTRL_GENE_RANDNUM, wait);

Even though starfive_trng_wait_idle() polls until the hardware is idle, could there still be a pending IRQ from a previous operation that hasn't been processed by the CPU yet?

Quoted 4 lines

If that pending IRQ is handled right after reinit_completion() is called inside starfive_trng_cmd(), would it complete the random_done completion early, causing this function to read from STARFIVE_RAND0 while the hardware is still actively generating the new random number?

Sorry, I didn't understand the problem here because every time the corresponding value is written to the STARFIVE-CTRL register, the corresponding interrupt is triggered,
and then the corresponding completion amount is completed. That is to say,
even if there is an interrupt after calling reinit_completion(), it is not related to the
current completion amount being processed because the corresponding completion
amount has already been processed in each reinit_completion and wait_for_completion_timeout

Quoted 9 lines

[ ... ]

Quoted 2 lines
drivers/char/hw_random/jh7110-trng.c +0 -0
@@ -283,21 +320,22 @@ static int starfive_trng_probe(struct
 platform_device *pdev)

[ ... ]

Quoted 4 lines
drivers/char/hw_random/jh7110-trng.c +0 -0
 	init_completion(&trng->random_done);
 	init_completion(&trng->reseed_done);
 	spin_lock_init(&trng->write_lock);
Quoted 9 lines

drivers/char/hw_random/jh7110-trng.c static int starfive_trng_probe(struct platform_device *pdev) · line 339

Quoted 4 lines
drivers/char/hw_random/jh7110-trng.c +2 -1
-	ret = devm_request_irq(&pdev->dev, irq, starfive_trng_irq, 0, pdev->name,
+	ret = devm_request_irq(&pdev->dev, trng->irq, starfive_trng_irq, 0,
+pdev->name,
 			       (void *)trng);

This registers the IRQ before the hardware clocks are enabled below. If an interrupt is pending from a prior boot stage, will starfive_trng_irq() fire immediately and attempt to read STARFIVE_ISTAT while clocks are still gated off, potentially triggering a bus fault?

There should be no problem here. After devm_request_irq and before the clock is enabled,
the driver did not initialize the TRNG hardware, so it will not trigger an interrupt. The TRNG hardware is initialized in rng.init

Quoted 5 lines

Additionally, does starfive_trng_irq() need to check the PM state using pm_runtime_get_if_active() before accessing registers? If a spurious or delayed interrupt fires while the device is runtime suspended, the handler currently reads registers unconditionally.

This is a great suggestion. I have already added it to the code. Thank you for the reminder

Quoted 22 lines

[ ... ]

Quoted 4 lines
drivers/char/hw_random/jh7110-trng.c +1 -0
 	pm_runtime_use_autosuspend(&pdev->dev);
 	pm_runtime_set_autosuspend_delay(&pdev->dev, 100);
+	pm_runtime_set_active(&pdev->dev);
 	pm_runtime_enable(&pdev->dev);

drivers/char/hw_random/jh7110-trng.c static int starfive_trng_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/char/hw_random/jh7110-trng.c +2 -7
 
-	ret = devm_hwrng_register(&pdev->dev, &trng->rng);
-	if (ret) {
-		pm_runtime_disable(&pdev->dev);
-
-		reset_control_assert(trng->rst);
-		clk_disable_unprepare(trng->ahb);
-		clk_disable_unprepare(trng->hclk);
+	ret = devm_add_action_or_reset(&pdev->dev, starfive_trng_release,
+trng);

Devres actions execute in reverse order of creation. Since devm_request_irq() is called before devm_add_action_or_reset(), won't starfive_trng_release() run first during device unbind and disable the clocks, leaving the IRQ active?

Quoted 2 lines

If an interrupt fires during this window, wouldn't it cause a bus fault when the handler reads from a clock-gated IP?

This issue should exist, and in future versions, I will turn off interrupts like Cleanup and then turn off the clock

Quoted 4 lines

--
Sashiko AI
review · https://sashiko.dev/#/patchset/20260518065243.20865-1-lianfeng.ou
[email protected]?part=2