From patchwork Wed Jun 27 20:23:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 167737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9388FB6FAB for ; Thu, 28 Jun 2012 06:23:02 +1000 (EST) Received: from localhost ([::1]:33689 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SjylQ-0003Jt-8T for incoming@patchwork.ozlabs.org; Wed, 27 Jun 2012 16:23:00 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sjyl3-0003Ek-9N for qemu-devel@nongnu.org; Wed, 27 Jun 2012 16:22:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sjykx-0003KX-Jk for qemu-devel@nongnu.org; Wed, 27 Jun 2012 16:22:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38615) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sjykx-0003Ik-8r for qemu-devel@nongnu.org; Wed, 27 Jun 2012 16:22:31 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5RKMSZl008604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 27 Jun 2012 16:22:28 -0400 Received: from blackpad.lan.raisama.net (vpn1-4-120.gru2.redhat.com [10.97.4.120]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q5RKMS4D005878; Wed, 27 Jun 2012 16:22:28 -0400 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id B6305203BAA; Wed, 27 Jun 2012 17:23:13 -0300 (BRT) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 27 Jun 2012 17:23:05 -0300 Message-Id: <1340828587-15201-10-git-send-email-ehabkost@redhat.com> In-Reply-To: <1340828587-15201-1-git-send-email-ehabkost@redhat.com> References: <1340828587-15201-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Isaku Yamahata , Michael Tokarev , Gleb Natapov Subject: [Qemu-devel] [PATCH 09/11] acpi_table_add(): extract acpi_tables reallocation code to a separate function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This was the maint point of most of the previous variable renames and calculation-method changes: to isolate the g_realloc() call to avoid doing pointer math with acpi_tables everywhere. No behavior change, just code movement. Signed-off-by: Eduardo Habkost --- hw/acpi.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/hw/acpi.c b/hw/acpi.c index 251c770..cbc2ba7 100644 --- a/hw/acpi.c +++ b/hw/acpi.c @@ -81,6 +81,18 @@ static void init_acpi_tables(void) } } +/* Resize acpi_tables to fit a new (under construction) table of size 'newlen' + * + * acpi_tables_len is _not_ changed, as the table is still incomplete. + * + * Returns a pointer to the reallocated _new_ table at end of acpi_tables. + */ +static char *acpi_newtable_resize(size_t newlen) +{ + acpi_tables = g_realloc(acpi_tables, acpi_tables_len + newlen); + return acpi_tables + acpi_tables_len; +} + static int acpi_make_table_header(const char *t, bool has_header, char *f, size_t qemu_len) { @@ -213,7 +225,7 @@ int acpi_table_add(const char *t) init_acpi_tables(); - acpi_tables = g_realloc(acpi_tables, acpi_tables_len + ACPI_TABLE_HDR_SIZE); + 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 */ @@ -232,8 +244,7 @@ int acpi_table_add(const char *t) if (r == 0) { break; } else if (r > 0) { - acpi_tables = g_realloc(acpi_tables, acpi_tables_len + newlen - + r); + acpi_newtable_resize(newlen + r); memcpy(acpi_tables + acpi_tables_len + newlen, data, r); newlen += r; } else if (errno != EINTR) {