Re: [PATCH 2/4] backends/tpmL Avoid using g_alloca()

2025-06-08 Thread Stefan Berger




On 6/6/25 4:14 AM, Thomas Huth wrote:

On 05/06/2025 21.35, Philippe Mathieu-Daudé wrote:

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é 
---
  backends/tpm/tpm_emulator.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c
index 43d350e895d..4a234ab2c0b 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);


With the typo fixed:
Reviewed-by: Thomas Huth 

Reviewed-by: Stefan Berger 









Re: [PATCH 2/4] backends/tpmL Avoid using g_alloca()

2025-06-08 Thread Stefan Berger




On 6/5/25 3:35 PM, Philippe Mathieu-Daudé wrote:

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é 


Reviewed-by: Stefan Berger 


---
  backends/tpm/tpm_emulator.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c
index 43d350e895d..4a234ab2c0b 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);
  





Re: [PATCH 2/4] backends/tpmL Avoid using g_alloca()

2025-06-06 Thread Thomas Huth

On 05/06/2025 21.35, Philippe Mathieu-Daudé wrote:

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é 
---
  backends/tpm/tpm_emulator.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c
index 43d350e895d..4a234ab2c0b 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);
  


With the typo fixed:
Reviewed-by: Thomas Huth 




Re: [PATCH 2/4] backends/tpmL Avoid using g_alloca()

2025-06-06 Thread Philippe Mathieu-Daudé

On 5/6/25 23:23, BALATON Zoltan wrote:

On Thu, 5 Jun 2025, Philippe Mathieu-Daudé wrote:

tpm_emulator_ctrlcmd() is not in hot path.
Use the heap instead of the stack, removing
the g_alloca() call.


Typo in subject L -> :


Oops thanks, I hurt my ring finger and have it now tied with the
middle finger; typing like that is slower and makes me do a lot
of typos ;)




Re: [PATCH 2/4] backends/tpmL Avoid using g_alloca()

2025-06-05 Thread BALATON Zoltan

On Thu, 5 Jun 2025, Philippe Mathieu-Daudé wrote:

tpm_emulator_ctrlcmd() is not in hot path.
Use the heap instead of the stack, removing
the g_alloca() call.


Typo in subject L -> :

Regards,
BALATON Zoltan


Signed-off-by: Philippe Mathieu-Daudé 
---
backends/tpm/tpm_emulator.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c
index 43d350e895d..4a234ab2c0b 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);



[PATCH 2/4] backends/tpmL Avoid using g_alloca()

2025-06-05 Thread Philippe Mathieu-Daudé
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é 
---
 backends/tpm/tpm_emulator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c
index 43d350e895d..4a234ab2c0b 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);
 
-- 
2.49.0