qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 01/11] acpi_table_add(): simplify acpi_tables on-dem


From: Eduardo Habkost
Subject: [Qemu-devel] [PATCH 01/11] acpi_table_add(): simplify acpi_tables on-demand initialization
Date: Wed, 27 Jun 2012 17:22:57 -0300

Change the code to set acpi_tables_len as soon as acpi_tables is
allocated, so the rest of the code can simply use acpi_tables_len
safely.

There's a small behavior change if the first acpi_table_add() call fails
to open a file, but the change is actually desirable, because the old
code kept 'acpi_tables_len = 0' but a non-NULL 'acpi_tables' on error,
generating an invalid table if a second acpi_add() call were made.

Signed-off-by: Eduardo Habkost <address@hidden>
---
 hw/acpi.c |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/hw/acpi.c b/hw/acpi.c
index effc7ec..21e573b 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -102,12 +102,11 @@ int acpi_table_add(const char *t)
     }
 
     if (!acpi_tables) {
-        allen = sizeof(uint16_t);
-        acpi_tables = g_malloc0(allen);
-    } else {
-        allen = acpi_tables_len;
+        acpi_tables_len = sizeof(uint16_t);
+        acpi_tables = g_malloc0(acpi_tables_len);
     }
 
+    allen = acpi_tables_len;
     start = allen;
     acpi_tables = g_realloc(acpi_tables, start + ACPI_TABLE_HDR_SIZE);
     allen += has_header ? ACPI_TABLE_PFX_SIZE : ACPI_TABLE_HDR_SIZE;
-- 
1.7.10.4




reply via email to

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