diff mbox

[tpmdd-devel] tpm: print tpm error code in hex for TPM2.0 devices

Message ID 20170428171809.qtyb7naoezf7ern3@rhwork
State New
Headers show

Commit Message

Jerry Snitselaar April 28, 2017, 5:18 p.m. UTC
On Fri Apr 28 17, Jarkko Sakkinen wrote:
>On Wed, Apr 26, 2017 at 03:39:54PM -0700, Jerry Snitselaar wrote:
>> For easier decoding, output the error code returned
>> from the tpm device in hex when the device is TPM2.0.
>>
>> Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
>> Cc: Peter Huewe <peterhuewe@gmx.de>
>> Cc: Marcel Selhorst <tpmdd@selhorst.net>
>> Cc: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
>> Reported-by: Ken Goldman <kgoldman@us.ibm.com>
>> Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
>> ---
>>  drivers/char/tpm/tpm-interface.c | 11 ++++++++---
>>  1 file changed, 8 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
>> index bd2128e0b56c..b6c67eef9ae7 100644
>> --- a/drivers/char/tpm/tpm-interface.c
>> +++ b/drivers/char/tpm/tpm-interface.c
>> @@ -453,9 +453,14 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *buf,
>>  		return -EFAULT;
>>
>>  	err = be32_to_cpu(header->return_code);
>> -	if (err != 0 && desc)
>> -		dev_err(&chip->dev, "A TPM error (%d) occurred %s\n", err,
>> -			desc);
>> +	if (err != 0 && desc) {
>> +		if (chip->flags & TPM_CHIP_FLAG_TPM2)
>> +			dev_err(&chip->dev, "A TPM 2.0 error (0x%x) occurred %s\n",
>> +				err, desc);
>> +		else
>> +			dev_err(&chip->dev, "A TPM error (%d) occurred %s\n",
>> +				err, desc);
>> +	}
>
>Is there a reason for not to apply this also to TPM 1.2?
>
>/Jarkko
>

The 2.0 spec lists the response codes in hex, while the 1.2 spec lists them
in decimal. Maybe something like the following instead?

index 158c1db83f05..1f433d56f53c 100644

>>  	if (err)
>>  		return err;
>>
>> --
>> 2.13.0.rc0.45.ge2cb6ab84
>>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

Comments

Jarkko Sakkinen April 29, 2017, 11:17 a.m. UTC | #1
On Fri, Apr 28, 2017 at 10:18:09AM -0700, Jerry Snitselaar wrote:
> On Fri Apr 28 17, Jarkko Sakkinen wrote:
> > On Wed, Apr 26, 2017 at 03:39:54PM -0700, Jerry Snitselaar wrote:
> > > For easier decoding, output the error code returned
> > > from the tpm device in hex when the device is TPM2.0.
> > > 
> > > Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > Cc: Peter Huewe <peterhuewe@gmx.de>
> > > Cc: Marcel Selhorst <tpmdd@selhorst.net>
> > > Cc: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
> > > Reported-by: Ken Goldman <kgoldman@us.ibm.com>
> > > Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
> > > ---
> > >  drivers/char/tpm/tpm-interface.c | 11 ++++++++---
> > >  1 file changed, 8 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> > > index bd2128e0b56c..b6c67eef9ae7 100644
> > > --- a/drivers/char/tpm/tpm-interface.c
> > > +++ b/drivers/char/tpm/tpm-interface.c
> > > @@ -453,9 +453,14 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, const void *buf,
> > >  		return -EFAULT;
> > > 
> > >  	err = be32_to_cpu(header->return_code);
> > > -	if (err != 0 && desc)
> > > -		dev_err(&chip->dev, "A TPM error (%d) occurred %s\n", err,
> > > -			desc);
> > > +	if (err != 0 && desc) {
> > > +		if (chip->flags & TPM_CHIP_FLAG_TPM2)
> > > +			dev_err(&chip->dev, "A TPM 2.0 error (0x%x) occurred %s\n",
> > > +				err, desc);
> > > +		else
> > > +			dev_err(&chip->dev, "A TPM error (%d) occurred %s\n",
> > > +				err, desc);
> > > +	}
> > 
> > Is there a reason for not to apply this also to TPM 1.2?
> > 
> > /Jarkko
> > 
> 
> The 2.0 spec lists the response codes in hex, while the 1.2 spec lists them
> in decimal. Maybe something like the following instead?

Ah. Well, I thinkthe original patch is fine then. 

Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

/Jarkko

> 
> index 158c1db83f05..1f433d56f53c 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -526,8 +526,8 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space,
> 
>        err = be32_to_cpu(header->return_code);
>        if (err != 0 && desc)
> -               dev_err(&chip->dev, "A TPM error (%d) occurred %s\n", err,
> -                       desc);
> +               dev_err(&chip->dev, "A TPM error (%d (0x%x)) occurred %s\n", err,
> +                       err, desc);
>        if (err)
>                return err;
> 
> 
> > >  	if (err)
> > >  		return err;
> > > 
> > > --
> > > 2.13.0.rc0.45.ge2cb6ab84
> > > 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
diff mbox

Patch

--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -526,8 +526,8 @@  ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space,
 
        err = be32_to_cpu(header->return_code);
        if (err != 0 && desc)
-               dev_err(&chip->dev, "A TPM error (%d) occurred %s\n", err,
-                       desc);
+               dev_err(&chip->dev, "A TPM error (%d (0x%x)) occurred %s\n", err,
+                       err, desc);
        if (err)
                return err;