mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
Use g_new() & friends where that makes obvious sense
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). Patch created mechanically with: $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci \ --macro-file scripts/cocci-macro-file.h FILES... Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Cédric Le Goater <clg@kaod.org> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Message-Id: <20220315144156.1595462-4-armbru@redhat.com> Reviewed-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
This commit is contained in:
parent
1366244ab6
commit
b21e238037
102 changed files with 195 additions and 200 deletions
|
@ -108,7 +108,7 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque)
|
|||
unsigned long size;
|
||||
struct rlimit rlimit_as;
|
||||
|
||||
mapcache = g_malloc0(sizeof (MapCache));
|
||||
mapcache = g_new0(MapCache, 1);
|
||||
|
||||
mapcache->phys_offset_to_gaddr = f;
|
||||
mapcache->opaque = opaque;
|
||||
|
@ -164,8 +164,8 @@ static void xen_remap_bucket(MapCacheEntry *entry,
|
|||
|
||||
trace_xen_remap_bucket(address_index);
|
||||
|
||||
pfns = g_malloc0(nb_pfn * sizeof (xen_pfn_t));
|
||||
err = g_malloc0(nb_pfn * sizeof (int));
|
||||
pfns = g_new0(xen_pfn_t, nb_pfn);
|
||||
err = g_new0(int, nb_pfn);
|
||||
|
||||
if (entry->vaddr_base != NULL) {
|
||||
if (!(entry->flags & XEN_MAPCACHE_ENTRY_DUMMY)) {
|
||||
|
@ -231,8 +231,8 @@ static void xen_remap_bucket(MapCacheEntry *entry,
|
|||
entry->vaddr_base = vaddr_base;
|
||||
entry->paddr_index = address_index;
|
||||
entry->size = size;
|
||||
entry->valid_mapping = (unsigned long *) g_malloc0(sizeof(unsigned long) *
|
||||
BITS_TO_LONGS(size >> XC_PAGE_SHIFT));
|
||||
entry->valid_mapping = g_new0(unsigned long,
|
||||
BITS_TO_LONGS(size >> XC_PAGE_SHIFT));
|
||||
|
||||
if (dummy) {
|
||||
entry->flags |= XEN_MAPCACHE_ENTRY_DUMMY;
|
||||
|
@ -319,7 +319,7 @@ tryagain:
|
|||
pentry = free_pentry;
|
||||
}
|
||||
if (!entry) {
|
||||
entry = g_malloc0(sizeof (MapCacheEntry));
|
||||
entry = g_new0(MapCacheEntry, 1);
|
||||
pentry->next = entry;
|
||||
xen_remap_bucket(entry, NULL, cache_size, address_index, dummy);
|
||||
} else if (!entry->lock) {
|
||||
|
@ -353,7 +353,7 @@ tryagain:
|
|||
|
||||
mapcache->last_entry = entry;
|
||||
if (lock) {
|
||||
MapCacheRev *reventry = g_malloc0(sizeof(MapCacheRev));
|
||||
MapCacheRev *reventry = g_new0(MapCacheRev, 1);
|
||||
entry->lock++;
|
||||
if (entry->lock == 0) {
|
||||
fprintf(stderr,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue