[PATCH v2 1/2] cmd: tpm: Fix attempt to return value not in enum

Andrew Goodbody andrew.goodbody at linaro.org
Mon Jun 30 12:06:36 CEST 2025


On 30/06/2025 08:23, Ilias Apalodimas wrote:
> Hi Andrew
> 
> 
> 
> On Fri, 27 Jun 2025 at 12:37, Andrew Goodbody
> <andrew.goodbody at linaro.org> wrote:
>>
>> The function tpm2_name_to_algorithm is defined as returning an
>> enum for the algorithm specified but it also attempts to return
>> an error on failure, but that error is not included in the enum.
>> Add the error to the enum so that it can be returned.
>>
>> This issue was reported by Smatch.
>>
>> Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
>> ---
>>   cmd/tpm-v1.c                 | 1 +
>>   cmd/tpm_test.c               | 1 +
>>   drivers/tpm/sandbox_common.c | 1 +
>>   include/tpm-v2.h             | 1 +
>>   4 files changed, 4 insertions(+)
>>
>> diff --git a/cmd/tpm-v1.c b/cmd/tpm-v1.c
>> index 6e019d1c729..25402f7543b 100644
>> --- a/cmd/tpm-v1.c
>> +++ b/cmd/tpm-v1.c
>> @@ -8,6 +8,7 @@
>>   #include <malloc.h>
>>   #include <vsprintf.h>
>>   #include <asm/unaligned.h>
>> +#include <linux/errno.h>
> 
> Why is this needed? Shouldn't it only be on the header file?

OK, I will rework it.

Andrew

> Thanks
> /Ilias
>>   #include <tpm-common.h>
>>   #include <tpm-v1.h>
>>   #include "tpm-user-utils.h"
>> diff --git a/cmd/tpm_test.c b/cmd/tpm_test.c
>> index af83d78c3fe..1d9644d5aae 100644
>> --- a/cmd/tpm_test.c
>> +++ b/cmd/tpm_test.c
>> @@ -7,6 +7,7 @@
>>   #include <cpu_func.h>
>>   #include <log.h>
>>   #include <time.h>
>> +#include <linux/errno.h>
>>   #include <tpm-v1.h>
>>   #include <linux/printk.h>
>>   #include "tpm-user-utils.h"
>> diff --git a/drivers/tpm/sandbox_common.c b/drivers/tpm/sandbox_common.c
>> index 596e0156389..4bc003a2c09 100644
>> --- a/drivers/tpm/sandbox_common.c
>> +++ b/drivers/tpm/sandbox_common.c
>> @@ -7,6 +7,7 @@
>>
>>   #define LOG_CATEGORY   UCLASS_TPM
>>
>> +#include <linux/errno.h>
>>   #include <tpm-v1.h>
>>   #include <tpm-v2.h>
>>   #include <asm/unaligned.h>
>> diff --git a/include/tpm-v2.h b/include/tpm-v2.h
>> index ece422df0c7..6c516dd3c9b 100644
>> --- a/include/tpm-v2.h
>> +++ b/include/tpm-v2.h
>> @@ -266,6 +266,7 @@ enum tpm2_return_codes {
>>    * TPM2 algorithms.
>>    */
>>   enum tpm2_algorithms {
>> +       TPM2_ALG_INVAL          = -EINVAL,
>>          TPM2_ALG_SHA1           = 0x04,
>>          TPM2_ALG_XOR            = 0x0A,
>>          TPM2_ALG_SHA256         = 0x0B,
>>
>> --
>> 2.39.5
>>



More information about the U-Boot mailing list