From fd307fda578e04e4defb6e0ff47f8fe28a999d4a Mon Sep 17 00:00:00 2001 From: "Daniel P. Smith" Date: Fri, 13 Sep 2024 13:05:13 -0700 Subject: [PATCH] tpm: Support multiple localities in tpm_tis_request_locality() Validate that the input locality is within the correct range, as specified by TCG standards, and increase the locality count also for the positive return values. Signed-off-by: Daniel P. Smith Signed-off-by: Ross Philipson Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 3517db710423..75fb59df75a3 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -234,10 +234,13 @@ static int tpm_tis_request_locality(struct tpm_chip *chip, int l) struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); int ret = 0; + if (l < 0 || l > TPM_MAX_LOCALITY) + return -EINVAL; + mutex_lock(&priv->locality_count_mutex); if (priv->locality_count == 0) ret = __tpm_tis_request_locality(chip, l); - if (!ret) + if (ret >= 0) priv->locality_count++; mutex_unlock(&priv->locality_count_mutex); return ret; -- 2.47.0