diff mbox

[4/5] tpm_tis: further simplify calculation of ordinal duration

Message ID 1448026354-6807-5-git-send-email-martin.wilck@ts.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Martin Wilck Nov. 20, 2015, 1:32 p.m. UTC
From: Martin Wilck <Martin.Wilck@ts.fujitsu.com>

commit 07b133e6060b ("char/tpm: simplify duration calculation and
eliminate smatch warning.") includes a misleading test that is
always false. The tpm_ordinal_duration table is only valid for
TPM_PROTECTED ordinals where the higher 16 bits are all 0, anyway.

v2: avoid misleading masking of the ordinal index, add comment.
Signed-off-by: Martin Wilck <Martin.Wilck@ts.fujitsu.com>
---
 drivers/char/tpm/tpm-interface.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Jarkko Sakkinen Nov. 21, 2015, 1:16 p.m. UTC | #1
On Fri, Nov 20, 2015 at 02:32:33PM +0100, martin.wilck@ts.fujitsu.com wrote:
> From: Martin Wilck <Martin.Wilck@ts.fujitsu.com>
> 
> commit 07b133e6060b ("char/tpm: simplify duration calculation and
> eliminate smatch warning.") includes a misleading test that is
> always false. The tpm_ordinal_duration table is only valid for
> TPM_PROTECTED ordinals where the higher 16 bits are all 0, anyway.
> 
> v2: avoid misleading masking of the ordinal index, add comment.
> Signed-off-by: Martin Wilck <Martin.Wilck@ts.fujitsu.com>

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

/Jarkko

> ---
>  drivers/char/tpm/tpm-interface.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index c50637d..afdc836 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -310,10 +310,12 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,
>  {
>  	int duration_idx = TPM_UNDEFINED;
>  	int duration = 0;
> -	u8 category = (ordinal >> 24) & 0xFF;
>  
> -	if ((category == TPM_PROTECTED_COMMAND && ordinal < TPM_MAX_ORDINAL) ||
> -	    (category == TPM_CONNECTION_COMMAND && ordinal < TSC_MAX_ORDINAL))
> +	/*
> +	 * We only have a duration table for protected commands, where the upper
> +	 * 16 bits are 0. For the few other ordinals the fallback will be used.
> +	 */
> +	if (ordinal < TPM_MAX_ORDINAL)
>  		duration_idx = tpm_ordinal_duration[ordinal];
>  
>  	if (duration_idx != TPM_UNDEFINED)
> -- 
> 1.8.3.1
> 
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> tpmdd-devel mailing list
> tpmdd-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tpmdd-devel

------------------------------------------------------------------------------
Jarkko Sakkinen Nov. 21, 2015, 8:15 p.m. UTC | #2
On Sat, Nov 21, 2015 at 03:16:53PM +0200, Jarkko Sakkinen wrote:
> On Fri, Nov 20, 2015 at 02:32:33PM +0100, martin.wilck@ts.fujitsu.com wrote:
> > From: Martin Wilck <Martin.Wilck@ts.fujitsu.com>
> > 
> > commit 07b133e6060b ("char/tpm: simplify duration calculation and
> > eliminate smatch warning.") includes a misleading test that is
> > always false. The tpm_ordinal_duration table is only valid for
> > TPM_PROTECTED ordinals where the higher 16 bits are all 0, anyway.
> > 
> > v2: avoid misleading masking of the ordinal index, add comment.
> > Signed-off-by: Martin Wilck <Martin.Wilck@ts.fujitsu.com>
> 
> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

Applied to https://github.com/jsakkine/linux-tpmdd/commits/master

/Jarkko

------------------------------------------------------------------------------
diff mbox

Patch

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index c50637d..afdc836 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -310,10 +310,12 @@  unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,
 {
 	int duration_idx = TPM_UNDEFINED;
 	int duration = 0;
-	u8 category = (ordinal >> 24) & 0xFF;
 
-	if ((category == TPM_PROTECTED_COMMAND && ordinal < TPM_MAX_ORDINAL) ||
-	    (category == TPM_CONNECTION_COMMAND && ordinal < TSC_MAX_ORDINAL))
+	/*
+	 * We only have a duration table for protected commands, where the upper
+	 * 16 bits are 0. For the few other ordinals the fallback will be used.
+	 */
+	if (ordinal < TPM_MAX_ORDINAL)
 		duration_idx = tpm_ordinal_duration[ordinal];
 
 	if (duration_idx != TPM_UNDEFINED)