[PATCH] cmd: tpm: Fix attempt to return value not in enum
Andrew Goodbody
andrew.goodbody at linaro.org
Thu Jun 26 11:57:36 CEST 2025
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.
Fixes: 954b95e77ef0 (tpm-v2: add support for mapping algorithm names to algos)
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>
#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,
---
base-commit: 903eb123236ccbd8ef05d43507a2a910b785bd56
change-id: 20250625-tpm_enum-098ee9a5eb6b
Best regards,
--
Andrew Goodbody <andrew.goodbody at linaro.org>
More information about the U-Boot
mailing list