Skip to content

Commit

Permalink
drivers/tpm: Make temp test value naming consistent
Browse files Browse the repository at this point in the history
Make naming convention consistent across all functions return values.

BUG=b:296439237
TEST=Boot to OS on Skyrim
BRANCH=None

Change-Id: If86805b39048800276ab90b7687644ec2a0d4bee
Signed-off-by: Jon Murphy <jpmurphy@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/77536
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
Reviewed-by: Eric Lai <eric_lai@quanta.corp-partner.google.com>
  • Loading branch information
jpmurphy-google authored and karthikr-google committed Sep 18, 2023
1 parent 277db94 commit 2460481
Show file tree
Hide file tree
Showing 17 changed files with 299 additions and 295 deletions.
6 changes: 3 additions & 3 deletions src/drivers/crb/tis.c
Expand Up @@ -122,14 +122,14 @@ static int tpm_get_cap(uint32_t property, uint32_t *value)
{
TPMS_CAPABILITY_DATA cap_data;
int i;
uint32_t status;
uint32_t rc;

if (!value)
return -1;

status = tlcl_get_capability(TPM_CAP_TPM_PROPERTIES, property, 1, &cap_data);
rc = tlcl_get_capability(TPM_CAP_TPM_PROPERTIES, property, 1, &cap_data);

if (status)
if (rc)
return -1;

for (i = 0 ; i < cap_data.data.tpmProperties.count; i++) {
Expand Down
8 changes: 4 additions & 4 deletions src/drivers/i2c/tpm/cr50.c
Expand Up @@ -132,7 +132,7 @@ static int cr50_i2c_write(uint8_t addr, const uint8_t *buffer, size_t len)
static int process_reset(void)
{
struct stopwatch sw;
int rv = 0;
int rc = 0;
uint8_t access;

/*
Expand All @@ -148,9 +148,9 @@ static int process_reset(void)
const uint8_t mask =
TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY;

rv = cr50_i2c_read(TPM_ACCESS(0),
rc = cr50_i2c_read(TPM_ACCESS(0),
&access, sizeof(access));
if (rv || ((access & mask) == mask)) {
if (rc || ((access & mask) == mask)) {
/*
* Don't bombard the chip with traffic, let it keep
* processing the command.
Expand All @@ -165,7 +165,7 @@ static int process_reset(void)
return 0;
} while (!stopwatch_expired(&sw));

if (rv)
if (rc)
printk(BIOS_ERR, "Failed to read TPM\n");
else
printk(BIOS_ERR,
Expand Down
10 changes: 5 additions & 5 deletions src/mainboard/facebook/fbg1701/romstage.c
Expand Up @@ -73,7 +73,7 @@ static const uint8_t crtm_version[] =

int mb_crtm(void)
{
int status = TPM_E_IOERROR;
int rc = TPM_E_IOERROR;
TCG_PCR_EVENT2_HDR tcgEventHdr;

/* Use FirmwareVersion string to represent CRTM version. */
Expand All @@ -84,13 +84,13 @@ int mb_crtm(void)
tcgEventHdr.eventSize = sizeof(crtm_version);
printk(BIOS_DEBUG, "%s: EventSize - %u\n", __func__, tcgEventHdr.eventSize);

status = mboot_hash_extend_log(0, (uint8_t *)crtm_version,
rc = mboot_hash_extend_log(0, (uint8_t *)crtm_version,
tcgEventHdr.eventSize, &tcgEventHdr,
(uint8_t *)crtm_version);
if (status) {
printk(BIOS_DEBUG, "Measure CRTM Version returned 0x%x\n", status);
if (rc) {
printk(BIOS_DEBUG, "Measure CRTM Version returned 0x%x\n", rc);
}

return status;
return rc;
}
#endif
8 changes: 4 additions & 4 deletions src/mainboard/google/brya/mainboard.c
Expand Up @@ -34,11 +34,11 @@ static void mainboard_smbios_strings(struct device *dev, struct smbios_type11 *t

void mainboard_update_soc_chip_config(struct soc_intel_alderlake_config *config)
{
int ret;
int rc;

ret = tlcl_lib_init();
if (ret != VB2_SUCCESS) {
printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", ret);
rc = tlcl_lib_init();
if (rc != VB2_SUCCESS) {
printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", rc);
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/mainboard/google/dedede/mainboard.c
Expand Up @@ -14,11 +14,11 @@
static void mainboard_update_soc_chip_config(void)
{
struct soc_intel_jasperlake_config *cfg = config_of_soc();
int ret;
int rc;

ret = tlcl_lib_init();
if (ret != VB2_SUCCESS) {
printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", ret);
rc = tlcl_lib_init();
if (rc != VB2_SUCCESS) {
printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", rc);
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/mainboard/google/volteer/mainboard.c
Expand Up @@ -82,7 +82,7 @@ static void mainboard_enable(struct device *dev)

void mainboard_update_soc_chip_config(struct soc_intel_tigerlake_config *cfg)
{
int ret;
int rc;
if (!CONFIG(TPM_GOOGLE_CR50) || !CONFIG(SPI_TPM)) {
/*
* Negotiation of long interrupt pulses is only supported via SPI. I2C is only
Expand All @@ -93,9 +93,9 @@ void mainboard_update_soc_chip_config(struct soc_intel_tigerlake_config *cfg)
return;
}

ret = tlcl_lib_init();
if (ret != VB2_SUCCESS) {
printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", ret);
rc = tlcl_lib_init();
if (rc != VB2_SUCCESS) {
printk(BIOS_ERR, "tlcl_lib_init() failed: 0x%x\n", rc);
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/security/tpm/tspi/crtm.c
Expand Up @@ -192,11 +192,11 @@ int tspi_measure_cache_to_pcr(void)
i = 0;
while (!tpm_log_get(i++, &pcr, &digest_data, &digest_algo, &event_name)) {
printk(BIOS_DEBUG, "TPM: Write digest for %s into PCR %d\n", event_name, pcr);
int result = tlcl_extend(pcr, digest_data, digest_algo);
if (result != TPM_SUCCESS) {
int rc = tlcl_extend(pcr, digest_data, digest_algo);
if (rc != TPM_SUCCESS) {
printk(BIOS_ERR,
"TPM: Writing digest of %s into PCR failed with error %d\n",
event_name, result);
event_name, rc);
return VB2_ERROR_UNKNOWN;
}
}
Expand Down
116 changes: 58 additions & 58 deletions src/security/tpm/tspi/tspi.c
Expand Up @@ -15,49 +15,49 @@ static uint32_t tpm1_invoke_state_machine(void)
{
uint8_t disabled;
uint8_t deactivated;
uint32_t result = TPM_SUCCESS;
uint32_t rc = TPM_SUCCESS;

/* Check that the TPM is enabled and activated. */
result = tlcl_get_flags(&disabled, &deactivated, NULL);
if (result != TPM_SUCCESS) {
rc = tlcl_get_flags(&disabled, &deactivated, NULL);
if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't read capabilities.\n");
return result;
return rc;
}

if (disabled) {
printk(BIOS_INFO, "TPM: is disabled. Enabling...\n");

result = tlcl_set_enable();
if (result != TPM_SUCCESS) {
rc = tlcl_set_enable();
if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't set enabled state.\n");
return result;
return rc;
}
}

if (!!deactivated != CONFIG(TPM_DEACTIVATE)) {
printk(BIOS_INFO,
"TPM: Unexpected TPM deactivated state. Toggling...\n");
result = tlcl_set_deactivated(!deactivated);
if (result != TPM_SUCCESS) {
rc = tlcl_set_deactivated(!deactivated);
if (rc != TPM_SUCCESS) {
printk(BIOS_ERR,
"TPM: Can't toggle deactivated state.\n");
return result;
return rc;
}

deactivated = !deactivated;
result = TPM_E_MUST_REBOOT;
rc = TPM_E_MUST_REBOOT;
}

return result;
return rc;
}
#endif

static uint32_t tpm_setup_s3_helper(void)
{
uint32_t result;
uint32_t rc;

result = tlcl_resume();
switch (result) {
rc = tlcl_resume();
switch (rc) {
case TPM_SUCCESS:
break;

Expand All @@ -67,25 +67,25 @@ static uint32_t tpm_setup_s3_helper(void)
* in S3, so it's already initialized.
*/
printk(BIOS_INFO, "TPM: Already initialized.\n");
result = TPM_SUCCESS;
rc = TPM_SUCCESS;
break;

default:
printk(BIOS_ERR, "TPM: Resume failed (%#x).\n", result);
printk(BIOS_ERR, "TPM: Resume failed (%#x).\n", rc);
break;
}

return result;
return rc;
}

static uint32_t tpm_setup_epilogue(uint32_t result)
static uint32_t tpm_setup_epilogue(uint32_t rc)
{
if (result != TPM_SUCCESS)
if (rc != TPM_SUCCESS)
post_code(POSTCODE_TPM_FAILURE);
else
printk(BIOS_INFO, "TPM: setup succeeded\n");

return result;
return rc;
}

static int tpm_is_setup;
Expand Down Expand Up @@ -135,12 +135,12 @@ static inline int tspi_tpm_is_setup(void)
*/
uint32_t tpm_setup(int s3flag)
{
uint32_t result;
uint32_t rc;

result = tlcl_lib_init();
if (result != TPM_SUCCESS) {
rc = tlcl_lib_init();
if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't initialize.\n");
return tpm_setup_epilogue(result);
return tpm_setup_epilogue(rc);
}

/* Handle special init for S3 resume path */
Expand All @@ -149,69 +149,69 @@ uint32_t tpm_setup(int s3flag)
return tpm_setup_epilogue(tpm_setup_s3_helper());
}

result = tlcl_startup();
rc = tlcl_startup();
if (CONFIG(TPM_STARTUP_IGNORE_POSTINIT)
&& result == TPM_E_INVALID_POSTINIT) {
&& rc == TPM_E_INVALID_POSTINIT) {
printk(BIOS_DEBUG, "TPM: ignoring invalid POSTINIT\n");
result = TPM_SUCCESS;
rc = TPM_SUCCESS;
}
if (result != TPM_SUCCESS) {
if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't run startup command.\n");
return tpm_setup_epilogue(result);
return tpm_setup_epilogue(rc);
}

result = tlcl_assert_physical_presence();
if (result != TPM_SUCCESS) {
rc = tlcl_assert_physical_presence();
if (rc != TPM_SUCCESS) {
/*
* It is possible that the TPM was delivered with the physical
* presence command disabled. This tries enabling it, then
* tries asserting PP again.
*/
result = tlcl_physical_presence_cmd_enable();
if (result != TPM_SUCCESS) {
rc = tlcl_physical_presence_cmd_enable();
if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't enable physical presence command.\n");
return tpm_setup_epilogue(result);
return tpm_setup_epilogue(rc);
}

result = tlcl_assert_physical_presence();
if (result != TPM_SUCCESS) {
rc = tlcl_assert_physical_presence();
if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't assert physical presence.\n");
return tpm_setup_epilogue(result);
return tpm_setup_epilogue(rc);
}
}

#if CONFIG(TPM1)
result = tpm1_invoke_state_machine();
rc = tpm1_invoke_state_machine();
#endif
if (CONFIG(TPM_MEASURED_BOOT))
result = tspi_measure_cache_to_pcr();
rc = tspi_measure_cache_to_pcr();

tpm_is_setup = 1;
return tpm_setup_epilogue(result);
return tpm_setup_epilogue(rc);
}

uint32_t tpm_clear_and_reenable(void)
{
uint32_t result;
uint32_t rc;

printk(BIOS_INFO, "TPM: Clear and re-enable\n");
result = tlcl_force_clear();
if (result != TPM_SUCCESS) {
rc = tlcl_force_clear();
if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't initiate a force clear.\n");
return result;
return rc;
}

#if CONFIG(TPM1)
result = tlcl_set_enable();
if (result != TPM_SUCCESS) {
rc = tlcl_set_enable();
if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't set enabled state.\n");
return result;
return rc;
}

result = tlcl_set_deactivated(0);
if (result != TPM_SUCCESS) {
rc = tlcl_set_deactivated(0);
if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't set deactivated state.\n");
return result;
return rc;
}
#endif

Expand All @@ -221,24 +221,24 @@ uint32_t tpm_clear_and_reenable(void)
uint32_t tpm_extend_pcr(int pcr, enum vb2_hash_algorithm digest_algo,
const uint8_t *digest, size_t digest_len, const char *name)
{
uint32_t result;
uint32_t rc;

if (!digest)
return TPM_E_IOERROR;

if (tspi_tpm_is_setup()) {
result = tlcl_lib_init();
if (result != TPM_SUCCESS) {
rc = tlcl_lib_init();
if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't initialize library.\n");
return result;
return rc;
}

printk(BIOS_DEBUG, "TPM: Extending digest for `%s` into PCR %d\n", name, pcr);
result = tlcl_extend(pcr, digest, digest_algo);
if (result != TPM_SUCCESS) {
rc = tlcl_extend(pcr, digest, digest_algo);
if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Extending hash for `%s` into PCR %d failed.\n",
name, pcr);
return result;
return rc;
}
}

Expand Down

0 comments on commit 2460481

Please sign in to comment.