spapr_pci: convert g_malloc() to g_new()
authorGreg Kurz <groug@kaod.org>
Fri, 12 Oct 2018 09:05:09 +0000 (11:05 +0200)
committerDavid Gibson <david@gibson.dropbear.id.au>
Thu, 8 Nov 2018 01:04:40 +0000 (12:04 +1100)
When allocating an array, it is a recommended coding practice to call
g_new(FooType, n) instead of g_malloc(n * sizeof(FooType)) because
it takes care to avoid overflow when calculating the size of the
allocated block and it returns FooType *, which allows the compiler
to perform type checking.

Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
hw/ppc/spapr_pci.c

index 58afa46204629fbdb023e5e730cc22bf41495e73..2374d55fc112bfef41e32100638d8fef863643eb 100644 (file)
@@ -1882,7 +1882,7 @@ static int spapr_pci_pre_save(void *opaque)
     if (!sphb->msi_devs_num) {
         return 0;
     }
-    sphb->msi_devs = g_malloc(sphb->msi_devs_num * sizeof(spapr_pci_msi_mig));
+    sphb->msi_devs = g_new(spapr_pci_msi_mig, sphb->msi_devs_num);
 
     g_hash_table_iter_init(&iter, sphb->msi);
     for (i = 0; g_hash_table_iter_next(&iter, &key, &value); ++i) {