[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 10/11] acpi_table_add(): use acpi_newtable_resize()
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PATCH 10/11] acpi_table_add(): use acpi_newtable_resize() return value |
Date: |
Wed, 27 Jun 2012 17:23:06 -0300 |
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 <address@hidden>
---
hw/acpi.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
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;
}
--
1.7.10.4
- [Qemu-devel] [PATCH 00/11] acpi_table_add() code cleanup, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 03/11] acpi_table_add(): rename 'len' to 'acpi_len', Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 04/11] acpi_table_add(): introduce 'qemu_len' variable, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 09/11] acpi_table_add(): extract acpi_tables reallocation code to a separate function, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 05/11] acpi_table_add(): extract ACPI header creation to separate function, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 10/11] acpi_table_add(): use acpi_newtable_resize() return value,
Eduardo Habkost <=
- [Qemu-devel] [PATCH 01/11] acpi_table_add(): simplify acpi_tables on-demand initialization, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 06/11] acpi_table_add(): rename 'qemu_len' to 'newlen', Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 02/11] acpi_table_add(): extract acpi_tables init to separate function, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 07/11] acpi_table_add(): eliminate 'allen' variable, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 08/11] acpi_table_add(): eliminate 'start' variable, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 11/11] acpi_table_add(): extract acpi_tables count update code to separate function, Eduardo Habkost, 2012/06/27