diff mbox series

[v3,03/16] tpm: return 0 from pcrs_show() when tpm1_pcr_read() fails

Message ID 20181105014552.20262-4-jarkko.sakkinen@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series Remove nested TPM operations | expand

Commit Message

Jarkko Sakkinen Nov. 5, 2018, 1:45 a.m. UTC
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>
---
 drivers/char/tpm/tpm-sysfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Stefan Berger Nov. 5, 2018, 9:54 p.m. UTC | #1
On 11/4/18 8:45 PM, Jarkko Sakkinen wrote:
> 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>
> ---
>   drivers/char/tpm/tpm-sysfs.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
> index 7ed7eb6f906a..d3b05c7526c8 100644
> --- a/drivers/char/tpm/tpm-sysfs.c
> +++ b/drivers/char/tpm/tpm-sysfs.c
> @@ -115,13 +115,15 @@ static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr,
>   	for (i = 0; i < num_pcrs; i++) {
>   		rc = tpm1_pcr_read(chip, i, digest);
>   		if (rc)
> -			break;
> +			goto out;

Previous patch said "Return zero when tpm_buf_init() fails as we do for 
other functions in tpm-sysfs.c.". Why not return 0 in this case as well?


>   		str += sprintf(str, "PCR-%02d: ", i);
>   		for (j = 0; j < TPM_DIGEST_SIZE; j++)
>   			str += sprintf(str, "%02X ", digest[j]);
>   		str += sprintf(str, "\n");
>   	}
> -	return str - buf;
> +	rc = str - buf;
> +out:
> +	return rc;
>   }
>   static DEVICE_ATTR_RO(pcrs);
>
Jarkko Sakkinen Nov. 6, 2018, 5:54 a.m. UTC | #2
On Mon, Nov 05, 2018 at 04:54:52PM -0500, Stefan Berger wrote:
> On 11/4/18 8:45 PM, Jarkko Sakkinen wrote:
> > 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>
> > ---
> >   drivers/char/tpm/tpm-sysfs.c | 6 ++++--
> >   1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
> > index 7ed7eb6f906a..d3b05c7526c8 100644
> > --- a/drivers/char/tpm/tpm-sysfs.c
> > +++ b/drivers/char/tpm/tpm-sysfs.c
> > @@ -115,13 +115,15 @@ static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr,
> >   	for (i = 0; i < num_pcrs; i++) {
> >   		rc = tpm1_pcr_read(chip, i, digest);
> >   		if (rc)
> > -			break;
> > +			goto out;
> 
> Previous patch said "Return zero when tpm_buf_init() fails as we do for
> other functions in tpm-sysfs.c.". Why not return 0 in this case as well?

Yes, good catch, thank you.

/Jarkko
diff mbox series

Patch

diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
index 7ed7eb6f906a..d3b05c7526c8 100644
--- a/drivers/char/tpm/tpm-sysfs.c
+++ b/drivers/char/tpm/tpm-sysfs.c
@@ -115,13 +115,15 @@  static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr,
 	for (i = 0; i < num_pcrs; i++) {
 		rc = tpm1_pcr_read(chip, i, digest);
 		if (rc)
-			break;
+			goto out;
 		str += sprintf(str, "PCR-%02d: ", i);
 		for (j = 0; j < TPM_DIGEST_SIZE; j++)
 			str += sprintf(str, "%02X ", digest[j]);
 		str += sprintf(str, "\n");
 	}
-	return str - buf;
+	rc = str - buf;
+out:
+	return rc;
 }
 static DEVICE_ATTR_RO(pcrs);