Skip to content

Commit

Permalink
x86: Use g_new() & friends where that makes obvious sense
Browse files Browse the repository at this point in the history
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>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Markus Armbruster authored and bonzini committed Dec 15, 2014
1 parent 4be34d1 commit ab3ad07
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions hw/i386/pc.c
Expand Up @@ -601,8 +601,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);
Expand Down
2 changes: 1 addition & 1 deletion target-i386/kvm.c
Expand Up @@ -278,7 +278,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);
}
Expand Down

0 comments on commit ab3ad07

Please sign in to comment.