diff mbox series

[v3,1/5] tpm: change the end marker of the active_banks array to zero

Message ID 20181030154711.2782-2-roberto.sassu@huawei.com (mailing list archive)
State New, archived
Headers show
Series tpm: retrieve digest size of unknown algorithms from TPM | expand

Commit Message

Roberto Sassu Oct. 30, 2018, 3:47 p.m. UTC
This patch changes the end marker of the active_banks array from
TPM2_ALG_ERROR to zero.

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---
 drivers/char/tpm/tpm-interface.c | 2 +-
 drivers/char/tpm/tpm2-cmd.c      | 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)

Comments

Jarkko Sakkinen Oct. 30, 2018, 7:45 p.m. UTC | #1
On Tue, 30 Oct 2018, Roberto Sassu wrote:
> This patch changes the end marker of the active_banks array from
> TPM2_ALG_ERROR to zero.
>
> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> ---
> drivers/char/tpm/tpm-interface.c | 2 +-
> drivers/char/tpm/tpm2-cmd.c      | 3 ---
> 2 files changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 1a803b0cf980..f7fc4b5ee239 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -1051,7 +1051,7 @@ int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash)
> 		memset(digest_list, 0, sizeof(digest_list));
>
> 		for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
> -			    chip->active_banks[i] != TPM2_ALG_ERROR; i++) {
> +			    chip->active_banks[i]; i++) {
> 			digest_list[i].alg_id = chip->active_banks[i];
> 			memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
> 			count++;
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index c31b490bd41d..046c9d8f3c1e 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -908,9 +908,6 @@ static ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
> 	}
>
> out:
> -	if (i < ARRAY_SIZE(chip->active_banks))
> -		chip->active_banks[i] = TPM2_ALG_ERROR;
> -
> 	tpm_buf_destroy(&buf);
>
> 	return rc;
> -- 
> 2.17.1
>
>

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

/Jarkko
Mimi Zohar Oct. 31, 2018, 2:43 p.m. UTC | #2
On Tue, 2018-10-30 at 16:47 +0100, Roberto Sassu wrote:
> This patch changes the end marker of the active_banks array from
> TPM2_ALG_ERROR to zero.

The patch description is a bit off.

TPM2_ALG_ERROR is defined as zero.  Since tpm_chip_alloc() calls
kzalloc to allocate the structure, there is no need to explicitly set
the active_banks end marker to TPM2_ALG_ERROR, nor is there a need to
explicitly test for the end marker.

This patch removes explicitly setting the end marker and changes the
coding style.

> 
> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> ---
>  drivers/char/tpm/tpm-interface.c | 2 +-
>  drivers/char/tpm/tpm2-cmd.c      | 3 ---
>  2 files changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> index 1a803b0cf980..f7fc4b5ee239 100644
> --- a/drivers/char/tpm/tpm-interface.c
> +++ b/drivers/char/tpm/tpm-interface.c
> @@ -1051,7 +1051,7 @@ int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash)
>  		memset(digest_list, 0, sizeof(digest_list));
>  
>  		for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
> -			    chip->active_banks[i] != TPM2_ALG_ERROR; i++) {
> +			    chip->active_banks[i]; i++) {
>  			digest_list[i].alg_id = chip->active_banks[i];
>  			memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
>  			count++;
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index c31b490bd41d..046c9d8f3c1e 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -908,9 +908,6 @@ static ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
>  	}
>  
>  out:
> -	if (i < ARRAY_SIZE(chip->active_banks))
> -		chip->active_banks[i] = TPM2_ALG_ERROR;
> -
>  	tpm_buf_destroy(&buf);
>  
>  	return rc;
Mimi Zohar Nov. 1, 2018, 2:42 p.m. UTC | #3
On Wed, 2018-10-31 at 10:43 -0400, Mimi Zohar wrote:
> On Tue, 2018-10-30 at 16:47 +0100, Roberto Sassu wrote:
> > This patch changes the end marker of the active_banks array from
> > TPM2_ALG_ERROR to zero.
> 
> The patch description is a bit off.
> 
> TPM2_ALG_ERROR is defined as zero.  Since tpm_chip_alloc() calls
> kzalloc to allocate the structure, there is no need to explicitly set
> the active_banks end marker to TPM2_ALG_ERROR, nor is there a need to
> explicitly test for the end marker.
> 
> This patch removes explicitly setting the end marker and changes the
> coding style.
> 
> > 
> > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> > ---
> >  drivers/char/tpm/tpm-interface.c | 2 +-
> >  drivers/char/tpm/tpm2-cmd.c      | 3 ---
> >  2 files changed, 1 insertion(+), 4 deletions(-)
> > 
> > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> > index 1a803b0cf980..f7fc4b5ee239 100644
> > --- a/drivers/char/tpm/tpm-interface.c
> > +++ b/drivers/char/tpm/tpm-interface.c
> > @@ -1051,7 +1051,7 @@ int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash)
> >  		memset(digest_list, 0, sizeof(digest_list));
> >  
> >  		for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
> > -			    chip->active_banks[i] != TPM2_ALG_ERROR; i++) {
> > +			    chip->active_banks[i]; i++) {
> >  			digest_list[i].alg_id = chip->active_banks[i];
> >  			memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
> >  			count++;

The fourth patch further updates this code.  Please move those changes
to this first patch.  No need to touch the same code in both places.

                for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
-                           chip->active_banks[i]; i++) {
-                       digest_list[i].alg_id = chip->active_banks[i];
+                           chip->active_banks[i].alg_id; i++) {
+                       digest_list[i].alg_id = chip->active_banks[i].alg_id;
                        memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
                        count++;
                }
Mimi

> > diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> > index c31b490bd41d..046c9d8f3c1e 100644
> > --- a/drivers/char/tpm/tpm2-cmd.c
> > +++ b/drivers/char/tpm/tpm2-cmd.c
> > @@ -908,9 +908,6 @@ static ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
> >  	}
> >  
> >  out:
> > -	if (i < ARRAY_SIZE(chip->active_banks))
> > -		chip->active_banks[i] = TPM2_ALG_ERROR;
> > -
> >  	tpm_buf_destroy(&buf);
> >  
> >  	return rc;
>
Roberto Sassu Nov. 5, 2018, 8:07 a.m. UTC | #4
On 10/31/2018 3:43 PM, Mimi Zohar wrote:
> On Tue, 2018-10-30 at 16:47 +0100, Roberto Sassu wrote:
>> This patch changes the end marker of the active_banks array from
>> TPM2_ALG_ERROR to zero.
> 
> The patch description is a bit off.
> 
> TPM2_ALG_ERROR is defined as zero.  Since tpm_chip_alloc() calls
> kzalloc to allocate the structure, there is no need to explicitly set
> the active_banks end marker to TPM2_ALG_ERROR, nor is there a need to
> explicitly test for the end marker.
> 
> This patch removes explicitly setting the end marker and changes the
> coding style.

Thanks, I will use the text above as the patch description.

Roberto


>> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
>> ---
>>   drivers/char/tpm/tpm-interface.c | 2 +-
>>   drivers/char/tpm/tpm2-cmd.c      | 3 ---
>>   2 files changed, 1 insertion(+), 4 deletions(-)
>>
>> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
>> index 1a803b0cf980..f7fc4b5ee239 100644
>> --- a/drivers/char/tpm/tpm-interface.c
>> +++ b/drivers/char/tpm/tpm-interface.c
>> @@ -1051,7 +1051,7 @@ int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash)
>>   		memset(digest_list, 0, sizeof(digest_list));
>>   
>>   		for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
>> -			    chip->active_banks[i] != TPM2_ALG_ERROR; i++) {
>> +			    chip->active_banks[i]; i++) {
>>   			digest_list[i].alg_id = chip->active_banks[i];
>>   			memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
>>   			count++;
>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>> index c31b490bd41d..046c9d8f3c1e 100644
>> --- a/drivers/char/tpm/tpm2-cmd.c
>> +++ b/drivers/char/tpm/tpm2-cmd.c
>> @@ -908,9 +908,6 @@ static ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
>>   	}
>>   
>>   out:
>> -	if (i < ARRAY_SIZE(chip->active_banks))
>> -		chip->active_banks[i] = TPM2_ALG_ERROR;
>> -
>>   	tpm_buf_destroy(&buf);
>>   
>>   	return rc;
>
Roberto Sassu Nov. 5, 2018, 8:10 a.m. UTC | #5
On 11/1/2018 3:42 PM, Mimi Zohar wrote:
> On Wed, 2018-10-31 at 10:43 -0400, Mimi Zohar wrote:
>> On Tue, 2018-10-30 at 16:47 +0100, Roberto Sassu wrote:
>>> This patch changes the end marker of the active_banks array from
>>> TPM2_ALG_ERROR to zero.
>>
>> The patch description is a bit off.
>>
>> TPM2_ALG_ERROR is defined as zero.  Since tpm_chip_alloc() calls
>> kzalloc to allocate the structure, there is no need to explicitly set
>> the active_banks end marker to TPM2_ALG_ERROR, nor is there a need to
>> explicitly test for the end marker.
>>
>> This patch removes explicitly setting the end marker and changes the
>> coding style.
>>
>>>
>>> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
>>> ---
>>>   drivers/char/tpm/tpm-interface.c | 2 +-
>>>   drivers/char/tpm/tpm2-cmd.c      | 3 ---
>>>   2 files changed, 1 insertion(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
>>> index 1a803b0cf980..f7fc4b5ee239 100644
>>> --- a/drivers/char/tpm/tpm-interface.c
>>> +++ b/drivers/char/tpm/tpm-interface.c
>>> @@ -1051,7 +1051,7 @@ int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash)
>>>   		memset(digest_list, 0, sizeof(digest_list));
>>>   
>>>   		for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
>>> -			    chip->active_banks[i] != TPM2_ALG_ERROR; i++) {
>>> +			    chip->active_banks[i]; i++) {
>>>   			digest_list[i].alg_id = chip->active_banks[i];
>>>   			memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
>>>   			count++;
> 
> The fourth patch further updates this code.  Please move those changes
> to this first patch.  No need to touch the same code in both places.

alg_id is introduced in patch 4/5. It cannot be moved here.

Roberto


>                  for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
> -                           chip->active_banks[i]; i++) {
> -                       digest_list[i].alg_id = chip->active_banks[i];
> +                           chip->active_banks[i].alg_id; i++) {
> +                       digest_list[i].alg_id = chip->active_banks[i].alg_id;
>                          memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
>                          count++;
>                  }
> Mimi
> 
>>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>>> index c31b490bd41d..046c9d8f3c1e 100644
>>> --- a/drivers/char/tpm/tpm2-cmd.c
>>> +++ b/drivers/char/tpm/tpm2-cmd.c
>>> @@ -908,9 +908,6 @@ static ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
>>>   	}
>>>   
>>>   out:
>>> -	if (i < ARRAY_SIZE(chip->active_banks))
>>> -		chip->active_banks[i] = TPM2_ALG_ERROR;
>>> -
>>>   	tpm_buf_destroy(&buf);
>>>   
>>>   	return rc;
>>
>
Mimi Zohar Nov. 5, 2018, 1:02 p.m. UTC | #6
> >>> diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
> >>> index 1a803b0cf980..f7fc4b5ee239 100644
> >>> --- a/drivers/char/tpm/tpm-interface.c
> >>> +++ b/drivers/char/tpm/tpm-interface.c
> >>> @@ -1051,7 +1051,7 @@ int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash)
> >>>   		memset(digest_list, 0, sizeof(digest_list));
> >>>   
> >>>   		for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
> >>> -			    chip->active_banks[i] != TPM2_ALG_ERROR; i++) {
> >>> +			    chip->active_banks[i]; i++) {
> >>>   			digest_list[i].alg_id = chip->active_banks[i];
> >>>   			memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
> >>>   			count++;
> > 
> > The fourth patch further updates this code.  Please move those changes
> > to this first patch.  No need to touch the same code in both places.
> 
> alg_id is introduced in patch 4/5. It cannot be moved here.

Thanks, I missed that.

Mimi
diff mbox series

Patch

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 1a803b0cf980..f7fc4b5ee239 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -1051,7 +1051,7 @@  int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash)
 		memset(digest_list, 0, sizeof(digest_list));
 
 		for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
-			    chip->active_banks[i] != TPM2_ALG_ERROR; i++) {
+			    chip->active_banks[i]; i++) {
 			digest_list[i].alg_id = chip->active_banks[i];
 			memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
 			count++;
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index c31b490bd41d..046c9d8f3c1e 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -908,9 +908,6 @@  static ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
 	}
 
 out:
-	if (i < ARRAY_SIZE(chip->active_banks))
-		chip->active_banks[i] = TPM2_ALG_ERROR;
-
 	tpm_buf_destroy(&buf);
 
 	return rc;