aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilippe Mathieu-Daudé <philmd@linaro.org>2025-06-05 19:54:58 +0200
committerPhilippe Mathieu-Daudé <philmd@linaro.org>2025-06-10 12:59:09 +0200
commit0ff9cd9a6af54ccaa293e252aa356fb150788099 (patch)
tree7c9e6d5447155593eae26c1d194c2cc21f403382
parentc7785e243195799749242b5fc741b8fbf1053f82 (diff)
downloadqemu-0ff9cd9a6af54ccaa293e252aa356fb150788099.zip
qemu-0ff9cd9a6af54ccaa293e252aa356fb150788099.tar.gz
qemu-0ff9cd9a6af54ccaa293e252aa356fb150788099.tar.bz2
backends/tpm: Avoid using g_alloca()
tpm_emulator_ctrlcmd() is not in hot path. Use the heap instead of the stack, removing the g_alloca() call. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20250605193540.59874-3-philmd@linaro.org>
-rw-r--r--backends/tpm/tpm_emulator.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c
index 43d350e..4a234ab 100644
--- a/backends/tpm/tpm_emulator.c
+++ b/backends/tpm/tpm_emulator.c
@@ -129,11 +129,11 @@ static int tpm_emulator_ctrlcmd(TPMEmulator *tpm, unsigned long cmd, void *msg,
CharBackend *dev = &tpm->ctrl_chr;
uint32_t cmd_no = cpu_to_be32(cmd);
ssize_t n = sizeof(uint32_t) + msg_len_in;
- uint8_t *buf = NULL;
ptm_res res;
WITH_QEMU_LOCK_GUARD(&tpm->mutex) {
- buf = g_alloca(n);
+ g_autofree uint8_t *buf = g_malloc(n);
+
memcpy(buf, &cmd_no, sizeof(cmd_no));
memcpy(buf + sizeof(cmd_no), msg, msg_len_in);