Skip to contentSkip to conversation

aspeed/hace: Initialize g_autofree pointer

PATCH In review Cédric Le Goater 3 participants 4 messages Apr 21, 2023 – Apr 25, 2023 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 aspeed/hace: Initialize g_autofree pointer

As mentioned in docs/devel/style.rst "Automatic memory deallocation":

* Variables declared with g_auto* MUST always be initialized, otherwise the cleanup function will use uninitialized stack memory

This avoids QEMU to coredump when running the "hash test" command under Zephyr.

Cc Steven Lee <[email protected]>
Cc Joel Stanley <[email protected]>
Fixes c5475b3f9a ("hw: Model ASPEED's Hash and Crypto Engine")
---
 hw/misc/aspeed_hace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/aspeed_hace.c +1 -1
index 12a761f1f5..b07506ec04 100644
@@ -189,7 +189,7 @@ static void do_hash_operation(AspeedHACEState *s, int algo, bool sg_mode,
                               bool acc_mode)
 {
     struct iovec iov[ASPEED_HACE_MAX_SG];
-    g_autofree uint8_t *digest_buf;
+    g_autofree uint8_t *digest_buf = NULL;
     size_t digest_len = 0;
     int niov = 0;
     int i;
Signature · 1 line
2.40.0
#1 lore raw
Quoted 5 lines · Cédric Le Goater

As mentioned in docs/devel/style.rst "Automatic memory deallocation":

* Variables declared with g_auto* MUST always be initialized, otherwise the cleanup function will use uninitialized stack memory

Quoted 7 lines

This avoids QEMU to coredump when running the "hash test" command under Zephyr.

Cc Steven Lee <[email protected]>
Cc Joel Stanley <[email protected]>
Fixes c5475b3f9a ("hw: Model ASPEED's Hash and Crypto Engine")

Alex,

FYI, with Thomas's fixes and this oneliner, make check-avocado ran fine with avocado bumped to version 100.1.

Cheers,

C.

Quoted 17 lines
---
  hw/misc/aspeed_hace.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/aspeed_hace.c +1 -1
index 12a761f1f5..b07506ec04 100644
@@ -189,7 +189,7 @@ static void do_hash_operation(AspeedHACEState *s, int algo, bool sg_mode,
                                bool acc_mode)
  {
      struct iovec iov[ASPEED_HACE_MAX_SG];
-    g_autofree uint8_t *digest_buf;
+    g_autofree uint8_t *digest_buf = NULL;
      size_t digest_len = 0;
      int niov = 0;
      int i;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Cédric Le Goater
Quoted 5 lines · Cédric Le Goater

As mentioned in docs/devel/style.rst "Automatic memory deallocation":

* Variables declared with g_auto* MUST always be initialized, otherwise the cleanup function will use uninitialized stack memory

Quoted 7 lines

This avoids QEMU to coredump when running the "hash test" command under Zephyr.

Cc Steven Lee <[email protected]>
Cc Joel Stanley <[email protected]>
Fixes c5475b3f9a ("hw: Model ASPEED's Hash and Crypto Engine")
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
Reviewed-by on v1 1/1
#3 lore raw
In reply to Cédric Le Goater
Quoted 21 lines · Cédric Le Goater

As mentioned in docs/devel/style.rst "Automatic memory deallocation":

* Variables declared with g_auto* MUST always be initialized, otherwise the cleanup function will use uninitialized stack memory

This avoids QEMU to coredump when running the "hash test" command under Zephyr.

Cc Steven Lee <[email protected]>
Cc Joel Stanley <[email protected]>
Fixes c5475b3f9a ("hw: Model ASPEED's Hash and Crypto Engine")
---
  hw/misc/aspeed_hace.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/aspeed_hace.c +0 -0
index 12a761f1f5..b07506ec04 100644

hw/misc/aspeed_hace.c static void do_hash_operation(AspeedHACEState *s, int algo, bool sg_mode, · line 192

Quoted 5 lines
hw/misc/aspeed_hace.c +1 -1
@@ -189,7 +189,7 @@ static void do_hash_operation(AspeedHACEState *s, int algo, bool sg_mode,
                                bool acc_mode)
  {
      struct iovec iov[ASPEED_HACE_MAX_SG];
-    g_autofree uint8_t *digest_buf;
+    g_autofree uint8_t *digest_buf = NULL;

We maybe need a checkpatch.pl rule to catch such bugs...