Patchwork [10/11] acpi_table_add(): use acpi_newtable_resize() return value

login
register
mail settings
Submitter Eduardo Habkost
Date June 27, 2012, 8:23 p.m.
Message ID <1340828587-15201-11-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/167736/
State New
Headers show

Comments

Eduardo Habkost - June 27, 2012, 8:23 p.m.
By using the acpi_newtable_resize() return value, there's no need to do
'acpi_tables + acpi_tables_len' math every time. The acpi_table_add()
function just needs to keep a newtable/newlen pair, that points to the
table being constructed.

With this, almost every single reference to acpi_tables/acpi_tables_len
is hidden behind the acpi_newtable_resize() abstraction, and the
acpi_add() function only cares about the pointer to the new table being
constructed.

No behavior change, just code movement.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/acpi.c |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Patch

diff --git a/hw/acpi.c b/hw/acpi.c
index cbc2ba7..240e2cf 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -201,6 +201,7 @@  static int acpi_make_table_header(const char *t, bool has_header, char *f,
 int acpi_table_add(const char *t)
 {
     char buf[1024], *f;
+    char *newtable;
     size_t newlen; /* length of the new table */
     bool has_header;
     int r;
@@ -225,7 +226,7 @@  int acpi_table_add(const char *t)
 
     init_acpi_tables();
 
-    acpi_newtable_resize(ACPI_TABLE_HDR_SIZE);
+    newtable = acpi_newtable_resize(ACPI_TABLE_HDR_SIZE);
     newlen = has_header ? ACPI_TABLE_PFX_SIZE : ACPI_TABLE_HDR_SIZE;
 
     /* now read in the data files, reallocating buffer as needed */
@@ -244,8 +245,8 @@  int acpi_table_add(const char *t)
             if (r == 0) {
                 break;
             } else if (r > 0) {
-                acpi_newtable_resize(newlen + r);
-                memcpy(acpi_tables + acpi_tables_len + newlen, data, r);
+                newtable = acpi_newtable_resize(newlen + r);
+                memcpy(newtable + newlen, data, r);
                 newlen += r;
             } else if (errno != EINTR) {
                 fprintf(stderr, "can't read file %s: %s\n",
@@ -259,10 +260,7 @@  int acpi_table_add(const char *t)
     }
 
     /* now fill in the header fields */
-
-    f = acpi_tables + acpi_tables_len;   /* start of the table */
-
-    if (acpi_make_table_header(t, has_header, f, newlen) < 0) {
+    if (acpi_make_table_header(t, has_header, newtable, newlen) < 0) {
         return -1;
     }