Skip to content

Commit 4148467

Browse files
author
Jarkko Sakkinen
committed
tpm: return 0 from pcrs_show() when tpm1_pcr_read() fails
Do not print partial list of PCRs when tpm1_pcr_read() fails but instead return 0 from pcrs_show(). This is consistent behavior with other sysfs functions. Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Tested-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> Reviewed-by: James Bottomley <James.Bottomley@HansenPartnership.com> Tested-by: Alexander Steffen <Alexander.Steffen@infineon.com>
1 parent c628610 commit 4148467

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

drivers/char/tpm/tpm-sysfs.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,21 @@ static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr,
100100
{
101101
cap_t cap;
102102
u8 digest[TPM_DIGEST_SIZE];
103-
ssize_t rc;
104103
u32 i, j, num_pcrs;
105104
char *str = buf;
106105
struct tpm_chip *chip = to_tpm_chip(dev);
107106

108-
rc = tpm1_getcap(chip, TPM_CAP_PROP_PCR, &cap,
109-
"attempting to determine the number of PCRS",
110-
sizeof(cap.num_pcrs));
111-
if (rc)
107+
if (tpm1_getcap(chip, TPM_CAP_PROP_PCR, &cap,
108+
"attempting to determine the number of PCRS",
109+
sizeof(cap.num_pcrs)))
112110
return 0;
113111

114112
num_pcrs = be32_to_cpu(cap.num_pcrs);
115113
for (i = 0; i < num_pcrs; i++) {
116-
rc = tpm1_pcr_read(chip, i, digest);
117-
if (rc)
114+
if (tpm1_pcr_read(chip, i, digest)) {
115+
str = buf;
118116
break;
117+
}
119118
str += sprintf(str, "PCR-%02d: ", i);
120119
for (j = 0; j < TPM_DIGEST_SIZE; j++)
121120
str += sprintf(str, "%02X ", digest[j]);

0 commit comments

Comments
 (0)