[PATCH v10 2/4] tpm, tpm1-cmd: Use stack for trivial cases

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

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

Use stack allocation for trivial "low-hanging fruit" sites, which are often
also critical code paths associated with probing and power management.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@opinsys.com>
---
drivers/char/tpm/tpm1-cmd.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index ca3e7f9a105d..11c16ad9b2a7 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -323,19 +323,15 @@ unsigned long tpm1_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
*/
static int tpm1_startup(struct tpm_chip *chip)
{
+ u8 buf_data[TPM_BUF_MIN_SIZE];
+ struct tpm_buf *buf = (struct tpm_buf *)buf_data;
int rc;

- struct tpm_buf *buf __free(kfree) = kzalloc(PAGE_SIZE, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
-
- dev_info(&chip->dev, "starting up the TPM manually\n");
-
- tpm_buf_init(buf, TPM_BUF_MAX_SIZE);
+ dev_info(&chip->dev, "TPM_Startup\n");
+ tpm_buf_init(buf, TPM_BUF_INT_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, "attempting to start the TPM");
+ rc = tpm_transmit_cmd(chip, buf, 0, "TPM_Startup");
return rc;
}

--
2.39.5