Patchwork [08/11] acpi_table_add(): eliminate 'start' variable

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

Comments

Eduardo Habkost - June 27, 2012, 8:23 p.m.
The 'start' variable is initialized with the value of 'acpi_tables_len',
but neither 'acpi_tables_len' or 'start' are changed during the
acpi_table_add() call (except at the end of the function), so 'start'
can be simply replaced by 'acpi_tables_len'.

No behavior change, just calculation methods changed.

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

Patch

diff --git a/hw/acpi.c b/hw/acpi.c
index e116528..251c770 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -189,7 +189,6 @@  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;
-    size_t start;
     size_t newlen; /* length of the new table */
     bool has_header;
     int r;
@@ -214,8 +213,7 @@  int acpi_table_add(const char *t)
 
     init_acpi_tables();
 
-    start = acpi_tables_len;
-    acpi_tables = g_realloc(acpi_tables, start + ACPI_TABLE_HDR_SIZE);
+    acpi_tables = g_realloc(acpi_tables, acpi_tables_len + 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 */
@@ -234,8 +232,9 @@  int acpi_table_add(const char *t)
             if (r == 0) {
                 break;
             } else if (r > 0) {
-                acpi_tables = g_realloc(acpi_tables, start + newlen + r);
-                memcpy(acpi_tables + start + newlen, data, r);
+                acpi_tables = g_realloc(acpi_tables, acpi_tables_len + newlen
+                                                                     + r);
+                memcpy(acpi_tables + acpi_tables_len + newlen, data, r);
                 newlen += r;
             } else if (errno != EINTR) {
                 fprintf(stderr, "can't read file %s: %s\n",
@@ -250,7 +249,7 @@  int acpi_table_add(const char *t)
 
     /* now fill in the header fields */
 
-    f = acpi_tables + start;   /* start of the table */
+    f = acpi_tables + acpi_tables_len;   /* start of the table */
 
     if (acpi_make_table_header(t, has_header, f, newlen) < 0) {
         return -1;
@@ -260,7 +259,7 @@  int acpi_table_add(const char *t)
     (*(uint16_t *)acpi_tables) =
         cpu_to_le32(le32_to_cpu(*(uint16_t *)acpi_tables) + 1);
 
-    acpi_tables_len = start + newlen;
+    acpi_tables_len += newlen;
     return 0;
 
 }