qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, rth@twiddle.net
Subject: [Qemu-devel] [PATCH 3/4] x86: Use g_new() & friends where that makes obvious sense
Date: Thu,  4 Dec 2014 14:46:45 +0100	[thread overview]
Message-ID: <1417700806-23127-4-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1417700806-23127-1-git-send-email-armbru@redhat.com>

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 <armbru@redhat.com>
---
 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);
 }
-- 
1.9.3

  parent reply	other threads:[~2014-12-04 13:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-04 13:46 [Qemu-devel] [PATCH 0/4] x86: Trivial cleanups around g_malloc() Markus Armbruster
2014-12-04 13:46 ` [Qemu-devel] [PATCH 1/4] x86: Drop superfluous conditionals around g_free() Markus Armbruster
2014-12-04 13:46 ` [Qemu-devel] [PATCH 2/4] x86: Fuse g_malloc(); memset() into g_malloc0() Markus Armbruster
2014-12-04 13:46 ` Markus Armbruster [this message]
2014-12-04 13:46 ` [Qemu-devel] [PATCH 4/4] x86: Drop some superfluous casts from void * Markus Armbruster
2014-12-05 15:09 ` [Qemu-devel] [PATCH 0/4] x86: Trivial cleanups around g_malloc() Eric Blake
2014-12-05 15:40 ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1417700806-23127-4-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).