git: 4ba372dbc105 - stable/13 - tpm: Register TPM as entropy source

From: Kevin Bowling <kbowling_at_FreeBSD.org>
Date: Sat, 07 Sep 2024 05:14:22 UTC
The branch stable/13 has been updated by kbowling:

URL: https://cgit.FreeBSD.org/src/commit/?id=4ba372dbc1057ef080bcf9353cdebd3958c33b9c

commit 4ba372dbc1057ef080bcf9353cdebd3958c33b9c
Author:     Jean-François Hren <jean-francois.hren@stormshield.eu>
AuthorDate: 2024-08-31 17:53:02 +0000
Commit:     Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2024-09-07 05:14:06 +0000

    tpm: Register TPM as entropy source
    
    TPM is defined as an entropy and is called every 10 seconds. However it
    was not registered and calls were discarded.
    
    Signed-off-by: Jean-François Hren <jean-francois.hren@stormshield.eu>
    
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/1398
    
    (cherry picked from commit d7c87526b1c3d32d3ac3fee8c59d92405b7621b9)
---
 sys/dev/tpm/tpm20.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/dev/tpm/tpm20.c b/sys/dev/tpm/tpm20.c
index dc483ba9d4fc..6865403960b3 100644
--- a/sys/dev/tpm/tpm20.c
+++ b/sys/dev/tpm/tpm20.c
@@ -206,6 +206,7 @@ tpm20_init(struct tpm_sc *sc)
 		tpm20_release(sc);
 
 #ifdef TPM_HARVEST
+	random_harvest_register_source(RANDOM_PURE_TPM);
 	TIMEOUT_TASK_INIT(taskqueue_thread, &sc->harvest_task, 0,
 	    tpm20_harvest, sc);
 	taskqueue_enqueue_timeout(taskqueue_thread, &sc->harvest_task, 0);
@@ -222,6 +223,7 @@ tpm20_release(struct tpm_sc *sc)
 #ifdef TPM_HARVEST
 	if (device_is_attached(sc->dev))
 		taskqueue_drain_timeout(taskqueue_thread, &sc->harvest_task);
+	random_harvest_deregister_source(RANDOM_PURE_TPM);
 #endif
 
 	if (sc->buf != NULL)