[SeaBIOS] [PATCH 10/10] tpm: Return returnCode from build_and_send_cmd() instead of via pointer param
Kevin O'Connor
kevin at koconnor.net
Wed Dec 30 01:17:50 CET 2015
The callers interested in the return status of build_and_send_cmd()
are only interested in the command return code status (returnCode) and
not the status of the message transmission (rc). Simplify the callers
by returning returnCode directly instead of via a pointer parameter.
For the unlikely case that the command transmission fails, return -1
to signal the failure to the callers.
Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
src/tcgbios.c | 139 ++++++++++++++++++++++++++++------------------------------
1 file changed, 66 insertions(+), 73 deletions(-)
diff --git a/src/tcgbios.c b/src/tcgbios.c
index c578fd2..ee5e9f7 100644
--- a/src/tcgbios.c
+++ b/src/tcgbios.c
@@ -171,7 +171,7 @@ tpm_is_working(void)
*/
static u32
build_and_send_cmd(u8 locty, u32 ordinal, const u8 *append, u32 append_size,
- u32 *returnCode, enum tpmDurationType to_t)
+ enum tpmDurationType to_t)
{
struct {
struct tpm_req_header trqh;
@@ -195,30 +195,26 @@ build_and_send_cmd(u8 locty, u32 ordinal, const u8 *append, u32 append_size,
u32 rc = tpmhw_transmit(locty, &req.trqh, obuffer, &obuffer_len, to_t);
if (rc)
- return rc;
-
- *returnCode = be32_to_cpu(trsh->errcode);
- return 0;
+ return -1;
+ return be32_to_cpu(trsh->errcode);
}
static void
tpm_set_failure(void)
{
- u32 returnCode;
-
/* we will try to deactivate the TPM now - ignoring all errors */
build_and_send_cmd(0, TPM_ORD_PhysicalPresence,
PhysicalPresence_CMD_ENABLE,
sizeof(PhysicalPresence_CMD_ENABLE),
- &returnCode, TPM_DURATION_TYPE_SHORT);
+ TPM_DURATION_TYPE_SHORT);
build_and_send_cmd(0, TPM_ORD_PhysicalPresence,
PhysicalPresence_PRESENT,
sizeof(PhysicalPresence_PRESENT),
- &returnCode, TPM_DURATION_TYPE_SHORT);
+ TPM_DURATION_TYPE_SHORT);
build_and_send_cmd(0, TPM_ORD_SetTempDeactivated,
- NULL, 0, &returnCode, TPM_DURATION_TYPE_SHORT);
+ NULL, 0, TPM_DURATION_TYPE_SHORT);
TPM_working = 0;
}
@@ -429,44 +425,42 @@ tpm_startup(void)
return TCG_GENERAL_ERROR;
dprintf(DEBUG_tcg, "TCGBIOS: Starting with TPM_Startup(ST_CLEAR)\n");
- rc = build_and_send_cmd(0, TPM_ORD_Startup,
- Startup_ST_CLEAR, sizeof(Startup_ST_CLEAR),
- &returnCode, TPM_DURATION_TYPE_SHORT);
+ returnCode = build_and_send_cmd(0, TPM_ORD_Startup,
+ Startup_ST_CLEAR, sizeof(Startup_ST_CLEAR),
+ TPM_DURATION_TYPE_SHORT);
dprintf(DEBUG_tcg, "Return code from TPM_Startup = 0x%08x\n",
returnCode);
- if (CONFIG_COREBOOT) {
+ if (CONFIG_COREBOOT && returnCode == TPM_INVALID_POSTINIT)
/* with other firmware on the system the TPM may already have been
* initialized
*/
- if (returnCode == TPM_INVALID_POSTINIT)
- returnCode = 0;
- }
+ returnCode = 0;
- if (rc || returnCode)
+ if (returnCode)
goto err_exit;
rc = determine_timeouts();
if (rc)
goto err_exit;
- rc = build_and_send_cmd(0, TPM_ORD_SelfTestFull, NULL, 0,
- &returnCode, TPM_DURATION_TYPE_LONG);
+ returnCode = build_and_send_cmd(0, TPM_ORD_SelfTestFull, NULL, 0,
+ TPM_DURATION_TYPE_LONG);
dprintf(DEBUG_tcg, "Return code from TPM_SelfTestFull = 0x%08x\n",
returnCode);
- if (rc || returnCode)
+ if (returnCode)
goto err_exit;
- rc = build_and_send_cmd(3, TSC_ORD_ResetEstablishmentBit, NULL, 0,
- &returnCode, TPM_DURATION_TYPE_SHORT);
+ returnCode = build_and_send_cmd(3, TSC_ORD_ResetEstablishmentBit, NULL, 0,
+ TPM_DURATION_TYPE_SHORT);
dprintf(DEBUG_tcg, "Return code from TSC_ResetEstablishmentBit = 0x%08x\n",
returnCode);
- if (rc || (returnCode != 0 && returnCode != TPM_BAD_LOCALITY))
+ if (returnCode != 0 && returnCode != TPM_BAD_LOCALITY)
goto err_exit;
rc = tpm_smbios_measure();
@@ -519,18 +513,18 @@ tpm_prepboot(void)
if (!tpm_is_working())
return;
- rc = build_and_send_cmd(0, TPM_ORD_PhysicalPresence,
- PhysicalPresence_CMD_ENABLE,
- sizeof(PhysicalPresence_CMD_ENABLE),
- &returnCode, TPM_DURATION_TYPE_SHORT);
- if (rc || returnCode)
+ returnCode = build_and_send_cmd(0, TPM_ORD_PhysicalPresence,
+ PhysicalPresence_CMD_ENABLE,
+ sizeof(PhysicalPresence_CMD_ENABLE),
+ TPM_DURATION_TYPE_SHORT);
+ if (returnCode)
goto err_exit;
- rc = build_and_send_cmd(0, TPM_ORD_PhysicalPresence,
- PhysicalPresence_NOT_PRESENT_LOCK,
- sizeof(PhysicalPresence_NOT_PRESENT_LOCK),
- &returnCode, TPM_DURATION_TYPE_SHORT);
- if (rc || returnCode)
+ returnCode = build_and_send_cmd(0, TPM_ORD_PhysicalPresence,
+ PhysicalPresence_NOT_PRESENT_LOCK,
+ sizeof(PhysicalPresence_NOT_PRESENT_LOCK),
+ TPM_DURATION_TYPE_SHORT);
+ if (returnCode)
goto err_exit;
rc = tpm_add_action(4, "Calling INT 19h");
@@ -643,7 +637,6 @@ tpm_add_cdrom_catalog(const u8 *addr, u32 length)
void
tpm_s3_resume(void)
{
- u32 rc;
u32 returnCode;
if (!tpm_is_working())
@@ -651,14 +644,14 @@ tpm_s3_resume(void)
dprintf(DEBUG_tcg, "TCGBIOS: Resuming with TPM_Startup(ST_STATE)\n");
- rc = build_and_send_cmd(0, TPM_ORD_Startup,
- Startup_ST_STATE, sizeof(Startup_ST_STATE),
- &returnCode, TPM_DURATION_TYPE_SHORT);
+ returnCode = build_and_send_cmd(0, TPM_ORD_Startup,
+ Startup_ST_STATE, sizeof(Startup_ST_STATE),
+ TPM_DURATION_TYPE_SHORT);
dprintf(DEBUG_tcg, "TCGBIOS: ReturnCode from TPM_Startup = 0x%08x\n",
returnCode);
- if (rc || returnCode)
+ if (returnCode)
goto err_exit;
return;
@@ -984,31 +977,31 @@ assert_physical_presence(int verbose)
/* physical presence already asserted */
return 0;
- rc = build_and_send_cmd(0, TPM_ORD_PhysicalPresence,
- PhysicalPresence_CMD_ENABLE,
- sizeof(PhysicalPresence_CMD_ENABLE),
- &returnCode, TPM_DURATION_TYPE_SHORT);
+ returnCode = build_and_send_cmd(0, TPM_ORD_PhysicalPresence,
+ PhysicalPresence_CMD_ENABLE,
+ sizeof(PhysicalPresence_CMD_ENABLE),
+ TPM_DURATION_TYPE_SHORT);
dprintf(DEBUG_tcg,
- "Return code from TSC_PhysicalPresence(CMD_ENABLE) = 0x%08x\n",
- returnCode);
+ "Return code from TSC_PhysicalPresence(CMD_ENABLE) = 0x%08x\n",
+ returnCode);
- if (rc || returnCode) {
+ if (returnCode) {
if (verbose)
printf("Error: Could not enable physical presence.\n\n");
goto err_exit;
}
- rc = build_and_send_cmd(0, TPM_ORD_PhysicalPresence,
- PhysicalPresence_PRESENT,
- sizeof(PhysicalPresence_PRESENT),
- &returnCode, TPM_DURATION_TYPE_SHORT);
+ returnCode = build_and_send_cmd(0, TPM_ORD_PhysicalPresence,
+ PhysicalPresence_PRESENT,
+ sizeof(PhysicalPresence_PRESENT),
+ TPM_DURATION_TYPE_SHORT);
dprintf(DEBUG_tcg,
- "Return code from TSC_PhysicalPresence(PRESENT) = 0x%08x\n",
- returnCode);
+ "Return code from TSC_PhysicalPresence(PRESENT) = 0x%08x\n",
+ returnCode);
- if (rc || returnCode) {
+ if (returnCode) {
if (verbose)
printf("Error: Could not set presence flag.\n\n");
goto err_exit;
@@ -1074,9 +1067,9 @@ enable_tpm(int enable, u32 *returnCode, int verbose)
return rc;
}
- rc = build_and_send_cmd(0, enable ? TPM_ORD_PhysicalEnable
- : TPM_ORD_PhysicalDisable,
- NULL, 0, returnCode, TPM_DURATION_TYPE_SHORT);
+ *returnCode = build_and_send_cmd(0, enable ? TPM_ORD_PhysicalEnable
+ : TPM_ORD_PhysicalDisable,
+ NULL, 0, TPM_DURATION_TYPE_SHORT);
if (enable)
dprintf(DEBUG_tcg, "Return code from TPM_PhysicalEnable = 0x%08x\n",
*returnCode);
@@ -1084,7 +1077,7 @@ enable_tpm(int enable, u32 *returnCode, int verbose)
dprintf(DEBUG_tcg, "Return code from TPM_PhysicalDisable = 0x%08x\n",
*returnCode);
- if (rc || *returnCode)
+ if (*returnCode)
goto err_exit;
return 0;
@@ -1125,18 +1118,18 @@ activate_tpm(int activate, int allow_reset, u32 *returnCode, int verbose)
return rc;
}
- rc = build_and_send_cmd(0, TPM_ORD_PhysicalSetDeactivated,
- activate ? CommandFlag_FALSE
- : CommandFlag_TRUE,
- activate ? sizeof(CommandFlag_FALSE)
- : sizeof(CommandFlag_TRUE),
- returnCode, TPM_DURATION_TYPE_SHORT);
+ *returnCode = build_and_send_cmd(0, TPM_ORD_PhysicalSetDeactivated,
+ activate ? CommandFlag_FALSE
+ : CommandFlag_TRUE,
+ activate ? sizeof(CommandFlag_FALSE)
+ : sizeof(CommandFlag_TRUE),
+ TPM_DURATION_TYPE_SHORT);
dprintf(DEBUG_tcg,
"Return code from PhysicalSetDeactivated(%d) = 0x%08x\n",
activate ? 0 : 1, *returnCode);
- if (rc || *returnCode)
+ if (*returnCode)
goto err_exit;
if (activate && allow_reset) {
@@ -1204,13 +1197,13 @@ force_clear(int enable_activate_before, int enable_activate_after,
return rc;
}
- rc = build_and_send_cmd(0, TPM_ORD_ForceClear,
- NULL, 0, returnCode, TPM_DURATION_TYPE_SHORT);
+ *returnCode = build_and_send_cmd(0, TPM_ORD_ForceClear,
+ NULL, 0, TPM_DURATION_TYPE_SHORT);
dprintf(DEBUG_tcg, "Return code from TPM_ForceClear() = 0x%08x\n",
*returnCode);
- if (rc || *returnCode)
+ if (*returnCode)
goto err_exit;
if (!enable_activate_after) {
@@ -1265,16 +1258,16 @@ set_owner_install(int allow, u32 *returnCode, int verbose)
return rc;
}
- rc = build_and_send_cmd(0, TPM_ORD_SetOwnerInstall,
- (allow) ? CommandFlag_TRUE :
- CommandFlag_FALSE,
- sizeof(CommandFlag_TRUE),
- returnCode, TPM_DURATION_TYPE_SHORT);
+ *returnCode = build_and_send_cmd(0, TPM_ORD_SetOwnerInstall,
+ (allow) ? CommandFlag_TRUE
+ : CommandFlag_FALSE,
+ sizeof(CommandFlag_TRUE),
+ TPM_DURATION_TYPE_SHORT);
dprintf(DEBUG_tcg, "Return code from TPM_SetOwnerInstall() = 0x%08x\n",
*returnCode);
- if (rc || *returnCode)
+ if (*returnCode)
goto err_exit;
if (verbose)
--
2.5.0
More information about the SeaBIOS
mailing list