[coreboot-gerrit] Change in coreboot[master]: tpm: clean up tpm_setup function flow

Joel Kitching (Code Review) gerrit at coreboot.org
Thu Oct 11 12:23:44 CEST 2018


Joel Kitching has uploaded this change for review. ( https://review.coreboot.org/29026


Change subject: tpm: clean up tpm_setup function flow
......................................................................

tpm: clean up tpm_setup function flow

Introduce two helper functions for more readable code.

BUG=None
TEST=None

Change-Id: Ibea44880683a301e82ee2ba049003c36fcb44eba
Signed-off-by: Joel Kitching <kitching at google.com>
---
M src/security/tpm/tspi/tspi.c
1 file changed, 37 insertions(+), 25 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/26/29026/1

diff --git a/src/security/tpm/tspi/tspi.c b/src/security/tpm/tspi/tspi.c
index e882857..73722bd 100644
--- a/src/security/tpm/tspi/tspi.c
+++ b/src/security/tpm/tspi/tspi.c
@@ -64,6 +64,41 @@
 }
 #endif
 
+static uint32_t tpm_setup_epilogue(uint32_t result)
+{
+	if (result != TPM_SUCCESS)
+		post_code(POST_TPM_FAILURE);
+	else
+		printk(BIOS_INFO, "TPM: setup succeeded\n");
+
+	return result;
+}
+
+static uint32_t tpm_setup_s3_helper(void)
+{
+	result = tlcl_resume();
+	switch (result) {
+	case TPM_SUCCESS:
+		break;
+
+	case TPM_E_INVALID_POSTINIT:
+		/*
+		 * We're on a platform where the TPM maintains power
+		 * in S3, so it's already initialized.
+		 */
+		printk(BIOS_INFO, "TPM: Already initialized.\n");
+		result = TPM_SUCCESS;
+		break;
+
+	default:
+		printk(BIOS_ERR, "TPM: Resume failed (%d).\n", result);
+		break;
+
+	}
+
+	return result;
+}
+
 /*
  * tpm_setup starts the TPM and establishes the root of trust for the
  * anti-rollback mechanism.  SetupTPM can fail for three reasons.  1 A bug. 2 a
@@ -96,25 +131,7 @@
 
 	/* Handle special init for S3 resume path */
 	if (s3flag) {
-		result = tlcl_resume();
-		switch (result) {
-		case TPM_SUCCESS:
-			break;
-
-		case TPM_E_INVALID_POSTINIT:
-			/*
-			 * We're on a platform where the TPM maintains power
-			 * in S3, so it's already initialized.
-			 */
-			printk(BIOS_INFO, "TPM: Already initialized.\n");
-			result = TPM_SUCCESS;
-			break;
-
-		default:
-			printk(BIOS_ERR, "TPM: Resume failed.\n");
-			break;
-
-		}
+		result = tpm_setup_s3_helper();
 		goto out;
 	}
 
@@ -154,12 +171,7 @@
 #endif
 
 out:
-	if (result != TPM_SUCCESS)
-		post_code(POST_TPM_FAILURE);
-	else
-		printk(BIOS_INFO, "TPM: setup succeeded\n");
-
-	return result;
+	return tpm_setup_epilogue(result);
 }
 
 uint32_t tpm_clear_and_reenable(void)

-- 
To view, visit https://review.coreboot.org/29026
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibea44880683a301e82ee2ba049003c36fcb44eba
Gerrit-Change-Number: 29026
Gerrit-PatchSet: 1
Gerrit-Owner: Joel Kitching <kitching at google.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20181011/179355b5/attachment.html>


More information about the coreboot-gerrit mailing list