[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/33] target/s390x/arch_dump: Simplify memory allocation in s390x
From: |
Thomas Huth |
Subject: |
[PULL 09/33] target/s390x/arch_dump: Simplify memory allocation in s390x_write_elf64_notes() |
Date: |
Mon, 27 Feb 2023 12:35:57 +0100 |
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>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20230215085703.746788-1-thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
target/s390x/arch_dump.c | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/target/s390x/arch_dump.c b/target/s390x/arch_dump.c
index a7c44ba49d..cb98f4894d 100644
--- a/target/s390x/arch_dump.c
+++ b/target/s390x/arch_dump.c
@@ -227,25 +227,25 @@ 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;
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 = ¬e;
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) {
+ if (prev_size < note_size) {
+ g_free(notep);
notep = g_malloc(note_size);
+ prev_size = note_size;
}
memset(notep, 0, note_size);
@@ -258,15 +258,9 @@ static int s390x_write_elf64_notes(const char *note_name,
/* Get contents and write them out */
(*nf->note_contents_func)(notep, cpu, id);
ret = f(notep, note_size, s);
-
- if (nf->note_size_func) {
- g_free(notep);
- }
-
if (ret < 0) {
return -1;
}
-
}
return 0;
--
2.31.1
- [PULL 00/33] s390x and testing related patches, Thomas Huth, 2023/02/27
- [PULL 03/33] hw/vfio/ccw: Simplify using DEVICE() macro, Thomas Huth, 2023/02/27
- [PULL 02/33] Do not include hw/hw.h if it is not necessary, Thomas Huth, 2023/02/27
- [PULL 05/33] hw/vfio/ccw: Replace DO_UPCAST(S390CCWDevice) by S390_CCW_DEVICE(), Thomas Huth, 2023/02/27
- [PULL 06/33] hw/vfio/ccw: Remove pointless S390CCWDevice variable, Thomas Huth, 2023/02/27
- [PULL 04/33] hw/vfio/ccw: Use intermediate S390CCWDevice variable, Thomas Huth, 2023/02/27
- [PULL 01/33] tests/qtest/rtl8139-test: Make the test less verbose by default, Thomas Huth, 2023/02/27
- [PULL 07/33] hw/vfio/ccw: Replace DO_UPCAST(VFIOCCWDevice) by VFIO_CCW(), Thomas Huth, 2023/02/27
- [PULL 08/33] target/s390x/arch_dump: Fix memory corruption in s390x_write_elf64_notes(), Thomas Huth, 2023/02/27
- [PULL 09/33] target/s390x/arch_dump: Simplify memory allocation in s390x_write_elf64_notes(),
Thomas Huth <=
- [PULL 12/33] target/s390x: Use void* for haddr in S390Access, Thomas Huth, 2023/02/27
- [PULL 14/33] target/s390x: Remove TLB_NOTDIRTY workarounds, Thomas Huth, 2023/02/27
- [PULL 13/33] target/s390x: Tidy access_prepare_nf, Thomas Huth, 2023/02/27
- [PULL 10/33] target/s390x: Fix s390_probe_access for user-only, Thomas Huth, 2023/02/27
- [PULL 11/33] target/s390x: Pass S390Access pointer into access_prepare, Thomas Huth, 2023/02/27
- [PULL 15/33] target/s390x: Inline do_access_{get,set}_byte, Thomas Huth, 2023/02/27
- [PULL 16/33] target/s390x: Hoist some computation in access_memmove, Thomas Huth, 2023/02/27
- [PULL 22/33] tests/tcg/s390x: Add bal.S, Thomas Huth, 2023/02/27
- [PULL 29/33] gitlab-ci.d/buildtest: Disintegrate the build-coroutine-sigaltstack job, Thomas Huth, 2023/02/27
- [PULL 19/33] target/s390x: Use tcg_constant_* for DisasCompare, Thomas Huth, 2023/02/27