qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] target/s390x/arch_dump: Simplify memory allocation in s390x_


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH] target/s390x/arch_dump: Simplify memory allocation in s390x_write_elf64_notes()
Date: Wed, 15 Feb 2023 08:10:00 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.7.2

On 15/2/23 06:48, Thomas Huth wrote:
We are not on a hot path here, so there is no real need for the logic
here with the split heap and stack space allocation. Simplify it by
always allocating memory from the heap.

Suggested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
  Based-on: <20230214141056.680969-1-thuth@redhat.com>

  target/s390x/arch_dump.c | 20 ++++++--------------
  1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/target/s390x/arch_dump.c b/target/s390x/arch_dump.c
index a7c44ba49d..84e17effda 100644
--- a/target/s390x/arch_dump.c
+++ b/target/s390x/arch_dump.c
@@ -227,25 +227,23 @@ static int s390x_write_elf64_notes(const char *note_name,
                                         DumpState *s,
                                         const NoteFuncDesc *funcs)
  {
-    Note note, *notep;
+    g_autofree Note *notep = NULL;
      const NoteFuncDesc *nf;
-    int note_size, content_size;
+    int note_size, prev_size = 0, content_size;

We can start with:

  prev_size = sizeof(Note);

If this goes thru your tree, feel free to modify without respining.


Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Thanks!

      int ret = -1;
- assert(strlen(note_name) < sizeof(note.name));
+    assert(strlen(note_name) < sizeof(notep->name));
for (nf = funcs; nf->note_contents_func; nf++) {
-        notep = &note;
          if (nf->pvonly && !s390_is_pv()) {
              continue;
          }
content_size = nf->note_size_func ? nf->note_size_func() : nf->contents_size;
-        note_size = sizeof(note) - sizeof(notep->contents) + content_size;
+        note_size = sizeof(Note) - sizeof(notep->contents) + content_size;
- /* Notes with dynamic sizes need to allocate a note */
-        if (nf->note_size_func) {
-            notep = g_malloc(note_size);
+        if (prev_size < note_size) {
+            notep = g_realloc(notep, note_size);
          }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]