cmd: tpm: Fix attempt to return value not in enum
PATCH 1/1 cmd: tpm: Fix attempt to return value not in enum
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.
--- 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(+)
cmd/tpm-v1.c +1 -0
@@ -8,6 +8,7 @@#include <malloc.h> #include <vsprintf.h> #include <asm/unaligned.h> +#include <linux/errno.h> #include <tpm-common.h> #include <tpm-v1.h> #include "tpm-user-utils.h"
cmd/tpm_test.c +1 -0
@@ -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"
drivers/tpm/sandbox_common.c +1 -0
@@ -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>
include/tpm-v2.h +1 -0
@@ -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 ,
---
base-commit: 903eb123236ccbd8ef05d43507a2a910b785bd56
change-id: 20250625-tpm_enum-098ee9a5eb6b
Best regards,
Signature · 1 line
Andrew Goodbody <[email protected]>
Hi Andrew,
Quoted 9 lines · Andrew Goodbody
The function
tpm2_name_to_algorithmis 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.
Fixes 954b95e77ef0 (tpm-v2: add support for mapping algorithm names to algos)
This doesn't really fix a bug so please drop this.
Quoted 1 line
Signed-off-by Andrew Goodbody <[email protected]>
The change itself is fine , but can you also change the callsites to return TPM2_ALG_INVAL instead of -EINVAL?
Thanks
/Ilias
Quoted 64 lines
--- 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(+)cmd/tpm-v1.c +1
-0@@ -8,6 +8,7 @@#include <malloc.h> #include <vsprintf.h> #include <asm/unaligned.h> +#include <linux/errno.h> #include <tpm-common.h> #include <tpm-v1.h> #include "tpm-user-utils.h" cmd/tpm_test.c +1
-0@@ -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" drivers/tpm/sandbox_common.c +1
-0@@ -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> include/tpm-v2.h +1
-1@@ -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 , ---base-commit:
903eb123236ccbd8ef05d43507a2a910b785bd56
change-id: 20250625-tpm_enum-098ee9a5eb6bBest regards,
--
Andrew Goodbody <[email protected]>