From patchwork Thu Dec 4 13:46:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 417785 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 06E691400D5 for ; Fri, 5 Dec 2014 00:47:36 +1100 (AEDT) Received: from localhost ([::1]:45929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwWko-00036N-6X for incoming@patchwork.ozlabs.org; Thu, 04 Dec 2014 08:47:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwWkD-0002F6-Q6 for qemu-devel@nongnu.org; Thu, 04 Dec 2014 08:47:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XwWk5-0004su-M9 for qemu-devel@nongnu.org; Thu, 04 Dec 2014 08:46:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43280) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwWk5-0004sY-Di for qemu-devel@nongnu.org; Thu, 04 Dec 2014 08:46:49 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sB4Dkm4O012700 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 4 Dec 2014 08:46:48 -0500 Received: from blackfin.pond.sub.org (ovpn-116-62.ams2.redhat.com [10.36.116.62]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sB4DkkeI011725 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 4 Dec 2014 08:46:48 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4A6143042B72; Thu, 4 Dec 2014 14:46:46 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 4 Dec 2014 14:46:45 +0100 Message-Id: <1417700806-23127-4-git-send-email-armbru@redhat.com> In-Reply-To: <1417700806-23127-1-git-send-email-armbru@redhat.com> References: <1417700806-23127-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, rth@twiddle.net Subject: [Qemu-devel] [PATCH 3/4] x86: Use g_new() & friends where that makes obvious sense 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 g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowing size_t. Two, it returns T * rather than void *, which lets the compiler catch more type errors. This commit only touches allocations with size arguments of the form sizeof(T). Signed-off-by: Markus Armbruster --- hw/i386/pc.c | 3 +-- target-i386/kvm.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index f31d55e..c0e55a6 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -602,8 +602,7 @@ int e820_add_entry(uint64_t address, uint64_t length, uint32_t type) } /* new "etc/e820" file -- include ram too */ - e820_table = g_realloc(e820_table, - sizeof(struct e820_entry) * (e820_entries+1)); + e820_table = g_renew(struct e820_entry, e820_table, e820_entries + 1); e820_table[e820_entries].address = cpu_to_le64(address); e820_table[e820_entries].length = cpu_to_le64(length); e820_table[e820_entries].type = cpu_to_le32(type); diff --git a/target-i386/kvm.c b/target-i386/kvm.c index ccf36e8..c1559c4 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -277,7 +277,7 @@ static void kvm_hwpoison_page_add(ram_addr_t ram_addr) return; } } - page = g_malloc(sizeof(HWPoisonPage)); + page = g_new(HWPoisonPage, 1); page->ram_addr = ram_addr; QLIST_INSERT_HEAD(&hwpoison_page_list, page, list); }