[PATCH v10 4/4] tpm_vpm_proxy: Use stack for TPM_CC_SET_LOCALITY

Jarkko Sakkinen
2025-09-21T02:08:30Z

From: Jarkko Sakkinen <jarkko.sakkinen@opinsys.com>

Use stack allocation for TPM_CC_SET_LOCALITY, as it has known fixed size.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@opinsys.com>
---
drivers/char/tpm/tpm1-cmd.c | 2 +-
drivers/char/tpm/tpm_vtpm_proxy.c | 12 +++++-------
2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index 11c16ad9b2a7..433908cfb4a9 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -328,7 +328,7 @@ static int tpm1_startup(struct tpm_chip *chip)
int rc;

dev_info(&chip->dev, "TPM_Startup\n");
- tpm_buf_init(buf, TPM_BUF_INT_SIZE);
+ tpm_buf_init(buf, TPM_BUF_MIN_SIZE);
tpm_buf_reset(buf, TPM_TAG_RQU_COMMAND, TPM_ORD_STARTUP);
tpm_buf_append_u16(buf, TPM_ST_CLEAR);
rc = tpm_transmit_cmd(chip, buf, 0, "TPM_Startup");
diff --git a/drivers/char/tpm/tpm_vtpm_proxy.c b/drivers/char/tpm/tpm_vtpm_proxy.c
index e5de14379eb2..0f1b1b67ed4e 100644
--- a/drivers/char/tpm/tpm_vtpm_proxy.c
+++ b/drivers/char/tpm/tpm_vtpm_proxy.c
@@ -395,15 +395,13 @@ static bool vtpm_proxy_tpm_req_canceled(struct tpm_chip *chip, u8 status)

static int vtpm_proxy_request_locality(struct tpm_chip *chip, int locality)
{
- int rc;
- const struct tpm_header *header;
struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev);
+ u8 buf_data[TPM_BUF_MIN_SIZE];
+ struct tpm_buf *buf = (struct tpm_buf *)buf_data;
+ const struct tpm_header *header;
+ int rc;

- struct tpm_buf *buf __free(kfree) = kzalloc(PAGE_SIZE, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
-
- tpm_buf_init(buf, TPM_BUF_MAX_SIZE);
+ tpm_buf_init(buf, TPM_BUF_MIN_SIZE);
if (chip->flags & TPM_CHIP_FLAG_TPM2)
tpm_buf_reset(buf, TPM2_ST_SESSIONS, TPM2_CC_SET_LOCALITY);
else
--
2.39.5