Skip to contentSkip to conversation

use g_new() family of functions

PATCH Applied Philippe Mathieu-Daudé 23 participants 132 messages Oct 6, 2017 – Nov 6, 2017 Page 1 of 2

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover use g_new() family of functions

Hi,

This is a follow-up of Marc-André's clang-tidy series [1].
While chatting we realized we were trying to reach the same goal, Marc-André using clang-tidy and me using spatch; so he let me finish his series applying my changes over his.
I also included Jan's patch which fits well.

Summary:
- 1 bugfix (memory leak)
- few optimizations (avoid to zeroise when all memory is assigned)
- bunch of mechanical refactors

Regards,

Phil.

[1]: http://lists.nongnu.org/archive/html/qemu-devel/2017-09/msg00881.html

Jan Beulich (1):
hw/block/xen_disk: avoid use of g_new0()

Marc-André Lureau (57):
ARM: use g_new() family of functions
Audio: use g_new() family of functions
BT: use g_new() family of functions
Bootdevice: use g_new() family of functions Character devices: use g_new() family of functions Cryptodev Backends: use g_new() family of functions Dirty Bitmaps: use g_new() family of functions ui/vnc: use g_new() family of functions Main loop: use g_new() family of functions Memory API: use g_new() family of functions
memory: use g_new() family of functions
Migration: use g_new() family of functions
NBD: use g_new() family of functions
LM32: use g_new() family of functions
M68K: use g_new() family of functions
MIPS: use g_new() family of functions
OpenRISC: use g_new() family of functions
S390: use g_new() family of functions
SH4: use g_new() family of functions
disas: use g_new() family of functions
SPARC: use g_new() family of functions
QEMU Guest Agent: use g_new() family of functions
QMP: use g_new() family of functions
QObject: use g_new() family of functions Record/replay: use g_new() family of functions
SLIRP: use g_new() family of functions
TCG: use g_new() family of functions
VFIO: use g_new() family of functions hw/i386: use g_new() family of functions hw/xen: use g_new() family of functions
XTFPGA: use g_new() family of functions hw/core: use g_new() family of functions hw/display: use g_new() family of functions hw/i2c: use g_new() family of functions hw/input: use g_new() family of functions hw/misc: use g_new() family of functions
ivshmem: use g_new() family of functions hw/timer: use g_new() family of functions i.MX31: use g_new() family of functions
iSCSI: use g_new() family of functions
KVM: use g_new() family of functions
PReP: use g_new() family of functions
PowerPC: use g_new() family of functions
ppc: use g_new() family of functions
ppc4xx: use g_new() family of functions
ppce500: use g_new() family of functions
sPAPR: use g_new() family of functions
tests: use g_new() family of functions
user: use g_new() family of functions
user: use g_strfreev()
util: use g_new() family of functions
virtio: use g_new() family of functions
virtio-9p: use g_new() family of functions
decnumber: use g_new() family of functions
dma: use g_new() family of functions
dump: use g_new() family of functions
gdb: use g_new() family of functions

Philippe Mathieu-Daudé (30):
cocci: script to use g_new() & friends
cocci: add more g_new() transformations
cocci: extract typeof() from g_new()
cocci: avoid use of g_new0()
cocci: use g_strfreev()
backends/hostmem: use g_new() family of functions ui/spice: use g_new() family of functions
exec: use g_new() family of functions
qom: use g_new() family of functions
qapi: use g_new() family of functions target/i386: use g_new() family of functions hw/core/loader: use g_new() family of functions hw/display/vga: use g_new() family of functions bsd-user/syscall: fix a memory leak on EFAULT, use g_new() util/qemu-thread-win32: use g_new() family of functions util/coroutine: use g_new() family of functions
block: use g_new() family of functions
block: avoid use of g_new0()
hw/block/nvme: use g_new() family of functions
balloon: use g_new() family of functions
hmp: use g_new() family of functions
numa: use g_new() family of functions
hw/acpi: use g_new() family of functions hw/ipmi: use g_new() family of functions
hw/pci: use g_new() family of functions
hw/scsi: use g_new() family of functions
hw/usb: use g_new() family of functions
net/hub: use g_new() family of functions hw/net/rocker: use g_new() family of functions scripts/coverity-model: use g_new() family of functions

 hw/lm32/lm32_hwsetup.h              |   2 +-
 include/qemu/timer.h                |   2 +-
 accel/kvm/kvm-all.c                 |   8 +-
 audio/alsaaudio.c                   |   2 +-
 audio/coreaudio.c                   |   2 +-
 audio/dsoundaudio.c                 |   2 +-
 audio/ossaudio.c                    |   2 +-
 audio/paaudio.c                     |   2 +-
 audio/wavaudio.c                    |   2 +-
 audio/wavcapture.c                  |   2 +-
 backends/cryptodev.c                |   2 +-
 backends/hostmem.c                  |   4 +-
 balloon.c                           |   2 +-
 block/backup.c                      |   2 +-
 block/blkdebug.c                    |   4 +-
 block/commit.c                      |   2 +-
 block/iscsi.c                       |   2 +-
 block/linux-aio.c                   |   2 +-
 block/mirror.c                      |   2 +-
 block/qapi.c                        |   4 +-
 block/qcow2-refcount.c              |  12 +-
 block/qcow2.c                       |   2 +-
 block/qed-l2-cache.c                |   2 +-
 block/sheepdog.c                    |   2 +-
 block/stream.c                      |   2 +-
 block/vhdx.c                        |   9 +-
 block/win32-aio.c                   |   2 +-
 bootdevice.c                        |   2 +-
 bsd-user/main.c                     |   6 +-
 bsd-user/syscall.c                  |   3 +-
 bt-host.c                           |   2 +-
 bt-vhci.c                           |   2 +-
 cpus-common.c                       |   4 +-
 cpus.c                              |  18 +--
 disas/m68k.c                        |   3 +-
 disas/nios2.c                       |   3 +-
 disas/sparc.c                       |   3 +-
 dma-helpers.c                       |   4 +-
 dump.c                              |  11 +-
 exec.c                              |   8 +-
 gdbstub.c                           |   4 +-
 hmp.c                               |   2 +-
 hw/9pfs/9p-handle.c                 |   2 +-
 hw/9pfs/9p-proxy.c                  |   2 +-
 hw/9pfs/9p-synth.c                  |   8 +-
 hw/9pfs/9p.c                        |   2 +-
 hw/9pfs/xen-9p-backend.c            |   2 +-
 hw/acpi/vmgenid.c                   |   2 +-
 hw/arm/virt-acpi-build.c            |   2 +-
 hw/audio/intel-hda.c                |   2 +-
 hw/block/nvme.c                     |   4 +-
 hw/block/xen_disk.c                 |   2 +-
 hw/bt/core.c                        |   4 +-
 hw/bt/hci.c                         |   4 +-
 hw/bt/l2cap.c                       |   6 +-
 hw/char/parallel.c                  |   2 +-
 hw/char/serial.c                    |   4 +-
 hw/char/sh_serial.c                 |   2 +-
 hw/char/virtio-serial-bus.c         |   6 +-
 hw/core/irq.c                       |   2 +-
 hw/core/loader.c                    |   6 +-
 hw/core/ptimer.c                    |   2 +-
 hw/core/qdev.c                      |   2 +-
 hw/core/reset.c                     |   2 +-
 hw/display/pxa2xx_lcd.c             |   2 +-
 hw/display/tc6393xb.c               |   2 +-
 hw/display/vga-isa-mm.c             |   6 +-
 hw/display/vga.c                    |   2 +-
 hw/display/virtio-gpu.c             |   4 +-
 hw/display/xenfb.c                  |   4 +-
 hw/dma/etraxfs_dma.c                |   2 +-
 hw/dma/rc4030.c                     |   4 +-
 hw/i2c/bitbang_i2c.c                |   2 +-
 hw/i2c/core.c                       |   4 +-
 hw/i386/acpi-build.c                |   4 +-
 hw/i386/amd_iommu.c                 |   4 +-
 hw/i386/intel_iommu.c               |   2 +-
 hw/i386/pc.c                        |   8 +-
 hw/i386/pc_sysfw.c                  |   6 +-
 hw/i386/xen/xen-hvm.c               |  10 +-
 hw/i386/xen/xen-mapcache.c          |  14 +--
 hw/input/pckbd.c                    |   2 +-
 hw/input/ps2.c                      |   4 +-
 hw/input/pxa2xx_keypad.c            |   2 +-
 hw/input/tsc2005.c                  |   3 +-
 hw/intc/heathrow_pic.c              |   2 +-
 hw/intc/xics.c                      |   2 +-
 hw/intc/xics_kvm.c                  |   4 +-
 hw/ipmi/ipmi_bmc_sim.c              |   2 +-
 hw/lm32/lm32_boards.c               |   4 +-
 hw/lm32/milkymist.c                 |   2 +-
 hw/m68k/mcf5206.c                   |   4 +-
 hw/m68k/mcf5208.c                   |   2 +-
 hw/mips/mips_malta.c                |   2 +-
 hw/mips/mips_mipssim.c              |   2 +-
 hw/mips/mips_r4k.c                  |   2 +-
 hw/misc/applesmc.c                  |   2 +-
 hw/misc/imx6_src.c                  |   2 +-
 hw/misc/ivshmem.c                   |   4 +-
 hw/misc/pvpanic.c                   |   2 +-
 hw/net/rocker/rocker_of_dpa.c       |   4 +-
 hw/net/virtio-net.c                 |   4 +-
 hw/openrisc/openrisc_sim.c          |   2 +-
 hw/pci/pci.c                        |   2 +-
 hw/pci/pcie_port.c                  |   2 +-
 hw/ppc/e500.c                       |   7 +-
 hw/ppc/mac_newworld.c               |   5 +-
 hw/ppc/mac_oldworld.c               |   2 +-
 hw/ppc/ppc.c                        |   8 +-
 hw/ppc/ppc405_boards.c              |   4 +-
 hw/ppc/ppc405_uc.c                  |  24 ++--
 hw/ppc/ppc440_bamboo.c              |   2 +-
 hw/ppc/ppc4xx_devs.c                |   6 +-
 hw/ppc/ppc_booke.c                  |   4 +-
 hw/ppc/prep.c                       |   2 +-
 hw/ppc/spapr.c                      |   2 +-
 hw/ppc/spapr_events.c               |   4 +-
 hw/ppc/spapr_iommu.c                |   2 +-
 hw/ppc/spapr_pci.c                  |   2 +-
 hw/ppc/virtex_ml507.c               |   2 +-
 hw/s390x/css.c                      |  10 +-
 hw/s390x/s390-pci-bus.c             |   4 +-
 hw/scsi/vmw_pvscsi.c                |   2 +-
 hw/sh4/r2d.c                        |   4 +-
 hw/sh4/sh7750.c                     |   2 +-
 hw/sparc/leon3.c                    |   2 +-
 hw/sparc64/sparc64.c                |   4 +-
 hw/timer/arm_timer.c                |   2 +-
 hw/timer/sh_timer.c                 |   4 +-
 hw/timer/slavio_timer.c             |   2 +-
 hw/usb/hcd-ehci.c                   |   2 +-
 hw/vfio/common.c                    |  12 +-
 hw/vfio/pci-quirks.c                |  18 +--
 hw/vfio/pci.c                       |   7 +-
 hw/vfio/platform.c                  |   6 +-
 hw/virtio/vhost.c                   |   2 +-
 hw/virtio/virtio-crypto.c           |   2 +-
 hw/virtio/virtio.c                  |   2 +-
 hw/xen/xen_pvdev.c                  |   2 +-
 hw/xtensa/xtfpga.c                  |   2 +-
 libdecnumber/decNumber.c            |   8 +-
 linux-user/elfload.c                |   2 +-
 linux-user/main.c                   |   6 +-
 memory.c                            |   2 +-
 memory_mapping.c                    |   2 +-
 migration/migration.c               |   2 +-
 migration/page_cache.c              |   2 +-
 migration/postcopy-ram.c            |   2 +-
 migration/ram.c                     |   3 +-
 monitor.c                           |  14 +--
 nbd/server.c                        |   4 +-
 net/hub.c                           |   2 +-
 net/slirp.c                         |   4 +-
 numa.c                              |   2 +-
 qapi/opts-visitor.c                 |   2 +-
 qapi/qapi-clone-visitor.c           |   2 +-
 qapi/qapi-dealloc-visitor.c         |   2 +-
 qapi/qobject-output-visitor.c       |   2 +-
 qapi/string-input-visitor.c         |   2 +-
 qapi/string-output-visitor.c        |   2 +-
 qga/commands-posix.c                |  20 +--
 qga/commands-win32.c                |  12 +-
 qga/commands.c                      |   2 +-
 qmp.c                               |  14 +--
 qobject/json-parser.c               |   2 +-
 qobject/qbool.c                     |   2 +-
 qobject/qdict.c                     |   4 +-
 qobject/qlist.c                     |   4 +-
 qobject/qstring.c                   |   2 +-
 qom/object.c                        |   6 +-
 replay/replay-char.c                |   4 +-
 replay/replay-events.c              |  10 +-
 scripts/coverity-model.c            |   2 +-
 slirp/slirp.c                       |   2 +-
 slirp/socket.c                      |   2 +-
 target/arm/helper.c                 |   4 +-
 target/i386/cpu.c                   |   6 +-
 target/i386/hax-all.c               |   4 +-
 target/i386/hax-mem.c               |   2 +-
 target/i386/hyperv.c                |   2 +-
 target/mips/translate_init.c        |   4 +-
 target/openrisc/mmu.c               |   2 +-
 target/ppc/kvm.c                    |   2 +-
 target/ppc/translate_init.c         |  14 +--
 target/s390x/cpu_models.c           |  12 +-
 target/s390x/diag.c                 |   2 +-
 tcg/tcg.c                           |   4 +-
 tests/ahci-test.c                   |   4 +-
 tests/fw_cfg-test.c                 |   4 +-
 tests/libqos/ahci.c                 |   2 +-
 tests/libqos/libqos.c               |   2 +-
 tests/libqos/malloc.c               |   6 +-
 tests/libqos/pci-pc.c               |   2 +-
 tests/libqos/pci-spapr.c            |   2 +-
 tests/libqos/pci.c                  |   2 +-
 tests/libqos/virtio-mmio.c          |   4 +-
 tests/libqos/virtio-pci.c           |   4 +-
 tests/libqtest.c                    |   2 +-
 tests/pc-cpu-test.c                 |   2 +-
 tests/test-hbitmap.c                |   2 +-
 tests/test-qmp-commands.c           |  14 +--
 tests/test-qobject-output-visitor.c |   4 +-
 thunk.c                             |   2 +-
 ui/spice-core.c                     |  10 +-
 ui/spice-display.c                  |   4 +-
 ui/spice-input.c                    |   4 +-
 ui/vnc-enc-tight.c                  |   2 +-
 ui/vnc-palette.c                    |   2 +-
 ui/vnc.c                            |   6 +-
 util/acl.c                          |   6 +-
 util/coroutine-sigaltstack.c        |   2 +-
 util/coroutine-ucontext.c           |   2 +-
 util/coroutine-win32.c              |   2 +-
 util/envlist.c                      |   6 +-
 util/error.c                        |   2 +-
 util/hbitmap.c                      |   2 +-
 util/iohandler.c                    |   2 +-
 util/main-loop.c                    |   2 +-
 util/module.c                       |   4 +-
 util/qemu-option.c                  |   8 +-
 util/qemu-thread-win32.c            |   2 +-
 util/qemu-timer.c                   |   2 +-
 util/qht.c                          |   2 +-
 vl.c                                |  12 +-
 scripts/coccinelle/g_new.cocci      | 240 ++++++++++++++++++++++++++++++++++++
 225 files changed, 677 insertions(+), 456 deletions(-)
 create mode 100644 scripts/coccinelle/g_new.cocci
Signature · 1 line
2.14.2
#1 lore raw

PATCH 1/88 cocci: script to use g_new() & friends

Imported from Markus Armbruster commit b45c03f

---

 scripts/coccinelle/g_new.cocci | 101 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 101 insertions(+)
 create mode 100644 scripts/coccinelle/g_new.cocci
scripts/coccinelle/g_new.cocci new file +101 -0
new file mode 100644
index 0000000000..1e57685a6b
@@ -0,0 +1,101 @@
+/* transform g_new*() alloc with size arguments of the form sizeof(T) [* N]
+ *
+ *   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.
+ *
+ *    Copyright: (C) 2017 Markus Armbruster <[email protected]>. GPLv2+.
+ *    (Imported from b45c03f585ea9bb1af76c73e82195418c294919d)
+ *
+ * See http://lists.nongnu.org/archive/html/qemu-devel/2017-09/msg00908.html:
+ *
+ *   g_new() advantages (from glib doc):
+ *   - the returned pointer is cast to a pointer to the given type.
+ *   - care is taken to avoid overflow when calculating the size of the
+ *   allocated block.
+ *
+ *   p = g_malloc(sizeof(*p)) is idiomatic, and not obviously inferior to
+ *   p = g_new(T, 1), where T is the type of *p.
+ *   But once you add multiplication, g_new() adds something useful: overflow
+ *   protection.  Conversion to g_new() might make sense then.
+ */
+
+@@
+type T;
+@@
+-g_malloc(sizeof(T))
++g_new(T, 1)
+@@
+type T;
+@@
+-g_try_malloc(sizeof(T))
++g_try_new(T, 1)
+@@
+type T;
+@@
+-g_malloc0(sizeof(T))
++g_new0(T, 1)
+@@
+type T;
+@@
+-g_try_malloc0(sizeof(T))
++g_try_new0(T, 1)
+
+@@
+type T;
+expression n;
+@@
+-g_malloc(sizeof(T) * (n))
++g_new(T, n)
+@@
+type T;
+expression n;
+@@
+-g_try_malloc(sizeof(T) * (n))
++g_try_new(T, n)
+@@
+type T;
+expression n;
+@@
+-g_malloc0(sizeof(T) * (n))
++g_new0(T, n)
+@@
+type T;
+expression n;
+@@
+-g_try_malloc0(sizeof(T) * (n))
++g_try_new0(T, n)
+
+@@
+type T;
+expression p, n;
+@@
+-g_realloc(p, sizeof(T) * (n))
++g_renew(T, p, n)
+@@
+type T;
+expression p, n;
+@@
+-g_try_realloc(p, sizeof(T) * (n))
++g_try_renew(T, p, n)
+
+// drop superfluous cast
+@@
+type T;
+expression n;
+@@
+-(T *)g_new(T, n)
++g_new(T, n)
+@@
+type T;
+expression n;
+@@
+-(T *)g_new0(T, n)
++g_new0(T, n)
+@@
+type T;
+expression p, n;
+@@
+-(T *)g_renew(T, p, n)
++g_renew(T, p, n)
Signature · 1 line
2.14.2
#2 lore raw

Re: [Qemu-devel] [PATCH 01/88] cocci: script to use g_new() & friends

Quoted 16 lines · Philippe Mathieu-Daudé

Imported from Markus Armbruster commit b45c03f

---

 scripts/coccinelle/g_new.cocci | 101 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 101 insertions(+)
 create mode 100644 scripts/coccinelle/g_new.cocci
scripts/coccinelle/g_new.cocci new file +0 -0
new file mode 100644
index 0000000000..1e57685a6b

scripts/coccinelle/g_new.cocci line 1

Quoted 1 line
scripts/coccinelle/g_new.cocci new file +1 -0
@@ -0,0 +1,101 @@
+/* transform g_new*() alloc with size arguments of the form sizeof(T) [* N]

Confusing. Sounds like we transform g_new() into something else. Also, wing both ends of the comment, and start with a capital letter.

scripts/coccinelle/g_new.cocci line 5

Quoted 4 lines
scripts/coccinelle/g_new.cocci new file +4 -0
+ *
+ *   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

Start your sentences with a capital letter. Or rather, keep my commit message's capital letters intact ;)

scripts/coccinelle/g_new.cocci line 8

Quoted 3 lines
scripts/coccinelle/g_new.cocci new file +3 -0
+ *   more type errors.
+ *
+ *    Copyright: (C) 2017 Markus Armbruster <[email protected]>. GPLv2+.

If you want to put a copyright note into this file, you should stick to the common format:

/*
* Rewrite memory allocations to use g_new() & friends
*
* Copyright (C) 2014-2017 Red Hat, Inc.
*
* Authors:
* Markus Armbruster <[email protected]>,
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/

scripts/coccinelle/g_new.cocci line 9

Quoted 1 line
scripts/coccinelle/g_new.cocci new file +1 -0
+ *    (Imported from b45c03f585ea9bb1af76c73e82195418c294919d)

Scratch this line. It's in the commit message, and that suffices.

scripts/coccinelle/g_new.cocci line 16

Quoted 7 lines
scripts/coccinelle/g_new.cocci new file +7 -0
+ *
+ * See http://lists.nongnu.org/archive/html/qemu-devel/2017-09/msg00908.html:
+ *
+ *   g_new() advantages (from glib doc):
+ *   - the returned pointer is cast to a pointer to the given type.
+ *   - care is taken to avoid overflow when calculating the size of the
+ *   allocated block.

Repeats what you just said in the text pasted from my commit message.

scripts/coccinelle/g_new.cocci line 22

Quoted 6 lines
scripts/coccinelle/g_new.cocci new file +6 -0
+ *
+ *   p = g_malloc(sizeof(*p)) is idiomatic, and not obviously inferior to
+ *   p = g_new(T, 1), where T is the type of *p.
+ *   But once you add multiplication, g_new() adds something useful: overflow
+ *   protection.  Conversion to g_new() might make sense then.
+ */

This part doesn't really apply, yet: the semantic patch doesn't deal with sizeof(*p).

Please write a coherent introduction instead of a series of quotations.

Quoted 12 lines
scripts/coccinelle/g_new.cocci new file +12 -0
+
+@@
+type T;
+@@
+-g_malloc(sizeof(T))
++g_new(T, 1)
+@@
+type T;
+@@
+-g_try_malloc(sizeof(T))
++g_try_new(T, 1)
+@@

scripts/coccinelle/g_new.cocci line 44

Quoted 10 lines
scripts/coccinelle/g_new.cocci new file +10 -0
+type T;
+@@
+-g_malloc0(sizeof(T))
++g_new0(T, 1)
+@@
+type T;
+@@
+-g_try_malloc0(sizeof(T))
++g_try_new0(T, 1)
+

Any particular reason for adding this blank line?

You add more below, and a comment. Okay, but I'd commit the script exactly as given in commit b45c03f, then add improvements on top.

Quoted 57 lines
scripts/coccinelle/g_new.cocci new file +57 -0
+@@
+type T;
+expression n;
+@@
+-g_malloc(sizeof(T) * (n))
++g_new(T, n)
+@@
+type T;
+expression n;
+@@
+-g_try_malloc(sizeof(T) * (n))
++g_try_new(T, n)
+@@
+type T;
+expression n;
+@@
+-g_malloc0(sizeof(T) * (n))
++g_new0(T, n)
+@@
+type T;
+expression n;
+@@
+-g_try_malloc0(sizeof(T) * (n))
++g_try_new0(T, n)
+
+@@
+type T;
+expression p, n;
+@@
+-g_realloc(p, sizeof(T) * (n))
++g_renew(T, p, n)
+@@
+type T;
+expression p, n;
+@@
+-g_try_realloc(p, sizeof(T) * (n))
++g_try_renew(T, p, n)
+
+// drop superfluous cast
+@@
+type T;
+expression n;
+@@
+-(T *)g_new(T, n)
++g_new(T, n)
+@@
+type T;
+expression n;
+@@
+-(T *)g_new0(T, n)
++g_new0(T, n)
+@@
+type T;
+expression p, n;
+@@
+-(T *)g_renew(T, p, n)
++g_renew(T, p, n)
#3 lore raw

Re: [Qemu-devel] [PATCH 01/88] cocci: script to use g_new() & friends

Hi Markus,

Quoted 12 lines · Markus Armbruster
Quoted 10 lines · Philippe Mathieu-Daudé

Imported from Markus Armbruster commit b45c03f

---

 scripts/coccinelle/g_new.cocci | 101 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 101 insertions(+)
 create mode 100644 scripts/coccinelle/g_new.cocci
Quoted 10 lines

scripts/coccinelle/g_new.cocci line 1

Quoted 7 lines
scripts/coccinelle/g_new.cocci new file +1 -0
new file mode 100644
index 0000000000..1e57685a6b
@@ -0,0 +1,101 @@
+/* transform g_new*() alloc with size arguments of the form sizeof(T) [* N]

Confusing. Sounds like we transform g_new() into something else. Also, wing both ends of the comment, and start with a capital letter.

Ok

Quoted 8 lines

scripts/coccinelle/g_new.cocci line 5

Quoted 5 lines
scripts/coccinelle/g_new.cocci new file +4 -0
+ *
+ *   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

Start your sentences with a capital letter. Or rather, keep my commit message's capital letters intact ;)

Yes :|

Quoted 8 lines

scripts/coccinelle/g_new.cocci line 8

Quoted 4 lines
scripts/coccinelle/g_new.cocci new file +3 -0
+ *   more type errors.
+ *
+ *    Copyright: (C) 2017 Markus Armbruster <[email protected]>. GPLv2+.

If you want to put a copyright note into this file, you should stick to the common format:

Quoted 11 lines

/*
* Rewrite memory allocations to use g_new() & friends
*
* Copyright (C) 2014-2017 Red Hat, Inc.
*
* Authors:
* Markus Armbruster <[email protected]>,
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/

Ok

Quoted 3 lines

scripts/coccinelle/g_new.cocci line 9

Quoted 1 line
scripts/coccinelle/g_new.cocci new file +1 -0
+ *    (Imported from b45c03f585ea9bb1af76c73e82195418c294919d)

Scratch this line. It's in the commit message, and that suffices.

Ok

Quoted 9 lines

scripts/coccinelle/g_new.cocci line 16

Quoted 7 lines
scripts/coccinelle/g_new.cocci new file +7 -0
+ *
+ * See http://lists.nongnu.org/archive/html/qemu-devel/2017-09/msg00908.html:
+ *
+ *   g_new() advantages (from glib doc):
+ *   - the returned pointer is cast to a pointer to the given type.
+ *   - care is taken to avoid overflow when calculating the size of the
+ *   allocated block.

Repeats what you just said in the text pasted from my commit message.

Ok

Quoted 11 lines

scripts/coccinelle/g_new.cocci line 22

Quoted 6 lines
scripts/coccinelle/g_new.cocci new file +6 -0
+ *
+ *   p = g_malloc(sizeof(*p)) is idiomatic, and not obviously inferior to
+ *   p = g_new(T, 1), where T is the type of *p.
+ *   But once you add multiplication, g_new() adds something useful: overflow
+ *   protection.  Conversion to g_new() might make sense then.
+ */

This part doesn't really apply, yet: the semantic patch doesn't deal with sizeof(*p).

Please write a coherent introduction instead of a series of quotations.

Sorry :S I'll try :)

Quoted 25 lines
Quoted 12 lines
scripts/coccinelle/g_new.cocci new file +12 -0
+
+@@
+type T;
+@@
+-g_malloc(sizeof(T))
++g_new(T, 1)
+@@
+type T;
+@@
+-g_try_malloc(sizeof(T))
++g_try_new(T, 1)
+@@

scripts/coccinelle/g_new.cocci line 44

Quoted 10 lines
scripts/coccinelle/g_new.cocci new file +10 -0
+type T;
+@@
+-g_malloc0(sizeof(T))
++g_new0(T, 1)
+@@
+type T;
+@@
+-g_try_malloc0(sizeof(T))
++g_try_new0(T, 1)
+

Any particular reason for adding this blank line?

Quoted 2 lines

You add more below, and a comment. Okay, but I'd commit the script exactly as given in commit b45c03f, then add improvements on top.

Yes.

Quoted 49 lines
Quoted 49 lines
scripts/coccinelle/g_new.cocci new file +49 -0
+@@
+type T;
+expression n;
+@@
+-g_malloc(sizeof(T) * (n))
++g_new(T, n)
+@@
+type T;
+expression n;
+@@
+-g_try_malloc(sizeof(T) * (n))
++g_try_new(T, n)
+@@
+type T;
+expression n;
+@@
+-g_malloc0(sizeof(T) * (n))
++g_new0(T, n)
+@@
+type T;
+expression n;
+@@
+-g_try_malloc0(sizeof(T) * (n))
++g_try_new0(T, n)
+
+@@
+type T;
+expression p, n;
+@@
+-g_realloc(p, sizeof(T) * (n))
++g_renew(T, p, n)
+@@
+type T;
+expression p, n;
+@@
+-g_try_realloc(p, sizeof(T) * (n))
++g_try_renew(T, p, n)
+
+// drop superfluous cast
+@@
+type T;
+expression n;
+@@
+-(T *)g_new(T, n)
++g_new(T, n)
+@@
+type T;
+expression n;
+@@
Quoted 8 lines

scripts/coccinelle/g_new.cocci line 101

Quoted 8 lines
scripts/coccinelle/g_new.cocci new file +8 -0
+-(T *)g_new0(T, n)
++g_new0(T, n)
+@@
+type T;
+expression p, n;
+@@
+-(T *)g_renew(T, p, n)
++g_renew(T, p, n)

Thanks for your review :)

Phil.

#4 lore raw

PATCH 2/88 cocci: add more g_new() transformations

In reply to Philippe Mathieu-Daudé
---
 scripts/coccinelle/g_new.cocci | 73 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
scripts/coccinelle/g_new.cocci +73 -0
index 1e57685a6b..c767325a21 100644
@@ -80,6 +80,49 @@ expression p, n;
 -g_try_realloc(p, sizeof(T) * (n))
 +g_try_renew(T, p, n)
 
+@@
+type T;
+expression n;
+@@
+(
+-g_malloc_n(n, sizeof(T))
++g_new(T, n)
+|
+-g_malloc0_n(n, sizeof(T))
++g_new0(T, n)
+|
+-g_try_malloc_n(n, sizeof(T))
++g_try_new(T, n)
+|
+-g_try_malloc0_n(n, sizeof(T))
++g_try_new0(T, n)
+)
+
+@@
+type T;
+identifier m;
+@@
+T *m;
+...
+(
+-m = g_malloc(sizeof(*m));
++m = g_new(T, 1);
+|
+-m = g_malloc0(sizeof(*m));
++m = g_new0(T, 1);
+|
+-m = g_try_malloc(sizeof(*m));
++m = g_try_new(T, 1);
+|
+-m = g_try_malloc0(sizeof(*m));
++m = g_try_new0(T, 1);
+)
+
+////////////////////////////////////////
+//
+// last transformations: cleanups
+//
+
 // drop superfluous cast
 @@
 type T;
@@ -99,3 +142,33 @@ expression p, n;
 @@
 -(T *)g_renew(T, p, n)
 +g_renew(T, p, n)
+@@
+type T;
+expression n;
+@@
+(
+-(T *)g_try_new(T, n)
++g_try_new(T, n)
+|
+-(T *)g_try_new0(T, n)
++g_try_new0(T, n)
+)
+
+// drop superfluous parenthesis
+@@
+type T;
+expression c;
+@@
+(
+-g_new(T, (c))
++g_new(T, c)
+|
+-g_try_new(T, (c))
++g_try_new(T, c)
+|
+-g_new0(T, (c))
++g_new0(T, c)
+|
+-g_try_new0(T, (c))
++g_try_new0(T, c)
+)
Signature · 1 line
2.14.2
#5 lore raw

Re: [Qemu-devel] [PATCH 02/88] cocci: add more g_new() transformations

The commit message should explain the additional transformations briefly and informally. In particular, why they're a good idea. Same for PATCH 3-5.

Quoted 42 lines · Philippe Mathieu-Daudé
---
 scripts/coccinelle/g_new.cocci | 73 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
scripts/coccinelle/g_new.cocci +29 -0
index 1e57685a6b..c767325a21 100644
@@ -80,6 +80,49 @@ expression p, n;
 -g_try_realloc(p, sizeof(T) * (n))
 +g_try_renew(T, p, n)
 
+@@
+type T;
+expression n;
+@@
+(
+-g_malloc_n(n, sizeof(T))
++g_new(T, n)
+|
+-g_malloc0_n(n, sizeof(T))
++g_new0(T, n)
+|
+-g_try_malloc_n(n, sizeof(T))
++g_try_new(T, n)
+|
+-g_try_malloc0_n(n, sizeof(T))
++g_try_new0(T, n)
+)
+
+@@
+type T;
+identifier m;
+@@
+T *m;
+...
+(
+-m = g_malloc(sizeof(*m));
++m = g_new(T, 1);
+|
+-m = g_malloc0(sizeof(*m));

scripts/coccinelle/g_new.cocci expression p, n; · line 121

Quoted 10 lines
scripts/coccinelle/g_new.cocci +10 -0
++m = g_new0(T, 1);
+|
+-m = g_try_malloc(sizeof(*m));
++m = g_try_new(T, 1);
+|
+-m = g_try_malloc0(sizeof(*m));
++m = g_try_new0(T, 1);
+)
+
+////////////////////////////////////////

Please scratch this line. Overly elaborate comment decoration.

Quoted 41 lines
scripts/coccinelle/g_new.cocci +34 -0
+//
+// last transformations: cleanups
+//
+
 // drop superfluous cast
 @@
 type T;
@@ -99,3 +142,33 @@ expression p, n;
 @@
 -(T *)g_renew(T, p, n)
 +g_renew(T, p, n)
+@@
+type T;
+expression n;
+@@
+(
+-(T *)g_try_new(T, n)
++g_try_new(T, n)
+|
+-(T *)g_try_new0(T, n)
++g_try_new0(T, n)
+)
+
+// drop superfluous parenthesis
+@@
+type T;
+expression c;
+@@
+(
+-g_new(T, (c))
++g_new(T, c)
+|
+-g_try_new(T, (c))
++g_try_new(T, c)
+|
+-g_new0(T, (c))
++g_new0(T, c)
+|
+-g_try_new0(T, (c))
++g_try_new0(T, c)
+)
#6 lore raw

PATCH 3/88 cocci: extract typeof() from g_new()

In reply to Philippe Mathieu-Daudé
---
 scripts/coccinelle/g_new.cocci | 9 +++++++++
 1 file changed, 9 insertions(+)
scripts/coccinelle/g_new.cocci +9 -0
index c767325a21..368f0c5651 100644
@@ -118,6 +118,15 @@ T *m;
 +m = g_try_new0(T, 1);
 )
 
+@@
+type T;
+identifier m;
+@@
+T **m;
+...
+- *m = g_malloc0(sizeof(**m));
++ *m = g_new0(T *, 1);
+
 ////////////////////////////////////////
 //
 // last transformations: cleanups
Signature · 1 line
2.14.2
#7 lore raw

PATCH 4/88 cocci: avoid use of g_new0()

In reply to Philippe Mathieu-Daudé
---
 scripts/coccinelle/g_new.cocci | 46 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
scripts/coccinelle/g_new.cocci +46 -0
index 368f0c5651..9643ce3f23 100644
@@ -127,6 +127,52 @@ T **m;
 - *m = g_malloc0(sizeof(**m));
 + *m = g_new0(T *, 1);
 
+////////////////////////////////////////
+//
+// no point in zeroing the allocation
+//
+
+// the loop right afterwards fully initializes the memory
+@@
+type T;
+identifier a, i;
+expression c, e;
+@@
+(
+-a = g_new0(T, c);
+    ... when != a, c
++a = g_new(T, c);
+    for (i = 0; i < c; i++) {
+        a[i] = e;
+    }
+|
+-a = g_try_new0(T, c);
+    ... when != a, c
++a = g_try_new(T, c);
+    for (i = 0; i < c; i++) {
+        a[i] = e;
+    }
+)
+
+// compound literals
+@@
+type T;
+identifier p;
+expression s, e;
+@@
+(
+- p = g_malloc0(s);
++ p = g_malloc(s);
+|
+- p = g_try_malloc0(s);
++ p = g_try_malloc(s);
+|
+- p = g_new0(T, 1);
++ p = g_new(T, 1);
+)
+  ... when != p
+  *p = e;
+
 ////////////////////////////////////////
 //
 // last transformations: cleanups
Signature · 1 line
2.14.2
#8 lore raw

Re: [Qemu-devel] [PATCH 04/88] cocci: avoid use of g_new0()

Quoted 48 lines · Philippe Mathieu-Daudé
---
 scripts/coccinelle/g_new.cocci | 46 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
scripts/coccinelle/g_new.cocci +35 -0
index 368f0c5651..9643ce3f23 100644
@@ -127,6 +127,52 @@ T **m;
 - *m = g_malloc0(sizeof(**m));
 + *m = g_new0(T *, 1);
 
+////////////////////////////////////////
+//
+// no point in zeroing the allocation
+//
+
+// the loop right afterwards fully initializes the memory
+@@
+type T;
+identifier a, i;
+expression c, e;
+@@
+(
+-a = g_new0(T, c);
+    ... when != a, c
++a = g_new(T, c);
+    for (i = 0; i < c; i++) {
+        a[i] = e;
+    }
+|
+-a = g_try_new0(T, c);
+    ... when != a, c
++a = g_try_new(T, c);
+    for (i = 0; i < c; i++) {
+        a[i] = e;
+    }
+)
+
+// compound literals
+@@
+type T;
+identifier p;
+expression s, e;
+@@
+(
+- p = g_malloc0(s);

scripts/coccinelle/g_new.cocci T **m; · line 174

Quoted 10 lines
scripts/coccinelle/g_new.cocci +10 -0
++ p = g_malloc(s);
+|
+- p = g_try_malloc0(s);
++ p = g_try_malloc(s);
+|
+- p = g_new0(T, 1);
++ p = g_new(T, 1);
+)
+  ... when != p
+  *p = e;

It seems I misunderstood compound literals, I somehow believed this would imply uninitialized fields would be zeroed.
So this transformation leads to incorrect code.

Quoted 5 lines
scripts/coccinelle/g_new.cocci +1 -0
+
 ////////////////////////////////////////
 //
 // last transformations: cleanups
#9 lore raw

PATCH 5/88 cocci: use g_strfreev()

In reply to Philippe Mathieu-Daudé
---
 scripts/coccinelle/g_new.cocci | 11 +++++++++++
 1 file changed, 11 insertions(+)
scripts/coccinelle/g_new.cocci +11 -0
index 9643ce3f23..42ab166d04 100644
@@ -173,6 +173,17 @@ expression s, e;
   ... when != p
   *p = e;
 
+// g_strfreev()
+@@
+identifier p, a;
+@@
+-   for (p = a; *p; p++) {
+-       g_free(*p);
+-   }
+    ... when != a
+-    g_free(a);
++    g_strfreev(a);
+
 ////////////////////////////////////////
 //
 // last transformations: cleanups
Signature · 1 line
2.14.2
#10 lore raw

PATCH 6/88 ARM: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: added hw/arm/virt-acpi-build.c and target/arm/helper.c]
---
 hw/arm/virt-acpi-build.c | 2 +-
 hw/timer/arm_timer.c     | 2 +-
 target/arm/helper.c      | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
hw/arm/virt-acpi-build.c +1 -1
index 3d78ff68e6..812c3c3f5b 100644
@@ -869,7 +869,7 @@ void virt_acpi_setup(VirtMachineState *vms)
         return;
     }
 
-    build_state = g_malloc0(sizeof *build_state);
+    build_state = g_new0(AcpiBuildState, 1);
 
     acpi_build_tables_init(&tables);
     virt_acpi_build(vms, &tables);
hw/timer/arm_timer.c +1 -1
index 98fddd7ac1..75affcb8a6 100644
@@ -166,7 +166,7 @@ static arm_timer_state *arm_timer_init(uint32_t freq)
     arm_timer_state *s;
     QEMUBH *bh;
 
-    s = (arm_timer_state *)g_malloc0(sizeof(arm_timer_state));
+    s = g_new0(arm_timer_state, 1);
     s->freq = freq;
     s->control = TIMER_CTRL_IE;
 
target/arm/helper.c +2 -2
index 1d689f00b3..b320772cc6 100644
@@ -5333,12 +5333,12 @@ static void arm_cpu_add_definition(gpointer data, gpointer user_data)
     const char *typename;
 
     typename = object_class_get_name(oc);
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(CpuDefinitionInfo, 1);
     info->name = g_strndup(typename,
                            strlen(typename) - strlen("-" TYPE_ARM_CPU));
     info->q_typename = g_strdup(typename);
 
-    entry = g_malloc0(sizeof(*entry));
+    entry = g_new0(CpuDefinitionInfoList, 1);
     entry->value = info;
     entry->next = *cpu_list;
     *cpu_list = entry;
Signature · 1 line
2.14.2
#11 lore raw

PATCH 7/88 Audio: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: added audio/alsaaudio.c and audio/coreaudio.c]
---
 audio/alsaaudio.c    | 2 +-
 audio/coreaudio.c    | 2 +-
 audio/dsoundaudio.c  | 2 +-
 audio/ossaudio.c     | 2 +-
 audio/paaudio.c      | 2 +-
 audio/wavaudio.c     | 2 +-
 audio/wavcapture.c   | 2 +-
 hw/audio/intel-hda.c | 2 +-
 8 files changed, 8 insertions(+), 8 deletions(-)
audio/alsaaudio.c +1 -1
index 3652a7b5fa..1a129c79e3 100644
@@ -1126,7 +1126,7 @@ static ALSAConf glob_conf = {
 
 static void *alsa_audio_init (void)
 {
-    ALSAConf *conf = g_malloc(sizeof(ALSAConf));
+    ALSAConf *conf = g_new(ALSAConf, 1);
     *conf = glob_conf;
     return conf;
 }
audio/coreaudio.c +1 -1
index c75142084f..651b390b5e 100644
@@ -687,7 +687,7 @@ static CoreaudioConf glob_conf = {
 
 static void *coreaudio_audio_init (void)
 {
-    CoreaudioConf *conf = g_malloc(sizeof(CoreaudioConf));
+    CoreaudioConf *conf = g_new(CoreaudioConf, 1);
     *conf = glob_conf;
 
     return conf;
audio/dsoundaudio.c +1 -1
index 516846eb80..0492d9075e 100644
@@ -787,7 +787,7 @@ static void *dsound_audio_init (void)
 {
     int err;
     HRESULT hr;
-    dsound *s = g_malloc0(sizeof(dsound));
+    dsound *s = g_new0(dsound, 1);
 
     s->conf = glob_conf;
     hr = CoInitialize (NULL);
audio/ossaudio.c +1 -1
index 0edd7ea5fe..50d772011c 100644
@@ -846,7 +846,7 @@ static OSSConf glob_conf = {
 
 static void *oss_audio_init (void)
 {
-    OSSConf *conf = g_malloc(sizeof(OSSConf));
+    OSSConf *conf = g_new(OSSConf, 1);
     *conf = glob_conf;
 
     if (access(conf->devpath_in, R_OK | W_OK) < 0 ||
audio/paaudio.c +1 -1
index 65beb6f010..fc32960c25 100644
@@ -814,7 +814,7 @@ static PAConf glob_conf = {
 
 static void *qpa_audio_init (void)
 {
-    paaudio *g = g_malloc(sizeof(paaudio));
+    paaudio *g = g_new(paaudio, 1);
     g->conf = glob_conf;
     g->mainloop = NULL;
     g->context = NULL;
audio/wavaudio.c +1 -1
index 341eec3121..f90a02610f 100644
@@ -231,7 +231,7 @@ static WAVConf glob_conf = {
 
 static void *wav_audio_init (void)
 {
-    WAVConf *conf = g_malloc(sizeof(WAVConf));
+    WAVConf *conf = g_new(WAVConf, 1);
     *conf = glob_conf;
     return conf;
 }
audio/wavcapture.c +1 -1
index 5863803584..a744b748a5 100644
@@ -145,7 +145,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
     ops.capture = wav_capture;
     ops.destroy = wav_destroy;
 
-    wav = g_malloc0 (sizeof (*wav));
+    wav = g_new0(WAVState, 1);
 
     shift = bits16 + stereo;
     hdr[34] = bits16 ? 0x10 : 0x08;
hw/audio/intel-hda.c +1 -1
index 18a50a8f83..3a2b611d41 100644
@@ -470,7 +470,7 @@ static void intel_hda_parse_bdl(IntelHDAState *d, IntelHDAStream *st)
     addr = intel_hda_addr(st->bdlp_lbase, st->bdlp_ubase);
     st->bentries = st->lvi +1;
     g_free(st->bpl);
-    st->bpl = g_malloc(sizeof(bpl) * st->bentries);
+    st->bpl = g_new(bpl, st->bentries);
     for (i = 0; i < st->bentries; i++, addr += 16) {
         pci_dma_read(&d->pci, addr, buf, 16);
         st->bpl[i].addr  = le64_to_cpu(*(uint64_t *)buf);
Signature · 1 line
2.14.2
#12 lore raw

PATCH 8/88 BT: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: another use in hw/bt/l2cap.c]
---
 bt-host.c     | 2 +-
 bt-vhci.c     | 2 +-
 hw/bt/core.c  | 4 ++--
 hw/bt/hci.c   | 4 ++--
 hw/bt/l2cap.c | 6 +++---
 5 files changed, 9 insertions(+), 9 deletions(-)
bt-host.c +1 -1
index 2f8f631c25..ad9e45ea43 100644
@@ -177,7 +177,7 @@ struct HCIInfo *bt_host_hci(const char *id)
     }
 # endif
 
-    s = g_malloc0(sizeof(struct bt_host_hci_s));
+    s = g_new0(struct bt_host_hci_s, 1);
     s->fd = fd;
     s->hci.cmd_send = bt_host_cmd;
     s->hci.sco_send = bt_host_sco;
bt-vhci.c +1 -1
index 9d277c32bf..a885e2b8b9 100644
@@ -157,7 +157,7 @@ void bt_vhci_init(struct HCIInfo *info)
         exit(-1);
     }
 
-    s = g_malloc0(sizeof(struct bt_vhci_s));
+    s = g_new0(struct bt_vhci_s, 1);
     s->fd = fd;
     s->info = info ?: qemu_next_hci();
     s->info->opaque = s;
hw/bt/core.c +2 -2
index 615f0af073..281bb40501 100644
@@ -55,7 +55,7 @@ static void bt_dummy_lmp_acl_resp(struct bt_link_s *link,
 /* Slaves that don't hold any additional per link state can use these */
 static void bt_dummy_lmp_connection_request(struct bt_link_s *req)
 {
-    struct bt_link_s *link = g_malloc0(sizeof(struct bt_link_s));
+    struct bt_link_s *link = g_new0(struct bt_link_s, 1);
 
     link->slave = req->slave;
     link->host = req->host;
@@ -135,7 +135,7 @@ struct bt_scatternet_s *qemu_find_bt_vlan(int id)
         if (vlan->id == id)
             return &vlan->net;
     }
-    vlan = g_malloc0(sizeof(struct bt_vlan_s));
+    vlan = g_new0(struct bt_vlan_s, 1);
     vlan->id = id;
     pvlan = &first_bt_vlan;
     while (*pvlan != NULL)
hw/bt/hci.c +2 -2
index 476ebec0ab..08e65eb62e 100644
@@ -742,7 +742,7 @@ static void bt_hci_connection_reject_event(struct bt_hci_s *hci,
 static void bt_hci_connection_accept(struct bt_hci_s *hci,
                 struct bt_device_s *host)
 {
-    struct bt_hci_link_s *link = g_malloc0(sizeof(struct bt_hci_link_s));
+    struct bt_hci_link_s *link = g_new0(struct bt_hci_link_s, 1);
     evt_conn_complete params;
     uint16_t handle;
     uint8_t status = HCI_SUCCESS;
@@ -2158,7 +2158,7 @@ static void bt_hci_destroy(struct bt_device_s *dev)
 
 struct HCIInfo *bt_new_hci(struct bt_scatternet_s *net)
 {
-    struct bt_hci_s *s = g_malloc0(sizeof(struct bt_hci_s));
+    struct bt_hci_s *s = g_new0(struct bt_hci_s, 1);
 
     s->lm.inquiry_done = timer_new_ns(QEMU_CLOCK_VIRTUAL, bt_hci_inquiry_done, s);
     s->lm.inquiry_next = timer_new_ns(QEMU_CLOCK_VIRTUAL, bt_hci_inquiry_next, s);
hw/bt/l2cap.c +3 -3
index e342045140..94f5067d6e 100644
@@ -1241,7 +1241,7 @@ static void l2cap_lmp_connection_request(struct bt_link_s *link)
 
     /* Always accept - we only get called if (dev->device->page_scan).  */
 
-    l2cap = g_malloc0(sizeof(struct slave_l2cap_instance_s));
+    l2cap = g_new0(struct slave_l2cap_instance_s, 1);
     l2cap->link.slave = &dev->device;
     l2cap->link.host = link->host;
     l2cap_init(&l2cap->l2cap, &l2cap->link, 0);
@@ -1262,7 +1262,7 @@ static void l2cap_lmp_connection_complete(struct bt_link_s *link)
         return;
     }
 
-    l2cap = g_malloc0(sizeof(struct l2cap_instance_s));
+    l2cap = g_new0(struct l2cap_instance_s, 1);
     l2cap_init(l2cap, link, 1);
 
     link->acl_mode = acl_active;
@@ -1358,7 +1358,7 @@ void bt_l2cap_psm_register(struct bt_l2cap_device_s *dev, int psm, int min_mtu,
         exit(-1);
     }
 
-    new_psm = g_malloc0(sizeof(*new_psm));
+    new_psm = g_new0(struct bt_l2cap_psm_s, 1);
     new_psm->psm = psm;
     new_psm->min_mtu = min_mtu;
     new_psm->new_channel = new_channel;
Signature · 1 line
2.14.2
#13 lore raw

PATCH 9/88 Bootdevice: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 bootdevice.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bootdevice.c +1 -1
index 1141009114..a2936503da 100644
@@ -165,7 +165,7 @@ void add_boot_device_path(int32_t bootindex, DeviceState *dev,
 
     del_boot_device_path(dev, suffix);
 
-    node = g_malloc0(sizeof(FWBootEntry));
+    node = g_new0(FWBootEntry, 1);
     node->bootindex = bootindex;
     node->suffix = g_strdup(suffix);
     node->dev = dev;
Signature · 1 line
2.14.2
#14 lore raw

PATCH 10/88 Character devices: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: squashed PC Chipsets: parallel + serial]
---
 hw/char/parallel.c  | 2 +-
 hw/char/serial.c    | 4 ++--
 hw/char/sh_serial.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
hw/char/parallel.c +1 -1
index f79dc76543..da8566538e 100644
@@ -614,7 +614,7 @@ bool parallel_mm_init(MemoryRegion *address_space,
 {
     ParallelState *s;
 
-    s = g_malloc0(sizeof(ParallelState));
+    s = g_new0(ParallelState, 1);
     s->irq = irq;
     qemu_chr_fe_init(&s->chr, chr, &error_abort);
     s->it_shift = it_shift;
hw/char/serial.c +2 -2
index 376bd2f240..dcc25d649f 100644
@@ -978,7 +978,7 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase,
 {
     SerialState *s;
 
-    s = g_malloc0(sizeof(SerialState));
+    s = g_new0(SerialState, 1);
 
     s->irq = irq;
     s->baudbase = baudbase;
@@ -1034,7 +1034,7 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
 {
     SerialState *s;
 
-    s = g_malloc0(sizeof(SerialState));
+    s = g_new0(SerialState, 1);
 
     s->it_shift = it_shift;
     s->irq = irq;
hw/char/sh_serial.c +1 -1
index 835b5378a0..0d1a67d450 100644
@@ -365,7 +365,7 @@ void sh_serial_init(MemoryRegion *sysmem,
 {
     sh_serial_state *s;
 
-    s = g_malloc0(sizeof(sh_serial_state));
+    s = g_new0(sh_serial_state, 1);
 
     s->feat = feat;
     s->flags = SH_SERIAL_FLAG_TEND | SH_SERIAL_FLAG_TDE;
Signature · 1 line
2.14.2
#15 lore raw

PATCH 11/88 Cryptodev Backends: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 backends/cryptodev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
backends/cryptodev.c +1 -1
index 67edfa5328..44f693f58b 100644
@@ -42,7 +42,7 @@ cryptodev_backend_new_client(const char *model,
 {
     CryptoDevBackendClient *cc;
 
-    cc = g_malloc0(sizeof(CryptoDevBackendClient));
+    cc = g_new0(CryptoDevBackendClient, 1);
     cc->model = g_strdup(model);
     if (name) {
         cc->name = g_strdup(name);
Signature · 1 line
2.14.2
#16 lore raw

PATCH 12/88 backends/hostmem: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 backends/hostmem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
backends/hostmem.c +2 -2
index ee2c2d5bfd..6a12f920c2 100644
@@ -78,7 +78,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
         return;
     }
 
-    *node = g_malloc0(sizeof(**node));
+    *node = g_new0(uint16List, 1);
     (*node)->value = value;
     node = &(*node)->next;
 
@@ -88,7 +88,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
             break;
         }
 
-        *node = g_malloc0(sizeof(**node));
+        *node = g_new0(uint16List, 1);
         (*node)->value = value;
         node = &(*node)->next;
     } while (true);
Signature · 1 line
2.14.2
#17 lore raw

PATCH 13/88 Dirty Bitmaps: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: squashed tests/test-hbitmap.c changes]
---
 tests/test-hbitmap.c | 2 +-
 util/hbitmap.c       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tests/test-hbitmap.c +1 -1
index af41642346..fea3a64712 100644
@@ -122,7 +122,7 @@ static void hbitmap_test_truncate_impl(TestHBitmapData *data,
 
     n = hbitmap_test_array_size(size);
     m = hbitmap_test_array_size(data->old_size);
-    data->bits = g_realloc(data->bits, sizeof(unsigned long) * n);
+    data->bits = g_renew(unsigned long, data->bits, n);
     if (n > m) {
         memset(&data->bits[m], 0x00, sizeof(unsigned long) * (n - m));
     }
util/hbitmap.c +1 -1
index 2f9d0fdbd0..4eb0188836 100644
@@ -668,7 +668,7 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size)
         }
         old = hb->sizes[i];
         hb->sizes[i] = size;
-        hb->levels[i] = g_realloc(hb->levels[i], size * sizeof(unsigned long));
+        hb->levels[i] = g_renew(unsigned long, hb->levels[i], size);
         if (!shrink) {
             memset(&hb->levels[i][old], 0x00,
                    (size - old) * sizeof(*hb->levels[i]));
Signature · 1 line
2.14.2
Reviewed-by Acked-by on v1 13/88
#18 lore raw

Re: [Qemu-devel] [PATCH 13/88] Dirty Bitmaps: use g_new() family of functions

Quoted 29 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: squashed tests/test-hbitmap.c changes]
---
 tests/test-hbitmap.c | 2 +-
 util/hbitmap.c       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tests/test-hbitmap.c +1 -1
index af41642346..fea3a64712 100644
@@ -122,7 +122,7 @@ static void hbitmap_test_truncate_impl(TestHBitmapData *data,
 
     n = hbitmap_test_array_size(size);
     m = hbitmap_test_array_size(data->old_size);
-    data->bits = g_realloc(data->bits, sizeof(unsigned long) * n);
+    data->bits = g_renew(unsigned long, data->bits, n);
     if (n > m) {
         memset(&data->bits[m], 0x00, sizeof(unsigned long) * (n - m));
     }
util/hbitmap.c +0 -0
index 2f9d0fdbd0..4eb0188836 100644

util/hbitmap.c void hbitmap_truncate(HBitmap *hb, uint64_t size) · line 674

Quoted 8 lines
util/hbitmap.c +1 -1
@@ -668,7 +668,7 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size)
         }
         old = hb->sizes[i];
         hb->sizes[i] = size;
-        hb->levels[i] = g_realloc(hb->levels[i], size * sizeof(unsigned long));
+        hb->levels[i] = g_renew(unsigned long, hb->levels[i], size);
         if (!shrink) {
             memset(&hb->levels[i][old], 0x00,
                    (size - old) * sizeof(*hb->levels[i]));

Hm, I guess g_renew() isn't a new addition to glib, and we can safely use it.

And for convenience, this can be staged by whomever wishes to stage the whole 88 patch enchilada:

#19 lore raw

PATCH 14/88 ui/vnc: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: renamed 'Graphics' -> ui/vnc, added ui/vnc.c and ui/vnc-palette.c]
---
 ui/vnc-enc-tight.c | 2 +-
 ui/vnc-palette.c   | 2 +-
 ui/vnc.c           | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)
ui/vnc-enc-tight.c +1 -1
index f38aceb4da..48ec584098 100644
@@ -1475,7 +1475,7 @@ static int send_sub_rect(VncState *vs, int x, int y, int w, int h)
 #endif
 
     if (!color_count_palette) {
-        color_count_palette = g_malloc(sizeof(VncPalette));
+        color_count_palette = g_new(VncPalette, 1);
         vnc_tight_cleanup_notifier.notify = vnc_tight_cleanup;
         qemu_thread_atexit_add(&vnc_tight_cleanup_notifier);
     }
ui/vnc-palette.c +1 -1
index dc7c0ba997..284e118715 100644
@@ -56,7 +56,7 @@ VncPalette *palette_new(size_t max, int bpp)
 {
     VncPalette *palette;
 
-    palette = g_malloc0(sizeof(*palette));
+    palette = g_new0(VncPalette, 1);
     palette_init(palette, max, bpp);
     return palette;
 }
ui/vnc.c +3 -3
index 9f8d5a1b1f..b021fb398b 100644
@@ -231,7 +231,7 @@ static VncServerInfo *vnc_server_info_get(VncDisplay *vd)
         return NULL;
     }
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(VncServerInfo, 1);
     vnc_init_basic_info_from_server_addr(vd->lsock[0],
                                          qapi_VncServerInfo_base(info), &err);
     info->has_auth = true;
@@ -316,7 +316,7 @@ static VncClientInfo *qmp_query_vnc_client(const VncState *client)
     VncClientInfo *info;
     Error *err = NULL;
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(VncClientInfo, 1);
 
     vnc_init_basic_info_from_remote_addr(client->sioc,
                                          qapi_VncClientInfo_base(info),
@@ -3047,7 +3047,7 @@ void vnc_display_init(const char *id)
     if (vnc_display_find(id) != NULL) {
         return;
     }
-    vd = g_malloc0(sizeof(*vd));
+    vd = g_new0(VncDisplay, 1);
 
     vd->id = strdup(id);
     QTAILQ_INSERT_TAIL(&vnc_displays, vd, next);
Signature · 1 line
2.14.2
#20 lore raw

PATCH 15/88 ui/spice: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 ui/spice-core.c    | 10 +++++-----
 ui/spice-display.c |  4 ++--
 ui/spice-input.c   |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)
ui/spice-core.c +5 -5
index ea04dc69b5..e76a3f46eb 100644
@@ -63,7 +63,7 @@ static SpiceTimer *timer_add(SpiceTimerFunc func, void *opaque)
 {
     SpiceTimer *timer;
 
-    timer = g_malloc0(sizeof(*timer));
+    timer = g_new0(SpiceTimer, 1);
     timer->timer = timer_new_ms(QEMU_CLOCK_REALTIME, func, opaque);
     QTAILQ_INSERT_TAIL(&timers, timer, next);
     return timer;
@@ -127,7 +127,7 @@ static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func, void *
 {
     SpiceWatch *watch;
 
-    watch = g_malloc0(sizeof(*watch));
+    watch = g_new0(SpiceWatch, 1);
     watch->fd     = fd;
     watch->func   = func;
     watch->opaque = opaque;
@@ -155,7 +155,7 @@ static void channel_list_add(SpiceChannelEventInfo *info)
 {
     ChannelList *item;
 
-    item = g_malloc0(sizeof(*item));
+    item = g_new0(ChannelList, 1);
     item->info = info;
     QTAILQ_INSERT_TAIL(&channel_list, item, link);
 }
@@ -380,7 +380,7 @@ static SpiceChannelList *qmp_query_spice_channels(void)
 
         assert(item->info->flags & SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT);
 
-        chan = g_malloc0(sizeof(*chan));
+        chan = g_new0(SpiceChannelList, 1);
         chan->value = g_malloc0(sizeof(*chan->value));
 
         paddr = (struct sockaddr *)&item->info->paddr_ext;
@@ -525,7 +525,7 @@ SpiceInfo *qmp_query_spice(Error **errp)
     unsigned int minor;
     unsigned int micro;
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(SpiceInfo, 1);
 
     if (!spice_server || !opts) {
         info->enabled = false;
ui/spice-display.c +2 -2
index 0963c7825f..5b9f6f0bb0 100644
@@ -66,7 +66,7 @@ QXLCookie *qxl_cookie_new(int type, uint64_t io)
 {
     QXLCookie *cookie;
 
-    cookie = g_malloc0(sizeof(*cookie));
+    cookie = g_new0(QXLCookie, 1);
     cookie->type = type;
     cookie->io = io;
     return cookie;
@@ -142,7 +142,7 @@ static void qemu_spice_create_one_update(SimpleSpiceDisplay *ssd,
            rect->left, rect->right,
            rect->top, rect->bottom);
 
-    update   = g_malloc0(sizeof(*update));
+    update = g_new0(SimpleSpiceUpdate, 1);
     drawable = &update->drawable;
     image    = &update->image;
     cmd      = &update->ext.cmd;
ui/spice-input.c +2 -2
index 3d41aa1831..e47ca7a051 100644
@@ -243,12 +243,12 @@ void qemu_spice_input_init(void)
     QemuSpiceKbd *kbd;
     QemuSpicePointer *pointer;
 
-    kbd = g_malloc0(sizeof(*kbd));
+    kbd = g_new0(QemuSpiceKbd, 1);
     kbd->sin.base.sif = &kbd_interface.base;
     qemu_spice_add_interface(&kbd->sin.base);
     qemu_add_led_event_handler(kbd_leds, kbd);
 
-    pointer = g_malloc0(sizeof(*pointer));
+    pointer = g_new0(QemuSpicePointer, 1);
     pointer->mouse.base.sif  = &mouse_interface.base;
     pointer->tablet.base.sif = &tablet_interface.base;
     qemu_spice_add_interface(&pointer->mouse.base);
Signature · 1 line
2.14.2
#21 lore raw

PATCH 16/88 Main loop: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: more uses in vl.c (fixed const char * cast),
squashed cpus-common and changes in util/qemu-timer]

---
 include/qemu/timer.h |  2 +-
 cpus-common.c        |  4 ++--
 util/main-loop.c     |  2 +-
 util/qemu-timer.c    |  2 +-
 vl.c                 | 12 ++++++------
 5 files changed, 11 insertions(+), 11 deletions(-)
include/qemu/timer.h +1 -1
index 1b518bca30..dfc028259c 100644
@@ -518,7 +518,7 @@ static inline QEMUTimer *timer_new_tl(QEMUTimerList *timer_list,
                                       QEMUTimerCB *cb,
                                       void *opaque)
 {
-    QEMUTimer *ts = g_malloc0(sizeof(QEMUTimer));
+    QEMUTimer *ts = g_new0(QEMUTimer, 1);
     timer_init_tl(ts, timer_list, scale, cb, opaque);
     return ts;
 }
cpus-common.c +2 -2
index 59f751ecf9..e613cc33ef 100644
@@ -158,7 +158,7 @@ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data)
 {
     struct qemu_work_item *wi;
 
-    wi = g_malloc0(sizeof(struct qemu_work_item));
+    wi = g_new0(struct qemu_work_item, 1);
     wi->func = func;
     wi->data = data;
     wi->free = true;
@@ -301,7 +301,7 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func,
 {
     struct qemu_work_item *wi;
 
-    wi = g_malloc0(sizeof(struct qemu_work_item));
+    wi = g_new0(struct qemu_work_item, 1);
     wi->func = func;
     wi->data = data;
     wi->free = true;
util/main-loop.c +1 -1
index 7558eb5f53..ef784bcda0 100644
@@ -279,7 +279,7 @@ static PollingEntry *first_polling_entry;
 int qemu_add_polling_cb(PollingFunc *func, void *opaque)
 {
     PollingEntry **ppe, *pe;
-    pe = g_malloc0(sizeof(PollingEntry));
+    pe = g_new0(PollingEntry, 1);
     pe->func = func;
     pe->opaque = opaque;
     for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next);
util/qemu-timer.c +1 -1
index 82d56507a2..2f4e21c482 100644
@@ -102,7 +102,7 @@ QEMUTimerList *timerlist_new(QEMUClockType type,
     QEMUTimerList *timer_list;
     QEMUClock *clock = qemu_clock_ptr(type);
 
-    timer_list = g_malloc0(sizeof(QEMUTimerList));
+    timer_list = g_new0(QEMUTimerList, 1);
     qemu_event_init(&timer_list->timers_done_ev, true);
     timer_list->clock = clock;
     timer_list->notify_cb = cb;
vl.c +6 -6
index 3fed457921..9f82a375b3 100644
@@ -1416,7 +1416,7 @@ static int add_semihosting_arg(void *opaque,
     if (strcmp(name, "arg") == 0) {
         s->argc++;
         /* one extra element as g_strjoinv() expects NULL-terminated array */
-        s->argv = g_realloc(s->argv, (s->argc + 1) * sizeof(void *));
+        s->argv = g_renew(const char *, s->argv, s->argc + 1);
         s->argv[s->argc - 1] = val;
         s->argv[s->argc] = NULL;
     }
@@ -1589,7 +1589,7 @@ MachineInfoList *qmp_query_machines(Error **errp)
         MachineInfoList *entry;
         MachineInfo *info;
 
-        info = g_malloc0(sizeof(*info));
+        info = g_new0(MachineInfo, 1);
         if (mc->is_default) {
             info->has_is_default = true;
             info->is_default = true;
@@ -1604,7 +1604,7 @@ MachineInfoList *qmp_query_machines(Error **errp)
         info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus;
         info->hotpluggable_cpus = mc->has_hotpluggable_cpus;
 
-        entry = g_malloc0(sizeof(*entry));
+        entry = g_new0(MachineInfoList, 1);
         entry->value = info;
         entry->next = mach_list;
         mach_list = entry;
@@ -1657,7 +1657,7 @@ VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
 {
     VMChangeStateEntry *e;
 
-    e = g_malloc0(sizeof (*e));
+    e = g_new0(VMChangeStateEntry, 1);
 
     e->cb = cb;
     e->opaque = opaque;
@@ -2546,7 +2546,7 @@ static void add_device_config(int type, const char *cmdline)
 {
     struct device_config *conf;
 
-    conf = g_malloc0(sizeof(*conf));
+    conf = g_new0(struct device_config, 1);
     conf->type = type;
     conf->cmdline = cmdline;
     loc_save(&conf->loc);
@@ -3047,7 +3047,7 @@ static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
 {
     GlobalProperty *g;
 
-    g = g_malloc0(sizeof(*g));
+    g = g_new0(GlobalProperty, 1);
     g->driver   = qemu_opt_get(opts, "driver");
     g->property = qemu_opt_get(opts, "property");
     g->value    = qemu_opt_get(opts, "value");
Signature · 1 line
2.14.2
#22 lore raw

PATCH 17/88 Memory API: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
memory.c +1 -1
index 5e6351a6c1..40d30640eb 100644
@@ -2762,7 +2762,7 @@ void memory_region_invalidate_mmio_ptr(MemoryRegion *mr, hwaddr offset,
     }
 
     if (!invalidate_data) {
-        invalidate_data = g_malloc0(sizeof(MMIOPtrInvalidate));
+        invalidate_data = g_new0(MMIOPtrInvalidate, 1);
         invalidate_data->allocated = 1;
     }
 
Signature · 1 line
2.14.2
#23 lore raw

PATCH 18/88 memory: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
does this file belong to the Memory API subsystem in MAINTAINERS?

 memory_mapping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
memory_mapping.c +1 -1
index a5d38552a6..9c78b41363 100644
@@ -43,7 +43,7 @@ static void create_new_memory_mapping(MemoryMappingList *list,
 {
     MemoryMapping *memory_mapping;
 
-    memory_mapping = g_malloc(sizeof(MemoryMapping));
+    memory_mapping = g_new(MemoryMapping, 1);
     memory_mapping->phys_addr = phys_addr;
     memory_mapping->virt_addr = virt_addr;
     memory_mapping->length = length;
Signature · 1 line
2.14.2
#24 lore raw

PATCH 19/88 exec: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 exec.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
exec.c +4 -4
index 7a80460725..e060c6fea7 100644
@@ -836,7 +836,7 @@ int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
                      VADDR_PRIx ", len=%" VADDR_PRIu, addr, len);
         return -EINVAL;
     }
-    wp = g_malloc(sizeof(*wp));
+    wp = g_new(CPUWatchpoint, 1);
 
     wp->vaddr = addr;
     wp->len = len;
@@ -922,7 +922,7 @@ int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
 {
     CPUBreakpoint *bp;
 
-    bp = g_malloc(sizeof(*bp));
+    bp = g_new(CPUBreakpoint, 1);
 
     bp->pc = pc;
     bp->flags = flags;
@@ -1975,7 +1975,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
         return NULL;
     }
 
-    new_block = g_malloc0(sizeof(*new_block));
+    new_block = g_new0(RAMBlock, 1);
     new_block->mr = mr;
     new_block->used_length = size;
     new_block->max_length = size;
@@ -2036,7 +2036,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
 
     size = HOST_PAGE_ALIGN(size);
     max_size = HOST_PAGE_ALIGN(max_size);
-    new_block = g_malloc0(sizeof(*new_block));
+    new_block = g_new0(RAMBlock, 1);
     new_block->mr = mr;
     new_block->resized = resized;
     new_block->used_length = size;
Signature · 1 line
2.14.2
#25 lore raw

PATCH 20/88 Migration: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: indented, added migration/migration.c and migration/page_cache.c]
---
 migration/migration.c    | 2 +-
 migration/page_cache.c   | 2 +-
 migration/postcopy-ram.c | 2 +-
 migration/ram.c          | 3 +--
 4 files changed, 4 insertions(+), 5 deletions(-)
migration/migration.c +1 -1
index 98429dc843..4899182b32 100644
@@ -485,7 +485,7 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     MigrationState *s = migrate_get_current();
 
     /* TODO use QAPI_CLONE() instead of duplicating it inline */
-    params = g_malloc0(sizeof(*params));
+    params = g_new0(MigrationParameters, 1);
     params->has_compress_level = true;
     params->compress_level = s->parameters.compress_level;
     params->has_compress_threads = true;
migration/page_cache.c +1 -1
index ba984c4858..30169a1dd3 100644
@@ -57,7 +57,7 @@ PageCache *cache_init(int64_t num_pages, unsigned int page_size)
     }
 
     /* We prefer not to abort if there is no memory */
-    cache = g_try_malloc(sizeof(*cache));
+    cache = g_try_new(PageCache, 1);
     if (!cache) {
         DPRINTF("Failed to allocate cache\n");
         return NULL;
migration/postcopy-ram.c +1 -1
index 0de68e8b25..d51684ce30 100644
@@ -811,7 +811,7 @@ void *postcopy_get_tmp_page(MigrationIncomingState *mis)
 PostcopyDiscardState *postcopy_discard_send_init(MigrationState *ms,
                                                  const char *name)
 {
-    PostcopyDiscardState *res = g_malloc0(sizeof(PostcopyDiscardState));
+    PostcopyDiscardState *res = g_new0(PostcopyDiscardState, 1);
 
     if (res) {
         res->ramblock_name = name;
migration/ram.c +1 -2
index b83f8977c5..3f5407ee43 100644
@@ -1376,8 +1376,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len)
         goto err;
     }
 
-    struct RAMSrcPageRequest *new_entry =
-        g_malloc0(sizeof(struct RAMSrcPageRequest));
+    struct RAMSrcPageRequest *new_entry = g_new0(struct RAMSrcPageRequest, 1);
     new_entry->rb = ramblock;
     new_entry->offset = start;
     new_entry->len = len;
Signature · 1 line
2.14.2
Reviewed-by on v1 20/88
#26 lore raw

Re: [Qemu-devel] [PATCH 20/88] Migration: use g_new() family of functions

Quoted 5 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: indented, added migration/migration.c and migration/page_cache.c]

Do you want me to include it, or you want to include it yourself?

Later, Juan.

#27 lore raw

PATCH 21/88 NBD: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 nbd/server.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
nbd/server.c +2 -2
index 993ade30bb..b74cc6ab7e 100644
@@ -1047,7 +1047,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size,
 {
     AioContext *ctx;
     BlockBackend *blk;
-    NBDExport *exp = g_malloc0(sizeof(NBDExport));
+    NBDExport *exp = g_new0(NBDExport, 1);
     uint64_t perm;
     int ret;
 
@@ -1539,7 +1539,7 @@ void nbd_client_new(NBDExport *exp,
     NBDClient *client;
     Coroutine *co;
 
-    client = g_malloc0(sizeof(NBDClient));
+    client = g_new0(NBDClient, 1);
     client->refcount = 1;
     client->exp = exp;
     client->tlscreds = tlscreds;
Signature · 1 line
2.14.2
Reviewed-by on v1 21/88
#28 lore raw

Re: [Qemu-devel] [PATCH 21/88] NBD: use g_new() family of functions

Quoted 6 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 nbd/server.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

I'm fine queueing this one through my NBD tree, if it doesn't go in as part of a larger series.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#29 lore raw

PATCH 22/88 LM32: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 hw/lm32/lm32_hwsetup.h | 2 +-
 hw/lm32/lm32_boards.c  | 4 ++--
 hw/lm32/milkymist.c    | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
hw/lm32/lm32_hwsetup.h +1 -1
index a01f6bc5df..38ade3db0e 100644
@@ -58,7 +58,7 @@ static inline HWSetup *hwsetup_init(void)
 {
     HWSetup *hw;
 
-    hw = g_malloc(sizeof(HWSetup));
+    hw = g_new(HWSetup, 1);
     hw->data = g_malloc0(TARGET_PAGE_SIZE);
     hw->ptr = hw->data;
 
hw/lm32/lm32_boards.c +2 -2
index b0bb3ef58a..a9c74e90d4 100644
@@ -99,7 +99,7 @@ static void lm32_evr_init(MachineState *machine)
     int timer0_irq                 = 1;
     int timer1_irq                 = 3;
 
-    reset_info = g_malloc0(sizeof(ResetInfo));
+    reset_info = g_new0(ResetInfo, 1);
 
     if (cpu_model == NULL) {
         cpu_model = "lm32-full";
@@ -196,7 +196,7 @@ static void lm32_uclinux_init(MachineState *machine)
     hwaddr initrd_base  = 0x08400000;
     size_t initrd_max               = 0x01000000;
 
-    reset_info = g_malloc0(sizeof(ResetInfo));
+    reset_info = g_new0(ResetInfo, 1);
 
     if (cpu_model == NULL) {
         cpu_model = "lm32-full";
hw/lm32/milkymist.c +1 -1
index 4db4d2d533..0335f0b322 100644
@@ -106,7 +106,7 @@ milkymist_init(MachineState *machine)
     hwaddr cmdline_base = sdram_base + 0x1000000;
     size_t initrd_max = sdram_size - 0x1002000;
 
-    reset_info = g_malloc0(sizeof(ResetInfo));
+    reset_info = g_new0(ResetInfo, 1);
 
     if (cpu_model == NULL) {
         cpu_model = "lm32-full";
Signature · 1 line
2.14.2
#30 lore raw

PATCH 23/88 M68K: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 hw/m68k/mcf5206.c | 4 ++--
 hw/m68k/mcf5208.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/m68k/mcf5206.c +2 -2
index b81901fdfd..df45e99547 100644
@@ -137,7 +137,7 @@ static m5206_timer_state *m5206_timer_init(qemu_irq irq)
     m5206_timer_state *s;
     QEMUBH *bh;
 
-    s = (m5206_timer_state *)g_malloc0(sizeof(m5206_timer_state));
+    s = g_new0(m5206_timer_state, 1);
     bh = qemu_bh_new(m5206_timer_trigger, s);
     s->timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
     s->irq = irq;
@@ -533,7 +533,7 @@ qemu_irq *mcf5206_init(MemoryRegion *sysmem, uint32_t base, M68kCPU *cpu)
     m5206_mbar_state *s;
     qemu_irq *pic;
 
-    s = (m5206_mbar_state *)g_malloc0(sizeof(m5206_mbar_state));
+    s = g_new0(m5206_mbar_state, 1);
 
     memory_region_init_io(&s->iomem, NULL, &m5206_mbar_ops, s,
                           "mbar", 0x00001000);
hw/m68k/mcf5208.c +1 -1
index b9dde75106..9b93af5fbd 100644
@@ -183,7 +183,7 @@ static void mcf5208_sys_init(MemoryRegion *address_space, qemu_irq *pic)
     memory_region_add_subregion(address_space, 0xfc0a8000, iomem);
     /* Timers.  */
     for (i = 0; i < 2; i++) {
-        s = (m5208_timer_state *)g_malloc0(sizeof(m5208_timer_state));
+        s = g_new0(m5208_timer_state, 1);
         bh = qemu_bh_new(m5208_timer_trigger, s);
         s->timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
         memory_region_init_io(&s->iomem, NULL, &m5208_timer_ops, s,
Signature · 1 line
2.14.2
Reviewed-by on v1 23/88
#31 lore raw

Re: [Qemu-devel] [PATCH 23/88] M68K: use g_new() family of functions

Am Fri, 6 Oct 2017 20:49:18 -0300
schrieb Philippe Mathieu-Daudé <[email protected]>:

Quoted 9 lines

From: Marc-André Lureau <[email protected]>

---
 hw/m68k/mcf5206.c | 4 ++--
 hw/m68k/mcf5208.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
#32 lore raw

PATCH 24/88 MIPS: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: squashed malta + mipssim + r4k]
---
 hw/mips/mips_malta.c         | 2 +-
 hw/mips/mips_mipssim.c       | 2 +-
 hw/mips/mips_r4k.c           | 2 +-
 target/mips/translate_init.c | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)
hw/mips/mips_malta.c +1 -1
index 2adb9bcf89..0eda20e120 100644
@@ -555,7 +555,7 @@ static MaltaFPGAState *malta_fpga_init(MemoryRegion *address_space,
     MaltaFPGAState *s;
     Chardev *chr;
 
-    s = (MaltaFPGAState *)g_malloc0(sizeof(MaltaFPGAState));
+    s = g_new0(MaltaFPGAState, 1);
 
     memory_region_init_io(&s->iomem, NULL, &malta_fpga_ops, s,
                           "malta-fpga", 0x100000);
hw/mips/mips_mipssim.c +1 -1
index a092072e2a..b2696faba1 100644
@@ -166,7 +166,7 @@ mips_mipssim_init(MachineState *machine)
     cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
     env = &cpu->env;
 
-    reset_info = g_malloc0(sizeof(ResetData));
+    reset_info = g_new0(ResetData, 1);
     reset_info->cpu = cpu;
     reset_info->vector = env->active_tc.PC;
     qemu_register_reset(main_cpu_reset, reset_info);
hw/mips/mips_r4k.c +1 -1
index 1272d4ef9d..233455d6e7 100644
@@ -196,7 +196,7 @@ void mips_r4k_init(MachineState *machine)
     cpu = MIPS_CPU(cpu_generic_init(TYPE_MIPS_CPU, cpu_model));
     env = &cpu->env;
 
-    reset_info = g_malloc0(sizeof(ResetData));
+    reset_info = g_new0(ResetData, 1);
     reset_info->cpu = cpu;
     reset_info->vector = env->active_tc.PC;
     qemu_register_reset(main_cpu_reset, reset_info);
target/mips/translate_init.c +2 -2
index 8bbded46c4..9778776677 100644
@@ -806,7 +806,7 @@ static void mmu_init (CPUMIPSState *env, const mips_def_t *def)
 {
     MIPSCPU *cpu = mips_env_get_cpu(env);
 
-    env->tlb = g_malloc0(sizeof(CPUMIPSTLBContext));
+    env->tlb = g_new0(CPUMIPSTLBContext, 1);
 
     switch (def->mmu_type) {
         case MMU_TYPE_NONE:
@@ -839,7 +839,7 @@ static void fpu_init (CPUMIPSState *env, const mips_def_t *def)
 
 static void mvp_init (CPUMIPSState *env, const mips_def_t *def)
 {
-    env->mvp = g_malloc0(sizeof(CPUMIPSMVPContext));
+    env->mvp = g_new0(CPUMIPSMVPContext, 1);
 
     /* MVPConf1 implemented, TLB sharable, no gating storage support,
        programmable cache partitioning implemented, number of allocatable
Signature · 1 line
2.14.2
#33 lore raw

PATCH 25/88 OpenRISC: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: squashed openrisc_sim.c]
---
 hw/openrisc/openrisc_sim.c | 2 +-
 target/openrisc/mmu.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/openrisc/openrisc_sim.c +1 -1
index 86bf2849c4..1eb381549c 100644
@@ -114,7 +114,7 @@ static void openrisc_sim_init(MachineState *machine)
         main_cpu_reset(cpu);
     }
 
-    ram = g_malloc(sizeof(*ram));
+    ram = g_new(MemoryRegion, 1);
     memory_region_init_ram(ram, NULL, "openrisc.ram", ram_size, &error_fatal);
     memory_region_add_subregion(get_system_memory(), 0, ram);
 
target/openrisc/mmu.c +1 -1
index ce2a29dd1a..4789a35b67 100644
@@ -247,7 +247,7 @@ hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
 
 void cpu_openrisc_mmu_init(OpenRISCCPU *cpu)
 {
-    cpu->env.tlb = g_malloc0(sizeof(CPUOpenRISCTLBContext));
+    cpu->env.tlb = g_new0(CPUOpenRISCTLBContext, 1);
 
     cpu->env.tlb->cpu_openrisc_map_address_code = &cpu_openrisc_get_phys_nommu;
     cpu->env.tlb->cpu_openrisc_map_address_data = &cpu_openrisc_get_phys_nommu;
Signature · 1 line
2.14.2
Acked-by on v1 25/88
#34 lore raw

Re: [Qemu-devel] [PATCH 25/88] OpenRISC: use g_new() family of functions

Quoted 4 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

Quoted 35 lines

[PMD: squashed openrisc_sim.c]

---
 hw/openrisc/openrisc_sim.c | 2 +-
 target/openrisc/mmu.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/openrisc/openrisc_sim.c +1 -1
index 86bf2849c4..1eb381549c 100644
@@ -114,7 +114,7 @@ static void openrisc_sim_init(MachineState *machine)
         main_cpu_reset(cpu);
     }
 
-    ram = g_malloc(sizeof(*ram));
+    ram = g_new(MemoryRegion, 1);
     memory_region_init_ram(ram, NULL, "openrisc.ram", ram_size, &error_fatal);
     memory_region_add_subregion(get_system_memory(), 0, ram);
 
target/openrisc/mmu.c +1 -1
index ce2a29dd1a..4789a35b67 100644
@@ -247,7 +247,7 @@ hwaddr openrisc_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
 
 void cpu_openrisc_mmu_init(OpenRISCCPU *cpu)
 {
-    cpu->env.tlb = g_malloc0(sizeof(CPUOpenRISCTLBContext));
+    cpu->env.tlb = g_new0(CPUOpenRISCTLBContext, 1);
 
     cpu->env.tlb->cpu_openrisc_map_address_code = &cpu_openrisc_get_phys_nommu;
     cpu->env.tlb->cpu_openrisc_map_address_data = &cpu_openrisc_get_phys_nommu;
Signature · 1 line
2.14.2
#35 lore raw

PATCH 26/88 S390: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: more changes in hw/s390x/css.c, added target/s390x/cpu_models.c]
---
 hw/s390x/css.c            | 10 +++++-----
 hw/s390x/s390-pci-bus.c   |  4 ++--
 target/s390x/cpu_models.c | 12 ++++++------
 target/s390x/diag.c       |  2 +-
 4 files changed, 14 insertions(+), 14 deletions(-)
hw/s390x/css.c +5 -5
index 35683d7954..b6d4fcaf06 100644
@@ -488,7 +488,7 @@ int css_create_css_image(uint8_t cssid, bool default_image)
     if (channel_subsys.css[cssid]) {
         return -EBUSY;
     }
-    channel_subsys.css[cssid] = g_malloc0(sizeof(CssImage));
+    channel_subsys.css[cssid] = g_new0(CssImage, 1);
     if (default_image) {
         channel_subsys.default_cssid = cssid;
     }
@@ -1778,7 +1778,7 @@ void css_undo_stcrw(CRW *crw)
 {
     CrwContainer *crw_cont;
 
-    crw_cont = g_try_malloc0(sizeof(CrwContainer));
+    crw_cont = g_try_new0(CrwContainer, 1);
     if (!crw_cont) {
         channel_subsys.crws_lost = true;
         return;
@@ -2185,7 +2185,7 @@ void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid,
     css = channel_subsys.css[cssid];
 
     if (!css->sch_set[ssid]) {
-        css->sch_set[ssid] = g_malloc0(sizeof(SubchSet));
+        css->sch_set[ssid] = g_new0(SubchSet, 1);
     }
     s_set = css->sch_set[ssid];
 
@@ -2206,7 +2206,7 @@ void css_queue_crw(uint8_t rsc, uint8_t erc, int solicited,
 
     trace_css_crw(rsc, erc, rsid, chain ? "(chained)" : "");
     /* TODO: Maybe use a static crw pool? */
-    crw_cont = g_try_malloc0(sizeof(CrwContainer));
+    crw_cont = g_try_new0(CrwContainer, 1);
     if (!crw_cont) {
         channel_subsys.crws_lost = true;
         return;
@@ -2498,7 +2498,7 @@ SubchDev *css_create_sch(CssDevId bus_id, bool is_virtual, bool squash_mcss,
         }
     }
 
-    sch = g_malloc0(sizeof(*sch));
+    sch = g_new0(SubchDev, 1);
     sch->cssid = bus_id.cssid;
     sch->ssid = bus_id.ssid;
     sch->devno = bus_id.devid;
hw/s390x/s390-pci-bus.c +2 -2
index 96116b7d1e..e7a58e81f7 100644
@@ -240,7 +240,7 @@ static void s390_pci_generate_event(uint8_t cc, uint16_t pec, uint32_t fh,
     SeiContainer *sei_cont;
     S390pciState *s = s390_get_phb();
 
-    sei_cont = g_malloc0(sizeof(SeiContainer));
+    sei_cont = g_new0(SeiContainer, 1);
     sei_cont->fh = fh;
     sei_cont->fid = fid;
     sei_cont->cc = cc;
@@ -416,7 +416,7 @@ static S390PCIIOMMU *s390_pci_get_iommu(S390pciState *s, PCIBus *bus,
     S390PCIIOMMU *iommu;
 
     if (!table) {
-        table = g_malloc0(sizeof(S390PCIIOMMUTable));
+        table = g_new0(S390PCIIOMMUTable, 1);
         table->key = key;
         g_hash_table_insert(s->iommu_table, &table->key, table);
     }
target/s390x/cpu_models.c +6 -6
index 07ef8a3b6e..8c2d8851ae 100644
@@ -392,7 +392,7 @@ static void create_cpu_model_list(ObjectClass *klass, void *opaque)
 
     /* strip off the -s390-cpu */
     g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0;
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(CpuDefinitionInfo, 1);
     info->name = name;
     info->has_migration_safe = true;
     info->migration_safe = scc->is_migration_safe;
@@ -412,7 +412,7 @@ static void create_cpu_model_list(ObjectClass *klass, void *opaque)
         object_unref(obj);
     }
 
-    entry = g_malloc0(sizeof(*entry));
+    entry = g_new0(CpuDefinitionInfoList, 1);
     entry->value = info;
     entry->next = *cpu_list;
     *cpu_list = entry;
@@ -574,7 +574,7 @@ CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type
     }
 
     /* convert it back to a static representation */
-    expansion_info = g_malloc0(sizeof(*expansion_info));
+    expansion_info = g_new0(CpuModelExpansionInfo, 1);
     expansion_info->model = g_malloc0(sizeof(*expansion_info->model));
     cpu_info_from_model(expansion_info->model, &s390_model, delta_changes);
     return expansion_info;
@@ -585,7 +585,7 @@ static void list_add_feat(const char *name, void *opaque)
     strList **last = (strList **) opaque;
     strList *entry;
 
-    entry = g_malloc0(sizeof(*entry));
+    entry = g_new0(strList, 1);
     entry->value = g_strdup(name);
     entry->next = *last;
     *last = entry;
@@ -609,7 +609,7 @@ CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *infoa,
     if (*errp) {
         return NULL;
     }
-    compare_info = g_malloc0(sizeof(*compare_info));
+    compare_info = g_new0(CpuModelCompareInfo, 1);
 
     /* check the cpu generation and ga level */
     if (modela.def->gen == modelb.def->gen) {
@@ -713,7 +713,7 @@ CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *infoa,
     bitmap_and(model.features, model.features, model.def->full_feat,
                S390_FEAT_MAX);
 
-    baseline_info = g_malloc0(sizeof(*baseline_info));
+    baseline_info = g_new0(CpuModelBaselineInfo, 1);
     baseline_info->model = g_malloc0(sizeof(*baseline_info->model));
     cpu_info_from_model(baseline_info->model, &model, true);
     return baseline_info;
target/s390x/diag.c +1 -1
index 82a623948d..dbbb9e886f 100644
@@ -144,7 +144,7 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3)
             program_interrupt(env, PGM_ADDRESSING, ILEN_AUTO);
             return;
         }
-        iplb = g_malloc0(sizeof(IplParameterBlock));
+        iplb = g_new0(IplParameterBlock, 1);
         cpu_physical_memory_read(addr, iplb, sizeof(iplb->len));
         if (!iplb_valid_len(iplb)) {
             env->regs[r1 + 1] = DIAG_308_RC_INVALID;
Signature · 1 line
2.14.2
Acked-by on v1 26/88
#36 lore raw

Re: [Qemu-devel] [PATCH 26/88] S390: use g_new() family of functions

Quoted 11 lines · On Fri, 6 Oct 2017 20:49:21 -0300 Philippe Mathieu-Daudé <[email protected]>…

From: Marc-André Lureau <[email protected]>

[PMD: more changes in hw/s390x/css.c, added target/s390x/cpu_models.c]
---
 hw/s390x/css.c            | 10 +++++-----
 hw/s390x/s390-pci-bus.c   |  4 ++--
 target/s390x/cpu_models.c | 12 ++++++------
 target/s390x/diag.c       |  2 +-
 4 files changed, 14 insertions(+), 14 deletions(-)

I think I'll just queue that on s390-next.

In case somebody wants to take the whole patchset after all,

#37 lore raw

Re: [Qemu-devel] [PATCH 26/88] S390: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · On Fri, 6 Oct 2017 20:49:21 -0300 Philippe Mathieu-Daudé <[email protected]>…

From: Marc-André Lureau <[email protected]>

[PMD: more changes in hw/s390x/css.c, added target/s390x/cpu_models.c]
---
 hw/s390x/css.c            | 10 +++++-----
 hw/s390x/s390-pci-bus.c   |  4 ++--
 target/s390x/cpu_models.c | 12 ++++++------
 target/s390x/diag.c       |  2 +-
 4 files changed, 14 insertions(+), 14 deletions(-)

Thanks, applied.

#38 lore raw

PATCH 27/88 SH4: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 hw/sh4/r2d.c        | 4 ++--
 hw/sh4/sh7750.c     | 2 +-
 hw/timer/sh_timer.c | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
hw/sh4/r2d.c +2 -2
index 16b9ed2db2..92d1fb99d7 100644
@@ -186,7 +186,7 @@ static qemu_irq *r2d_fpga_init(MemoryRegion *sysmem,
 {
     r2d_fpga_t *s;
 
-    s = g_malloc0(sizeof(r2d_fpga_t));
+    s = g_new0(r2d_fpga_t, 1);
 
     s->irl = irl;
 
@@ -249,7 +249,7 @@ static void r2d_init(MachineState *machine)
     cpu = SUPERH_CPU(cpu_generic_init(TYPE_SUPERH_CPU, cpu_model));
     env = &cpu->env;
 
-    reset_info = g_malloc0(sizeof(ResetData));
+    reset_info = g_new0(ResetData, 1);
     reset_info->cpu = cpu;
     reset_info->vector = env->pc;
     qemu_register_reset(main_cpu_reset, reset_info);
hw/sh4/sh7750.c +1 -1
index 166e4bd947..49c49c110b 100644
@@ -728,7 +728,7 @@ SH7750State *sh7750_init(SuperHCPU *cpu, MemoryRegion *sysmem)
 {
     SH7750State *s;
 
-    s = g_malloc0(sizeof(SH7750State));
+    s = g_new0(SH7750State, 1);
     s->cpu = cpu;
     s->periph_freq = 60000000;	/* 60MHz */
     memory_region_init_io(&s->iomem, NULL, &sh7750_mem_ops, s,
hw/timer/sh_timer.c +2 -2
index 9afb2d048c..46f3eb9647 100644
@@ -192,7 +192,7 @@ static void *sh_timer_init(uint32_t freq, int feat, qemu_irq irq)
     sh_timer_state *s;
     QEMUBH *bh;
 
-    s = (sh_timer_state *)g_malloc0(sizeof(sh_timer_state));
+    s = g_new0(sh_timer_state, 1);
     s->freq = freq;
     s->feat = feat;
     s->tcor = 0xffffffff;
@@ -313,7 +313,7 @@ void tmu012_init(MemoryRegion *sysmem, hwaddr base,
     tmu012_state *s;
     int timer_feat = (feat & TMU012_FEAT_EXTCLK) ? TIMER_FEAT_EXTCLK : 0;
 
-    s = (tmu012_state *)g_malloc0(sizeof(tmu012_state));
+    s = g_new0(tmu012_state, 1);
     s->feat = feat;
     s->timer[0] = sh_timer_init(freq, timer_feat, ch0_irq);
     s->timer[1] = sh_timer_init(freq, timer_feat, ch1_irq);
Signature · 1 line
2.14.2
#39 lore raw

PATCH 28/88 disas: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: fixed const cast, squashed M68K + NiosII + SPARC, renamed subject "disas"]
---
 disas/m68k.c  | 3 +--
 disas/nios2.c | 3 +--
 disas/sparc.c | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)
disas/m68k.c +1 -2
index 61b689ef3e..31cf6ea5f9 100644
@@ -1886,8 +1886,7 @@ print_insn_m68k (bfd_vma memaddr, disassemble_info *info)
 
       /* Then create a sorted table of pointers
 	 that point into the unsorted table.  */
-      opc_pointer[0] = malloc (sizeof (struct m68k_opcode *)
-                               * m68k_numopcodes);
+      opc_pointer[0] = g_new(const struct m68k_opcode *, m68k_numopcodes);
       opcodes[0] = opc_pointer[0];
 
       for (i = 1; i < 16; i++)
disas/nios2.c +1 -2
index b342936d21..9e6e1e6a1f 100644
@@ -2625,8 +2625,7 @@ nios2_init_opcode_hash (nios2_disassembler_state *state)
 
 	if (bucket)
 	  {
-	    new_hash =
-	      (nios2_opcode_hash *) malloc (sizeof (nios2_opcode_hash));
+	    new_hash = g_new(nios2_opcode_hash, 1);
 	    if (new_hash == NULL)
 	      {
 		fprintf (stderr,
disas/sparc.c +1 -2
index f120f4e86d..6d0adab8a7 100644
@@ -2684,8 +2684,7 @@ print_insn_sparc (bfd_vma memaddr, disassemble_info *info)
       current_arch_mask = compute_arch_mask (info->mach);
 
       if (!opcodes_initialized)
-        sorted_opcodes =
-          malloc (sparc_num_opcodes * sizeof (sparc_opcode *));
+        sorted_opcodes = g_new(const sparc_opcode *, sparc_num_opcodes);
       /* Reset the sorted table so we can resort it.  */
       for (i = 0; i < sparc_num_opcodes; ++i)
         sorted_opcodes[i] = &sparc_opcodes[i];
Signature · 1 line
2.14.2
#40 lore raw

PATCH 29/88 SPARC: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: split of disas/sparc.c change]
---
 hw/sparc/leon3.c     | 2 +-
 hw/sparc64/sparc64.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/sparc/leon3.c +1 -1
index ec2816bf94..05e7adefb8 100644
@@ -132,7 +132,7 @@ static void leon3_generic_hw_init(MachineState *machine)
     cpu_sparc_set_id(env, 0);
 
     /* Reset data */
-    reset_info        = g_malloc0(sizeof(ResetData));
+    reset_info        = g_new0(ResetData, 1);
     reset_info->cpu   = cpu;
     reset_info->sp    = 0x40000000 + ram_size;
     qemu_register_reset(main_cpu_reset, reset_info);
hw/sparc64/sparc64.c +2 -2
index 097d529ff1..6f2197fc13 100644
@@ -160,7 +160,7 @@ static CPUTimer *cpu_timer_create(const char *name, SPARCCPU *cpu,
                                   QEMUBHFunc *cb, uint32_t frequency,
                                   uint64_t disabled_mask, uint64_t npt_mask)
 {
-    CPUTimer *timer = g_malloc0(sizeof(CPUTimer));
+    CPUTimer *timer = g_new0(CPUTimer, 1);
 
     timer->name = name;
     timer->frequency = frequency;
@@ -368,7 +368,7 @@ SPARCCPU *sparc64_cpu_devinit(const char *cpu_model,
                                     hstick_frequency, TICK_INT_DIS,
                                     TICK_NPT_MASK);
 
-    reset_info = g_malloc0(sizeof(ResetData));
+    reset_info = g_new0(ResetData, 1);
     reset_info->cpu = cpu;
     reset_info->prom_addr = prom_addr;
     qemu_register_reset(main_cpu_reset, reset_info);
Signature · 1 line
2.14.2
#41 lore raw

PATCH 30/88 QEMU Guest Agent: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: added qga/commands-posix.c and qga/commands-win32.c]
---
 qga/commands-posix.c | 20 ++++++++++----------
 qga/commands-win32.c | 12 ++++++------
 qga/commands.c       |  2 +-
 3 files changed, 17 insertions(+), 17 deletions(-)
qga/commands-posix.c +10 -10
index ab0c63d931..3a4deb6ae0 100644
@@ -906,16 +906,16 @@ static void build_guest_fsinfo_for_real_device(char const *syspath,
         }
     }
 
-    pciaddr = g_malloc0(sizeof(*pciaddr));
+    pciaddr = g_new0(GuestPCIAddress, 1);
     pciaddr->domain = pci[0];
     pciaddr->bus = pci[1];
     pciaddr->slot = pci[2];
     pciaddr->function = pci[3];
 
-    disk = g_malloc0(sizeof(*disk));
+    disk = g_new0(GuestDiskAddress, 1);
     disk->pci_controller = pciaddr;
 
-    list = g_malloc0(sizeof(*list));
+    list = g_new0(GuestDiskAddressList, 1);
     list->value = disk;
 
     if (strcmp(driver, "ata_piix") == 0) {
@@ -1380,7 +1380,7 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp)
         return NULL;
     }
 
-    response = g_malloc0(sizeof(*response));
+    response = g_new0(GuestFilesystemTrimResponse, 1);
 
     QTAILQ_FOREACH(mount, &mounts, next) {
         result = g_malloc0(sizeof(*result));
@@ -1897,12 +1897,12 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
         GuestLogicalProcessor *vcpu;
         GuestLogicalProcessorList *entry;
 
-        vcpu = g_malloc0(sizeof *vcpu);
+        vcpu = g_new0(GuestLogicalProcessor, 1);
         vcpu->logical_id = current++;
         vcpu->has_can_offline = true; /* lolspeak ftw */
         transfer_vcpu(vcpu, true, &local_err);
 
-        entry = g_malloc0(sizeof *entry);
+        entry = g_new0(GuestLogicalProcessorList, 1);
         entry->value = vcpu;
 
         *link = entry;
@@ -2267,13 +2267,13 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp)
             continue;
         }
 
-        mem_blk = g_malloc0(sizeof *mem_blk);
+        mem_blk = g_new0(GuestMemoryBlock, 1);
         /* The d_name is "memoryXXX",  phys_index is block id, same as XXX */
         mem_blk->phys_index = strtoul(&de->d_name[6], NULL, 10);
         mem_blk->has_can_offline = true; /* lolspeak ftw */
         transfer_memory_block(mem_blk, true, NULL, &local_err);
 
-        entry = g_malloc0(sizeof *entry);
+        entry = g_new0(GuestMemoryBlockList, 1);
         entry->value = mem_blk;
 
         *link = entry;
@@ -2308,13 +2308,13 @@ qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks, Error **errp)
         GuestMemoryBlockResponseList *entry;
         GuestMemoryBlock *current_mem_blk = mem_blks->value;
 
-        result = g_malloc0(sizeof(*result));
+        result = g_new0(GuestMemoryBlockResponse, 1);
         result->phys_index = current_mem_blk->phys_index;
         transfer_memory_block(current_mem_blk, false, result, &local_err);
         if (local_err) { /* should never happen */
             goto err;
         }
-        entry = g_malloc0(sizeof *entry);
+        entry = g_new0(GuestMemoryBlockResponseList, 1);
         entry->value = result;
 
         *link = entry;
qga/commands-win32.c +6 -6
index 619dbd2bc2..908f110b8b 100644
@@ -617,7 +617,7 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
         goto out_close;
     }
 
-    disk = g_malloc0(sizeof(*disk));
+    disk = g_new0(GuestDiskAddress, 1);
     disk->bus_type = find_bus_type(bus);
     if (bus == BusTypeScsi || bus == BusTypeAta || bus == BusTypeRAID
 #if (_WIN32_WINNT >= 0x0600)
@@ -641,7 +641,7 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
          disk->pci_controller = NULL;
     }
 
-    list = g_malloc0(sizeof(*list));
+    list = g_new0(GuestDiskAddressList, 1);
     list->value = disk;
     list->next = NULL;
 out_close:
@@ -694,7 +694,7 @@ static GuestFilesystemInfo *build_guest_fsinfo(char *guid, Error **errp)
     }
 
     fs_name[sizeof(fs_name) - 1] = 0;
-    fs = g_malloc(sizeof(*fs));
+    fs = g_new(GuestFilesystemInfo, 1);
     fs->name = g_strdup(guid);
     if (len == 0) {
         fs->mountpoint = g_strdup("System Reserved");
@@ -877,7 +877,7 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp)
             continue;
         }
 
-        uc_path = g_malloc(sizeof(WCHAR) * char_count);
+        uc_path = g_new(WCHAR, char_count);
         if (!GetVolumePathNamesForVolumeNameW(guid, uc_path, char_count,
                                               &char_count) || !*uc_path) {
             /* strange, but this condition could be faced even with size == 2 */
@@ -1348,12 +1348,12 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
                     GuestLogicalProcessor *vcpu;
                     GuestLogicalProcessorList *entry;
 
-                    vcpu = g_malloc0(sizeof *vcpu);
+                    vcpu = g_new0(GuestLogicalProcessor, 1);
                     vcpu->logical_id = current++;
                     vcpu->online = true;
                     vcpu->has_can_offline = true;
 
-                    entry = g_malloc0(sizeof *entry);
+                    entry = g_new0(GuestLogicalProcessorList, 1);
                     entry->value = vcpu;
 
                     *link = entry;
qga/commands.c +1 -1
index ff89e805cf..d4c78ac935 100644
@@ -239,7 +239,7 @@ static char **guest_exec_get_args(const strList *entry, bool log)
 
     str = g_malloc(str_size);
     *str = 0;
-    args = g_malloc(count * sizeof(char *));
+    args = g_new(char *, count);
     for (it = entry; it != NULL; it = it->next) {
         args[i++] = it->value;
         pstrcat(str, str_size, it->value);
Signature · 1 line
2.14.2
#42 lore raw

PATCH 31/88 QMP: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 monitor.c                 | 14 +++++++-------
 qmp.c                     | 14 +++++++-------
 tests/test-qmp-commands.c | 14 +++++++-------
 3 files changed, 21 insertions(+), 21 deletions(-)
monitor.c +7 -7
index fe0d1bdbb4..ea6a485f11 100644
@@ -906,7 +906,7 @@ static void query_commands_cb(QmpCommand *cmd, void *opaque)
         return;
     }
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(CommandInfoList, 1);
     info->value = g_malloc0(sizeof(*info->value));
     info->value->name = g_strdup(cmd->name);
     info->next = *list;
@@ -1799,7 +1799,7 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
     int nchannels = qdict_get_try_int(qdict, "nchannels", -1);
     CaptureState *s;
 
-    s = g_malloc0 (sizeof (*s));
+    s = g_new0(CaptureState, 1);
 
     freq = has_freq ? freq : 44100;
     bits = has_bits ? bits : 16;
@@ -1947,7 +1947,7 @@ void qmp_getfd(const char *fdname, Error **errp)
         return;
     }
 
-    monfd = g_malloc0(sizeof(mon_fd_t));
+    monfd = g_new0(mon_fd_t, 1);
     monfd->name = g_strdup(fdname);
     monfd->fd = fd;
 
@@ -2110,7 +2110,7 @@ FdsetInfoList *qmp_query_fdsets(Error **errp)
         QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) {
             FdsetFdInfoList *fdsetfd_info;
 
-            fdsetfd_info = g_malloc0(sizeof(*fdsetfd_info));
+            fdsetfd_info = g_new0(FdsetFdInfoList, 1);
             fdsetfd_info->value = g_malloc0(sizeof(*fdsetfd_info->value));
             fdsetfd_info->value->fd = mon_fdset_fd->fd;
             if (mon_fdset_fd->opaque) {
@@ -2199,7 +2199,7 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
         }
     }
 
-    mon_fdset_fd = g_malloc0(sizeof(*mon_fdset_fd));
+    mon_fdset_fd = g_new0(MonFdsetFd, 1);
     mon_fdset_fd->fd = fd;
     mon_fdset_fd->removed = false;
     if (has_opaque) {
@@ -2207,7 +2207,7 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
     }
     QLIST_INSERT_HEAD(&mon_fdset->fds, mon_fdset_fd, next);
 
-    fdinfo = g_malloc0(sizeof(*fdinfo));
+    fdinfo = g_new0(AddfdInfo, 1);
     fdinfo->fdset_id = mon_fdset->id;
     fdinfo->fd = mon_fdset_fd->fd;
 
@@ -4102,7 +4102,7 @@ void monitor_init(Chardev *chr, int flags)
         is_first_init = 0;
     }
 
-    mon = g_malloc(sizeof(*mon));
+    mon = g_new(Monitor, 1);
     monitor_data_init(mon);
 
     qemu_chr_fe_init(&mon->chr, chr, &error_abort);
qmp.c +7 -7
index e8c303116a..e965020e37 100644
@@ -232,7 +232,7 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
     while ((prop = object_property_iter_next(&iter))) {
         ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
 
-        entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
+        entry->value = g_new0(ObjectPropertyInfo, 1);
         entry->next = props;
         props = entry;
 
@@ -432,7 +432,7 @@ static void qom_list_types_tramp(ObjectClass *klass, void *data)
     ObjectTypeInfo *info;
     ObjectClass *parent = object_class_get_parent(klass);
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(ObjectTypeInfo, 1);
     info->name = g_strdup(object_class_get_name(klass));
     info->has_abstract = info->abstract = object_class_is_abstract(klass);
     if (parent) {
@@ -440,7 +440,7 @@ static void qom_list_types_tramp(ObjectClass *klass, void *data)
         info->parent = g_strdup(object_class_get_name(parent));
     }
 
-    e = g_malloc0(sizeof(*e));
+    e = g_new0(ObjectTypeInfoList, 1);
     e->value = info;
     e->next = *pret;
     *pret = e;
@@ -490,7 +490,7 @@ static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
                 return NULL;           /* no way to set it, don't show */
             }
 
-            info = g_malloc0(sizeof(*info));
+            info = g_new0(DevicePropertyInfo, 1);
             info->name = g_strdup(prop->name);
             info->type = default_type ? g_strdup(default_type)
                                       : g_strdup(prop->info->name);
@@ -502,7 +502,7 @@ static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
     } while (klass != object_class_by_name(TYPE_DEVICE));
 
     /* Not a qdev property, use the default type */
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(DevicePropertyInfo, 1);
     info->name = g_strdup(name);
     info->type = g_strdup(default_type);
     info->has_description = !!description;
@@ -568,7 +568,7 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
             continue;
         }
 
-        entry = g_malloc0(sizeof(*entry));
+        entry = g_new0(DevicePropertyInfoList, 1);
         entry->value = info;
         entry->next = prop_list;
         prop_list = entry;
@@ -712,7 +712,7 @@ ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
 
 MemoryInfo *qmp_query_memory_size_summary(Error **errp)
 {
-    MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo));
+    MemoryInfo *mem_info = g_new0(MemoryInfo, 1);
 
     mem_info->base_memory = ram_size;
 
tests/test-qmp-commands.c +7 -7
index 904c89d4d4..e715c45a23 100644
@@ -28,8 +28,8 @@ UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a,
                               Error **errp)
 {
     UserDefTwo *ret;
-    UserDefOne *ud1c = g_malloc0(sizeof(UserDefOne));
-    UserDefOne *ud1d = g_malloc0(sizeof(UserDefOne));
+    UserDefOne *ud1c = g_new0(UserDefOne, 1);
+    UserDefOne *ud1d = g_new0(UserDefOne, 1);
 
     ud1c->string = strdup(ud1a->string);
     ud1c->integer = ud1a->integer;
@@ -209,23 +209,23 @@ static void test_dealloc_types(void)
     UserDefOne *ud1test, *ud1a, *ud1b;
     UserDefOneList *ud1list;
 
-    ud1test = g_malloc0(sizeof(UserDefOne));
+    ud1test = g_new0(UserDefOne, 1);
     ud1test->integer = 42;
     ud1test->string = g_strdup("hi there 42");
 
     qapi_free_UserDefOne(ud1test);
 
-    ud1a = g_malloc0(sizeof(UserDefOne));
+    ud1a = g_new0(UserDefOne, 1);
     ud1a->integer = 43;
     ud1a->string = g_strdup("hi there 43");
 
-    ud1b = g_malloc0(sizeof(UserDefOne));
+    ud1b = g_new0(UserDefOne, 1);
     ud1b->integer = 44;
     ud1b->string = g_strdup("hi there 44");
 
-    ud1list = g_malloc0(sizeof(UserDefOneList));
+    ud1list = g_new0(UserDefOneList, 1);
     ud1list->value = ud1a;
-    ud1list->next = g_malloc0(sizeof(UserDefOneList));
+    ud1list->next = g_new0(UserDefOneList, 1);
     ud1list->next->value = ud1b;
 
     qapi_free_UserDefOneList(ud1list);
Signature · 1 line
2.14.2
#43 lore raw

Re: [Qemu-devel] [PATCH 31/88] QMP: use g_new() family of functions

Quoted 16 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 monitor.c                 | 14 +++++++-------
 qmp.c                     | 14 +++++++-------
 tests/test-qmp-commands.c | 14 +++++++-------
 3 files changed, 21 insertions(+), 21 deletions(-)
monitor.c +0 -0
index fe0d1bdbb4..ea6a485f11 100644

monitor.c static void query_commands_cb(QmpCommand *cmd, void *opaque) · line 912

Quoted 8 lines
monitor.c +1 -1
@@ -906,7 +906,7 @@ static void query_commands_cb(QmpCommand *cmd, void *opaque)
         return;
     }
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(CommandInfoList, 1);
     info->value = g_malloc0(sizeof(*info->value));
     info->value->name = g_strdup(cmd->name);
     info->next = *list;

I'm not convinced rewriting

       LHS = g_malloc(sizeof(*LHS));

to

       LHS = g_new(T, 1);

where T is the type of LHS is worth the trouble. The code before the rewrite is pretty idiomatic. There's no possibility of integer overflow g_new() could avoid. The types are obviously correct, so the additional type checking is quite unlikely to catch anything. That leaves the consistency argument. I'm willing to hear it, but I feel it should be heard in a patch series that does nothing else.

monitor.c static void hmp_wavcapture(Monitor *mon, const QDict *qdict) · line 1805

Quoted 9 lines
monitor.c +1 -1
@@ -1799,7 +1799,7 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
     int nchannels = qdict_get_try_int(qdict, "nchannels", -1);
     CaptureState *s;
 
-    s = g_malloc0 (sizeof (*s));
+    s = g_new0(CaptureState, 1);
 
     freq = has_freq ? freq : 44100;
     bits = has_bits ? bits : 16;

This hunk is HMP, not QMP.

Quoted 37 lines
monitor.c +4 -4
@@ -1947,7 +1947,7 @@ void qmp_getfd(const char *fdname, Error **errp)
         return;
     }
 
-    monfd = g_malloc0(sizeof(mon_fd_t));
+    monfd = g_new0(mon_fd_t, 1);
     monfd->name = g_strdup(fdname);
     monfd->fd = fd;
 
@@ -2110,7 +2110,7 @@ FdsetInfoList *qmp_query_fdsets(Error **errp)
         QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) {
             FdsetFdInfoList *fdsetfd_info;
 
-            fdsetfd_info = g_malloc0(sizeof(*fdsetfd_info));
+            fdsetfd_info = g_new0(FdsetFdInfoList, 1);
             fdsetfd_info->value = g_malloc0(sizeof(*fdsetfd_info->value));
             fdsetfd_info->value->fd = mon_fdset_fd->fd;
             if (mon_fdset_fd->opaque) {
@@ -2199,7 +2199,7 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
         }
     }
 
-    mon_fdset_fd = g_malloc0(sizeof(*mon_fdset_fd));
+    mon_fdset_fd = g_new0(MonFdsetFd, 1);
     mon_fdset_fd->fd = fd;
     mon_fdset_fd->removed = false;
     if (has_opaque) {
@@ -2207,7 +2207,7 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
     }
     QLIST_INSERT_HEAD(&mon_fdset->fds, mon_fdset_fd, next);
 
-    fdinfo = g_malloc0(sizeof(*fdinfo));
+    fdinfo = g_new0(AddfdInfo, 1);
     fdinfo->fdset_id = mon_fdset->id;
     fdinfo->fd = mon_fdset_fd->fd;
 

monitor.c void monitor_init(Chardev *chr, int flags) · line 4108

Quoted 8 lines
monitor.c +1 -1
@@ -4102,7 +4102,7 @@ void monitor_init(Chardev *chr, int flags)
         is_first_init = 0;
     }
 
-    mon = g_malloc(sizeof(*mon));
+    mon = g_new(Monitor, 1);
     monitor_data_init(mon);
 
     qemu_chr_fe_init(&mon->chr, chr, &error_abort);

This is monitor core, not QMP.

Quoted 101 lines
qmp.c +7 -7
index e8c303116a..e965020e37 100644
@@ -232,7 +232,7 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
     while ((prop = object_property_iter_next(&iter))) {
         ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
 
-        entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
+        entry->value = g_new0(ObjectPropertyInfo, 1);
         entry->next = props;
         props = entry;
 
@@ -432,7 +432,7 @@ static void qom_list_types_tramp(ObjectClass *klass, void *data)
     ObjectTypeInfo *info;
     ObjectClass *parent = object_class_get_parent(klass);
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(ObjectTypeInfo, 1);
     info->name = g_strdup(object_class_get_name(klass));
     info->has_abstract = info->abstract = object_class_is_abstract(klass);
     if (parent) {
@@ -440,7 +440,7 @@ static void qom_list_types_tramp(ObjectClass *klass, void *data)
         info->parent = g_strdup(object_class_get_name(parent));
     }
 
-    e = g_malloc0(sizeof(*e));
+    e = g_new0(ObjectTypeInfoList, 1);
     e->value = info;
     e->next = *pret;
     *pret = e;
@@ -490,7 +490,7 @@ static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
                 return NULL;           /* no way to set it, don't show */
             }
 
-            info = g_malloc0(sizeof(*info));
+            info = g_new0(DevicePropertyInfo, 1);
             info->name = g_strdup(prop->name);
             info->type = default_type ? g_strdup(default_type)
                                       : g_strdup(prop->info->name);
@@ -502,7 +502,7 @@ static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
     } while (klass != object_class_by_name(TYPE_DEVICE));
 
     /* Not a qdev property, use the default type */
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(DevicePropertyInfo, 1);
     info->name = g_strdup(name);
     info->type = g_strdup(default_type);
     info->has_description = !!description;
@@ -568,7 +568,7 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
             continue;
         }
 
-        entry = g_malloc0(sizeof(*entry));
+        entry = g_new0(DevicePropertyInfoList, 1);
         entry->value = info;
         entry->next = prop_list;
         prop_list = entry;
@@ -712,7 +712,7 @@ ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
 
 MemoryInfo *qmp_query_memory_size_summary(Error **errp)
 {
-    MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo));
+    MemoryInfo *mem_info = g_new0(MemoryInfo, 1);
 
     mem_info->base_memory = ram_size;
 
tests/test-qmp-commands.c +5 -5
index 904c89d4d4..e715c45a23 100644
@@ -28,8 +28,8 @@ UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a,
                               Error **errp)
 {
     UserDefTwo *ret;
-    UserDefOne *ud1c = g_malloc0(sizeof(UserDefOne));
-    UserDefOne *ud1d = g_malloc0(sizeof(UserDefOne));
+    UserDefOne *ud1c = g_new0(UserDefOne, 1);
+    UserDefOne *ud1d = g_new0(UserDefOne, 1);
 
     ud1c->string = strdup(ud1a->string);
     ud1c->integer = ud1a->integer;
@@ -209,23 +209,23 @@ static void test_dealloc_types(void)
     UserDefOne *ud1test, *ud1a, *ud1b;
     UserDefOneList *ud1list;
 
-    ud1test = g_malloc0(sizeof(UserDefOne));
+    ud1test = g_new0(UserDefOne, 1);
     ud1test->integer = 42;
     ud1test->string = g_strdup("hi there 42");
 
     qapi_free_UserDefOne(ud1test);
 
-    ud1a = g_malloc0(sizeof(UserDefOne));
+    ud1a = g_new0(UserDefOne, 1);
     ud1a->integer = 43;
     ud1a->string = g_strdup("hi there 43");
 
-    ud1b = g_malloc0(sizeof(UserDefOne));
+    ud1b = g_new0(UserDefOne, 1);
     ud1b->integer = 44;

tests/test-qmp-commands.c static void test_dealloc_types(void) · line 231

Quoted 10 lines
tests/test-qmp-commands.c +2 -2
     ud1b->string = g_strdup("hi there 44");
 
-    ud1list = g_malloc0(sizeof(UserDefOneList));
+    ud1list = g_new0(UserDefOneList, 1);
     ud1list->value = ud1a;
-    ud1list->next = g_malloc0(sizeof(UserDefOneList));
+    ud1list->next = g_new0(UserDefOneList, 1);
     ud1list->next->value = ud1b;
 
     qapi_free_UserDefOneList(ud1list);

Could squash together with PATCH 79 and call the result "monitor: Use g_new() family of functions".

#44 lore raw

Re: [Qemu-devel] [PATCH 31/88] QMP: use g_new() family of functions

Quoted 33 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 16 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 monitor.c                 | 14 +++++++-------
 qmp.c                     | 14 +++++++-------
 tests/test-qmp-commands.c | 14 +++++++-------
 3 files changed, 21 insertions(+), 21 deletions(-)
monitor.c +0 -0
index fe0d1bdbb4..ea6a485f11 100644

monitor.c static void query_commands_cb(QmpCommand *cmd, void *opaque) · line 912

Quoted 8 lines
monitor.c +1 -1
@@ -906,7 +906,7 @@ static void query_commands_cb(QmpCommand *cmd, void *opaque)
         return;
     }
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(CommandInfoList, 1);
     info->value = g_malloc0(sizeof(*info->value));
     info->value->name = g_strdup(cmd->name);
     info->next = *list;

I'm not convinced rewriting

       LHS = g_malloc(sizeof(*LHS));

to

Quoted 8 lines
       LHS = g_new(T, 1);

where T is the type of LHS is worth the trouble. The code before the rewrite is pretty idiomatic. There's no possibility of integer overflow g_new() could avoid. The types are obviously correct, so the additional type checking is quite unlikely to catch anything. That leaves the consistency argument. I'm willing to hear it, but I feel it should be heard in a patch series that does nothing else.

The 'obviously correct' is the dodgy part of the argument here. How many bugs do we right that are obviously wrong?

t.c:13:20: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]

     struct c *pc = g_new(struct b, 1);

seems good to me.

Dave

Quoted 170 lines

monitor.c static void hmp_wavcapture(Monitor *mon, const QDict *qdict) · line 1805

Quoted 9 lines
monitor.c +1 -1
@@ -1799,7 +1799,7 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
     int nchannels = qdict_get_try_int(qdict, "nchannels", -1);
     CaptureState *s;
 
-    s = g_malloc0 (sizeof (*s));
+    s = g_new0(CaptureState, 1);
 
     freq = has_freq ? freq : 44100;
     bits = has_bits ? bits : 16;

This hunk is HMP, not QMP.

Quoted 37 lines
monitor.c +4 -4
@@ -1947,7 +1947,7 @@ void qmp_getfd(const char *fdname, Error **errp)
         return;
     }
 
-    monfd = g_malloc0(sizeof(mon_fd_t));
+    monfd = g_new0(mon_fd_t, 1);
     monfd->name = g_strdup(fdname);
     monfd->fd = fd;
 
@@ -2110,7 +2110,7 @@ FdsetInfoList *qmp_query_fdsets(Error **errp)
         QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) {
             FdsetFdInfoList *fdsetfd_info;
 
-            fdsetfd_info = g_malloc0(sizeof(*fdsetfd_info));
+            fdsetfd_info = g_new0(FdsetFdInfoList, 1);
             fdsetfd_info->value = g_malloc0(sizeof(*fdsetfd_info->value));
             fdsetfd_info->value->fd = mon_fdset_fd->fd;
             if (mon_fdset_fd->opaque) {
@@ -2199,7 +2199,7 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
         }
     }
 
-    mon_fdset_fd = g_malloc0(sizeof(*mon_fdset_fd));
+    mon_fdset_fd = g_new0(MonFdsetFd, 1);
     mon_fdset_fd->fd = fd;
     mon_fdset_fd->removed = false;
     if (has_opaque) {
@@ -2207,7 +2207,7 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
     }
     QLIST_INSERT_HEAD(&mon_fdset->fds, mon_fdset_fd, next);
 
-    fdinfo = g_malloc0(sizeof(*fdinfo));
+    fdinfo = g_new0(AddfdInfo, 1);
     fdinfo->fdset_id = mon_fdset->id;
     fdinfo->fd = mon_fdset_fd->fd;
 

monitor.c void monitor_init(Chardev *chr, int flags) · line 4108

Quoted 8 lines
monitor.c +1 -1
@@ -4102,7 +4102,7 @@ void monitor_init(Chardev *chr, int flags)
         is_first_init = 0;
     }
 
-    mon = g_malloc(sizeof(*mon));
+    mon = g_new(Monitor, 1);
     monitor_data_init(mon);
 
     qemu_chr_fe_init(&mon->chr, chr, &error_abort);

This is monitor core, not QMP.

Quoted 110 lines
qmp.c +7 -7
index e8c303116a..e965020e37 100644
@@ -232,7 +232,7 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
     while ((prop = object_property_iter_next(&iter))) {
         ObjectPropertyInfoList *entry = g_malloc0(sizeof(*entry));
 
-        entry->value = g_malloc0(sizeof(ObjectPropertyInfo));
+        entry->value = g_new0(ObjectPropertyInfo, 1);
         entry->next = props;
         props = entry;
 
@@ -432,7 +432,7 @@ static void qom_list_types_tramp(ObjectClass *klass, void *data)
     ObjectTypeInfo *info;
     ObjectClass *parent = object_class_get_parent(klass);
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(ObjectTypeInfo, 1);
     info->name = g_strdup(object_class_get_name(klass));
     info->has_abstract = info->abstract = object_class_is_abstract(klass);
     if (parent) {
@@ -440,7 +440,7 @@ static void qom_list_types_tramp(ObjectClass *klass, void *data)
         info->parent = g_strdup(object_class_get_name(parent));
     }
 
-    e = g_malloc0(sizeof(*e));
+    e = g_new0(ObjectTypeInfoList, 1);
     e->value = info;
     e->next = *pret;
     *pret = e;
@@ -490,7 +490,7 @@ static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
                 return NULL;           /* no way to set it, don't show */
             }
 
-            info = g_malloc0(sizeof(*info));
+            info = g_new0(DevicePropertyInfo, 1);
             info->name = g_strdup(prop->name);
             info->type = default_type ? g_strdup(default_type)
                                       : g_strdup(prop->info->name);
@@ -502,7 +502,7 @@ static DevicePropertyInfo *make_device_property_info(ObjectClass *klass,
     } while (klass != object_class_by_name(TYPE_DEVICE));
 
     /* Not a qdev property, use the default type */
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(DevicePropertyInfo, 1);
     info->name = g_strdup(name);
     info->type = g_strdup(default_type);
     info->has_description = !!description;
@@ -568,7 +568,7 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
             continue;
         }
 
-        entry = g_malloc0(sizeof(*entry));
+        entry = g_new0(DevicePropertyInfoList, 1);
         entry->value = info;
         entry->next = prop_list;
         prop_list = entry;
@@ -712,7 +712,7 @@ ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
 
 MemoryInfo *qmp_query_memory_size_summary(Error **errp)
 {
-    MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo));
+    MemoryInfo *mem_info = g_new0(MemoryInfo, 1);
 
     mem_info->base_memory = ram_size;
 
tests/test-qmp-commands.c +7 -7
index 904c89d4d4..e715c45a23 100644
@@ -28,8 +28,8 @@ UserDefTwo *qmp_user_def_cmd2(UserDefOne *ud1a,
                               Error **errp)
 {
     UserDefTwo *ret;
-    UserDefOne *ud1c = g_malloc0(sizeof(UserDefOne));
-    UserDefOne *ud1d = g_malloc0(sizeof(UserDefOne));
+    UserDefOne *ud1c = g_new0(UserDefOne, 1);
+    UserDefOne *ud1d = g_new0(UserDefOne, 1);
 
     ud1c->string = strdup(ud1a->string);
     ud1c->integer = ud1a->integer;
@@ -209,23 +209,23 @@ static void test_dealloc_types(void)
     UserDefOne *ud1test, *ud1a, *ud1b;
     UserDefOneList *ud1list;
 
-    ud1test = g_malloc0(sizeof(UserDefOne));
+    ud1test = g_new0(UserDefOne, 1);
     ud1test->integer = 42;
     ud1test->string = g_strdup("hi there 42");
 
     qapi_free_UserDefOne(ud1test);
 
-    ud1a = g_malloc0(sizeof(UserDefOne));
+    ud1a = g_new0(UserDefOne, 1);
     ud1a->integer = 43;
     ud1a->string = g_strdup("hi there 43");
 
-    ud1b = g_malloc0(sizeof(UserDefOne));
+    ud1b = g_new0(UserDefOne, 1);
     ud1b->integer = 44;
     ud1b->string = g_strdup("hi there 44");
 
-    ud1list = g_malloc0(sizeof(UserDefOneList));
+    ud1list = g_new0(UserDefOneList, 1);
     ud1list->value = ud1a;
-    ud1list->next = g_malloc0(sizeof(UserDefOneList));
+    ud1list->next = g_new0(UserDefOneList, 1);
     ud1list->next->value = ud1b;
 
Quoted 4 lines

tests/test-qmp-commands.c static void test_dealloc_types(void) · line 231

Quoted 1 line
tests/test-qmp-commands.c +0 -0
     qapi_free_UserDefOneList(ud1list);

Could squash together with PATCH 79 and call the result "monitor: Use g_new() family of functions".

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#45 lore raw

Re: [Qemu-devel] [PATCH 31/88] QMP: use g_new() family of functions

Quoted 22 lines · Dr. David Alan Gilbert
Quoted 13 lines

monitor.c static void query_commands_cb(QmpCommand *cmd, void *opaque) · line 912

Quoted 6 lines
monitor.c +1 -1
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(CommandInfoList, 1);
     info->value = g_malloc0(sizeof(*info->value));
     info->value->name = g_strdup(cmd->name);
     info->next = *list;

I'm not convinced rewriting

       LHS = g_malloc(sizeof(*LHS));

to

Quoted 8 lines
       LHS = g_new(T, 1);

where T is the type of LHS is worth the trouble. The code before the rewrite is pretty idiomatic. There's no possibility of integer overflow g_new() could avoid. The types are obviously correct, so the additional type checking is quite unlikely to catch anything. That leaves the consistency argument. I'm willing to hear it, but I feel it should be heard in a patch series that does nothing else.

Quoted 7 lines

The 'obviously correct' is the dodgy part of the argument here. How many bugs do we right that are obviously wrong?

t.c:13:20: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]

     struct c *pc = g_new(struct b, 1);

seems good to me.

Yes, that's a GOOD warning, and it proves that we DO get type safety when we convert:

LHS = g_malloc(sizeof(type))

into

LHS = g_new(type, 1)

but that's not what Markus was pointing out. When we already have the correctly-typed object on the right hand side, as in:

LHS = g_malloc(sizeof(*LHS))

then the compiler will always give us the correct type of LHS, whereas with:

LHS = g_new(type, 1)

we have to manually update the line if the type of LHS changes.

Thus, converting malloc(sizeof(type)) into new(type, 1) is a no-brainer, but converting malloc(sizeof(*expr)) needs justification. I'm not necessarily opposed to the conversion (if our justification is consistency, and where HACKING documents our style and where we have scripts that let us easily preserve our style), but I'm not sure I see the requisite justification in the current iteration of this series.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#46 lore raw

PATCH 32/88 QObject: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: added qbool.c, qdict.c, qlist.c, qstring.c and tests/]
---
 qobject/json-parser.c               | 2 +-
 qobject/qbool.c                     | 2 +-
 qobject/qdict.c                     | 4 ++--
 qobject/qlist.c                     | 4 ++--
 qobject/qstring.c                   | 2 +-
 tests/test-qobject-output-visitor.c | 4 ++--
 6 files changed, 9 insertions(+), 9 deletions(-)
qobject/json-parser.c +1 -1
index 724ca240e4..37dda9bc3f 100644
@@ -247,7 +247,7 @@ static JSONParserContext *parser_context_new(GQueue *tokens)
         return NULL;
     }
 
-    ctxt = g_malloc0(sizeof(JSONParserContext));
+    ctxt = g_new0(JSONParserContext, 1);
     ctxt->buf = tokens;
 
     return ctxt;
qobject/qbool.c +1 -1
index 0606bbd2a3..5ad7f6d98f 100644
@@ -25,7 +25,7 @@ QBool *qbool_from_bool(bool value)
 {
     QBool *qb;
 
-    qb = g_malloc(sizeof(*qb));
+    qb = g_new(QBool, 1);
     qobject_init(QOBJECT(qb), QTYPE_QBOOL);
     qb->value = value;
 
qobject/qdict.c +2 -2
index 576018e531..857e71c7a1 100644
@@ -30,7 +30,7 @@ QDict *qdict_new(void)
 {
     QDict *qdict;
 
-    qdict = g_malloc0(sizeof(*qdict));
+    qdict = g_new0(QDict, 1);
     qobject_init(QOBJECT(qdict), QTYPE_QDICT);
 
     return qdict;
@@ -70,7 +70,7 @@ static QDictEntry *alloc_entry(const char *key, QObject *value)
 {
     QDictEntry *entry;
 
-    entry = g_malloc0(sizeof(*entry));
+    entry = g_new0(QDictEntry, 1);
     entry->key = g_strdup(key);
     entry->value = value;
 
qobject/qlist.c +2 -2
index 86b60cb88c..8afc594d0d 100644
@@ -25,7 +25,7 @@ QList *qlist_new(void)
 {
     QList *qlist;
 
-    qlist = g_malloc(sizeof(*qlist));
+    qlist = g_new(QList, 1);
     qobject_init(QOBJECT(qlist), QTYPE_QLIST);
     QTAILQ_INIT(&qlist->head);
 
@@ -58,7 +58,7 @@ void qlist_append_obj(QList *qlist, QObject *value)
 {
     QListEntry *entry;
 
-    entry = g_malloc(sizeof(*entry));
+    entry = g_new(QListEntry, 1);
     entry->value = value;
 
     QTAILQ_INSERT_TAIL(&qlist->head, entry, next);
qobject/qstring.c +1 -1
index 5da7b5f37c..806c0306a2 100644
@@ -42,7 +42,7 @@ QString *qstring_from_substr(const char *str, int start, int end)
 {
     QString *qstring;
 
-    qstring = g_malloc(sizeof(*qstring));
+    qstring = g_new(QString, 1);
     qobject_init(QOBJECT(qstring), QTYPE_QSTRING);
 
     qstring->length = end - start + 1;
tests/test-qobject-output-visitor.c +2 -2
index d375100a52..d0a66a5dca 100644
@@ -182,7 +182,7 @@ static void test_visitor_out_struct_nested(TestOutputVisitorData *data,
     const char *strings[] = { "forty two", "forty three", "forty four",
                               "forty five" };
 
-    ud2 = g_malloc0(sizeof(*ud2));
+    ud2 = g_new0(UserDefTwo, 1);
     ud2->string0 = g_strdup(strings[0]);
 
     ud2->dict1 = g_malloc0(sizeof(*ud2->dict1));
@@ -372,7 +372,7 @@ static void test_visitor_out_union_flat(TestOutputVisitorData *data,
 {
     QDict *qdict;
 
-    UserDefFlatUnion *tmp = g_malloc0(sizeof(UserDefFlatUnion));
+    UserDefFlatUnion *tmp = g_new0(UserDefFlatUnion, 1);
     tmp->enum1 = ENUM_ONE_VALUE1;
     tmp->string = g_strdup("str");
     tmp->integer = 41;
Signature · 1 line
2.14.2
#47 lore raw

PATCH 33/88 qom: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 qom/object.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
qom/object.c +3 -3
index 6a7bd9257b..3273f9c1f0 100644
@@ -940,7 +940,7 @@ object_property_add(Object *obj, const char *name, const char *type,
         return NULL;
     }
 
-    prop = g_malloc0(sizeof(*prop));
+    prop = g_new0(ObjectProperty, 1);
 
     prop->name = g_strdup(name);
     prop->type = g_strdup(type);
@@ -973,7 +973,7 @@ object_class_property_add(ObjectClass *klass,
         return NULL;
     }
 
-    prop = g_malloc0(sizeof(*prop));
+    prop = g_new0(ObjectProperty, 1);
 
     prop->name = g_strdup(name);
     prop->type = g_strdup(type);
@@ -2281,7 +2281,7 @@ void object_property_add_alias(Object *obj, const char *name,
         prop_type = g_strdup(target_prop->type);
     }
 
-    prop = g_malloc(sizeof(*prop));
+    prop = g_new(AliasProperty, 1);
     prop->target_obj = target_obj;
     prop->target_name = g_strdup(target_name);
 
Signature · 1 line
2.14.2
#48 lore raw

PATCH 34/88 qapi: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 qapi/opts-visitor.c           | 2 +-
 qapi/qapi-clone-visitor.c     | 2 +-
 qapi/qapi-dealloc-visitor.c   | 2 +-
 qapi/qobject-output-visitor.c | 2 +-
 qapi/string-input-visitor.c   | 2 +-
 qapi/string-output-visitor.c  | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
qapi/opts-visitor.c +1 -1
index 324b197495..34ac49f3c2 100644
@@ -539,7 +539,7 @@ opts_visitor_new(const QemuOpts *opts)
     OptsVisitor *ov;
 
     assert(opts);
-    ov = g_malloc0(sizeof *ov);
+    ov = g_new0(OptsVisitor, 1);
 
     ov->visitor.type = VISITOR_INPUT;
 
qapi/qapi-clone-visitor.c +1 -1
index d8b62792bc..3d216e5906 100644
@@ -145,7 +145,7 @@ static Visitor *qapi_clone_visitor_new(void)
 {
     QapiCloneVisitor *v;
 
-    v = g_malloc0(sizeof(*v));
+    v = g_new0(QapiCloneVisitor, 1);
 
     v->visitor.type = VISITOR_CLONE;
     v->visitor.start_struct = qapi_clone_start_struct;
qapi/qapi-dealloc-visitor.c +1 -1
index ed70a0158b..ad0d0eb7e4 100644
@@ -120,7 +120,7 @@ Visitor *qapi_dealloc_visitor_new(void)
 {
     QapiDeallocVisitor *v;
 
-    v = g_malloc0(sizeof(*v));
+    v = g_new0(QapiDeallocVisitor, 1);
 
     v->visitor.type = VISITOR_DEALLOC;
     v->visitor.start_struct = qapi_dealloc_start_struct;
qapi/qobject-output-visitor.c +1 -1
index d325163e55..7228986c0c 100644
@@ -229,7 +229,7 @@ Visitor *qobject_output_visitor_new(QObject **result)
 {
     QObjectOutputVisitor *v;
 
-    v = g_malloc0(sizeof(*v));
+    v = g_new0(QObjectOutputVisitor, 1);
 
     v->visitor.type = VISITOR_OUTPUT;
     v->visitor.start_struct = qobject_output_start_struct;
qapi/string-input-visitor.c +1 -1
index 67a0a4a58b..3a2fe58478 100644
@@ -356,7 +356,7 @@ Visitor *string_input_visitor_new(const char *str)
     StringInputVisitor *v;
 
     assert(str);
-    v = g_malloc0(sizeof(*v));
+    v = g_new0(StringInputVisitor, 1);
 
     v->visitor.type = VISITOR_INPUT;
     v->visitor.type_int64 = parse_type_int64;
qapi/string-output-visitor.c +1 -1
index 7ab64468d9..a7bbbae109 100644
@@ -341,7 +341,7 @@ Visitor *string_output_visitor_new(bool human, char **result)
 {
     StringOutputVisitor *v;
 
-    v = g_malloc0(sizeof(*v));
+    v = g_new0(StringOutputVisitor, 1);
 
     v->string = g_string_new(NULL);
     v->human = human;
Signature · 1 line
2.14.2
#49 lore raw

Re: [Qemu-devel] [PATCH 34/88] qapi: use g_new() family of functions

Quoted 15 lines · Philippe Mathieu-Daudé
---
 qapi/opts-visitor.c           | 2 +-
 qapi/qapi-clone-visitor.c     | 2 +-
 qapi/qapi-dealloc-visitor.c   | 2 +-
 qapi/qobject-output-visitor.c | 2 +-
 qapi/string-input-visitor.c   | 2 +-
 qapi/string-output-visitor.c  | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
qapi/opts-visitor.c +0 -0
index 324b197495..34ac49f3c2 100644

qapi/opts-visitor.c opts_visitor_new(const QemuOpts *opts) · line 542

Quoted 5 lines
qapi/opts-visitor.c +1 -1
@@ -539,7 +539,7 @@ opts_visitor_new(const QemuOpts *opts)
     OptsVisitor *ov;
 
     assert(opts);
-    ov = g_malloc0(sizeof *ov);
+    ov = g_new0(OptsVisitor, 1);

Transformations like this are harder to justify - you have more typing rather than less, and no change in the amount of type-safety.

If we really want to convert LHS = g_malloc0(sizeof(*LHS)), we probably ought to have a stronger justification (consistency might be such an argument, if the entire series is applied and HACKING is updated to mention our new preferred style, and where the checked-in Coccinelle script can be easily re-run in the future to catch regressions).

Converting LHS = g_malloc0(sizeof(type)) is a no-brainer, because it DOES add type-safety, and often results in less typing. But I haven't looked at your entire series to see which patches fall in the no-brainer category vs. the weakly-argued consistency category.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#50 lore raw

PATCH 35/88 Record/replay: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 replay/replay-char.c   |  4 ++--
 replay/replay-events.c | 10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)
replay/replay-char.c +2 -2
index cbf7c04a9f..b8ed5c51d1 100755
@@ -51,7 +51,7 @@ void replay_register_char_driver(Chardev *chr)
 
 void replay_chr_be_write(Chardev *s, uint8_t *buf, int len)
 {
-    CharEvent *event = g_malloc0(sizeof(CharEvent));
+    CharEvent *event = g_new0(CharEvent, 1);
 
     event->id = find_char_driver(s);
     if (event->id < 0) {
@@ -86,7 +86,7 @@ void replay_event_char_read_save(void *opaque)
 
 void *replay_event_char_read_load(void)
 {
-    CharEvent *event = g_malloc0(sizeof(CharEvent));
+    CharEvent *event = g_new0(CharEvent, 1);
 
     event->id = replay_get_byte();
     replay_get_array_alloc(&event->buf, &event->len);
replay/replay-events.c +5 -5
index 94a6dcccfc..c72dcaa708 100644
@@ -128,7 +128,7 @@ void replay_add_event(ReplayAsyncEventKind event_kind,
         return;
     }
 
-    Event *event = g_malloc0(sizeof(Event));
+    Event *event = g_new0(Event, 1);
     event->event_kind = event_kind;
     event->opaque = opaque;
     event->opaque2 = opaque2;
@@ -239,17 +239,17 @@ static Event *replay_read_event(int checkpoint)
         }
         break;
     case REPLAY_ASYNC_EVENT_INPUT:
-        event = g_malloc0(sizeof(Event));
+        event = g_new0(Event, 1);
         event->event_kind = read_event_kind;
         event->opaque = replay_read_input_event();
         return event;
     case REPLAY_ASYNC_EVENT_INPUT_SYNC:
-        event = g_malloc0(sizeof(Event));
+        event = g_new0(Event, 1);
         event->event_kind = read_event_kind;
         event->opaque = 0;
         return event;
     case REPLAY_ASYNC_EVENT_CHAR_READ:
-        event = g_malloc0(sizeof(Event));
+        event = g_new0(Event, 1);
         event->event_kind = read_event_kind;
         event->opaque = replay_event_char_read_load();
         return event;
@@ -259,7 +259,7 @@ static Event *replay_read_event(int checkpoint)
         }
         break;
     case REPLAY_ASYNC_EVENT_NET:
-        event = g_malloc0(sizeof(Event));
+        event = g_new0(Event, 1);
         event->event_kind = read_event_kind;
         event->opaque = replay_event_net_load();
         return event;
Signature · 1 line
2.14.2
#51 lore raw

PATCH 36/88 SLIRP: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 net/slirp.c    | 4 ++--
 slirp/slirp.c  | 2 +-
 slirp/socket.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
net/slirp.c +2 -2
index 318a26e892..c42e1fd0d0 100644
@@ -869,7 +869,7 @@ net_init_slirp_configs(const StringList *fwd, int flags)
     while (fwd) {
         struct slirp_config_str *config;
 
-        config = g_malloc0(sizeof(*config));
+        config = g_new0(struct slirp_config_str, 1);
         pstrcpy(config->str, sizeof(config->str), fwd->value->str);
         config->flags = flags;
         config->next = slirp_configs;
@@ -973,7 +973,7 @@ int net_slirp_parse_legacy(QemuOptsList *opts_list, const char *optarg, int *ret
     if (QTAILQ_EMPTY(&slirp_stacks)) {
         struct slirp_config_str *config;
 
-        config = g_malloc(sizeof(*config));
+        config = g_new(struct slirp_config_str, 1);
         pstrcpy(config->str, sizeof(config->str), optarg);
         config->flags = SLIRP_CFG_LEGACY;
         config->next = slirp_configs;
slirp/slirp.c +1 -1
index 1cb6b07004..9af9179afa 100644
@@ -288,7 +288,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
                   struct in6_addr vnameserver6, const char **vdnssearch,
                   void *opaque)
 {
-    Slirp *slirp = g_malloc0(sizeof(Slirp));
+    Slirp *slirp = g_new0(Slirp, 1);
 
     slirp_init_once();
 
slirp/socket.c +1 -1
index cb7b5b608d..2eccb68c2e 100644
@@ -48,7 +48,7 @@ socreate(Slirp *slirp)
 {
   struct socket *so;
 
-  so = (struct socket *)malloc(sizeof(struct socket));
+  so = g_new(struct socket, 1);
   if(so) {
     memset(so, 0, sizeof(struct socket));
     so->so_state = SS_NOFDREF;
Signature · 1 line
2.14.2
#52 lore raw

Re: [Qemu-devel] [PATCH 36/88] SLIRP: use g_new() family of functions

Hello,

net/slirp.c net_init_slirp_configs(const StringList *fwd, int flags) · line 872

Quoted 8 lines · Philippe Mathieu-Daudé, on ven. 06 oct. 2017 20:49:31 -0300, wrote:
net/slirp.c +1 -1
@@ -869,7 +869,7 @@ net_init_slirp_configs(const StringList *fwd, int flags)
     while (fwd) {
         struct slirp_config_str *config;
 
-        config = g_malloc0(sizeof(*config));
+        config = g_new0(struct slirp_config_str, 1);

It doesn't really seem like an improvement to me in such case: we don't have overflow issues here, and using sizeof(*config) makes the line clearly correct, while expliciting the struct behind means we need to make sure of the coherency.

slirp/socket.c socreate(Slirp *slirp) · line 51

Quoted 10 lines
slirp/socket.c +1 -1
index cb7b5b608d..2eccb68c2e 100644
@@ -48,7 +48,7 @@ socreate(Slirp *slirp)
 {
   struct socket *so;
 
-  so = (struct socket *)malloc(sizeof(struct socket));
+  so = g_new(struct socket, 1);

Similarly, here I'd rather write g_malloc(sizeof(*so));

Samuel

#53 lore raw

PATCH 37/88 TCG: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: avoid use of g_malloc0() in cpus.c]
---
 cpus.c    | 18 +++++++++---------
 tcg/tcg.c |  4 ++--
 2 files changed, 11 insertions(+), 11 deletions(-)
cpus.c +9 -9
index c9a624003a..6dea1c7041 100644
@@ -1666,8 +1666,8 @@ static void qemu_tcg_init_vcpu(CPUState *cpu)
     static QemuThread *single_tcg_cpu_thread;
 
     if (qemu_tcg_mttcg_enabled() || !single_tcg_cpu_thread) {
-        cpu->thread = g_malloc0(sizeof(QemuThread));
-        cpu->halt_cond = g_malloc0(sizeof(QemuCond));
+        cpu->thread = g_new0(QemuThread, 1);
+        cpu->halt_cond = g_new0(QemuCond, 1);
         qemu_cond_init(cpu->halt_cond);
 
         if (qemu_tcg_mttcg_enabled()) {
@@ -1706,8 +1706,8 @@ static void qemu_hax_start_vcpu(CPUState *cpu)
 {
     char thread_name[VCPU_THREAD_NAME_SIZE];
 
-    cpu->thread = g_malloc0(sizeof(QemuThread));
-    cpu->halt_cond = g_malloc0(sizeof(QemuCond));
+    cpu->thread = g_new0(QemuThread, 1);
+    cpu->halt_cond = g_new0(QemuCond, 1);
     qemu_cond_init(cpu->halt_cond);
 
     snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HAX",
@@ -1726,8 +1726,8 @@ static void qemu_kvm_start_vcpu(CPUState *cpu)
 {
     char thread_name[VCPU_THREAD_NAME_SIZE];
 
-    cpu->thread = g_malloc0(sizeof(QemuThread));
-    cpu->halt_cond = g_malloc0(sizeof(QemuCond));
+    cpu->thread = g_new0(QemuThread, 1);
+    cpu->halt_cond = g_new0(QemuCond, 1);
     qemu_cond_init(cpu->halt_cond);
     snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/KVM",
              cpu->cpu_index);
@@ -1742,8 +1742,8 @@ static void qemu_dummy_start_vcpu(CPUState *cpu)
 {
     char thread_name[VCPU_THREAD_NAME_SIZE];
 
-    cpu->thread = g_malloc0(sizeof(QemuThread));
-    cpu->halt_cond = g_malloc0(sizeof(QemuCond));
+    cpu->thread = g_new0(QemuThread, 1);
+    cpu->halt_cond = g_new0(QemuCond, 1);
     qemu_cond_init(cpu->halt_cond);
     snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY",
              cpu->cpu_index);
@@ -1931,7 +1931,7 @@ CpuInfoList *qmp_query_cpus(Error **errp)
         info->value->has_props = !!mc->cpu_index_to_instance_props;
         if (info->value->has_props) {
             CpuInstanceProperties *props;
-            props = g_malloc0(sizeof(*props));
+            props = g_malloc(sizeof(*props));
             *props = mc->cpu_index_to_instance_props(ms, cpu->cpu_index);
             info->value->props = props;
         }
tcg/tcg.c +2 -2
index dff9999bc6..d5c1c75aa7 100644
@@ -342,8 +342,8 @@ void tcg_context_init(TCGContext *s)
         total_args += n;
     }
 
-    args_ct = g_malloc(sizeof(TCGArgConstraint) * total_args);
-    sorted_args = g_malloc(sizeof(int) * total_args);
+    args_ct = g_new(TCGArgConstraint, total_args);
+    sorted_args = g_new(int, total_args);
 
     for(op = 0; op < NB_OPS; op++) {
         def = &tcg_op_defs[op];
Signature · 1 line
2.14.2
#54 lore raw

PATCH 38/88 VFIO: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: more changes in each file, added pci-quirks.c]
---
 hw/vfio/common.c     | 12 ++++++------
 hw/vfio/pci-quirks.c | 18 +++++++++---------
 hw/vfio/pci.c        |  7 +++----
 hw/vfio/platform.c   |  6 +++---
 4 files changed, 21 insertions(+), 22 deletions(-)
hw/vfio/common.c +6 -6
index 7b2924c0ef..bde4fdba66 100644
@@ -272,7 +272,7 @@ static void vfio_host_win_add(VFIOContainer *container,
         }
     }
 
-    hostwin = g_malloc0(sizeof(*hostwin));
+    hostwin = g_new0(VFIOHostDMAWindow, 1);
 
     hostwin->min_iova = min_iova;
     hostwin->max_iova = max_iova;
@@ -488,7 +488,7 @@ static void vfio_listener_region_add(MemoryListener *listener,
          * would be the right place to wire that up (tell the KVM
          * device emulation the VFIO iommu handles to use).
          */
-        giommu = g_malloc0(sizeof(*giommu));
+        giommu = g_new0(VFIOGuestIOMMU, 1);
         giommu->iommu = iommu_mr;
         giommu->iommu_offset = section->offset_within_address_space -
                                section->offset_within_region;
@@ -688,7 +688,7 @@ static int vfio_setup_region_sparse_mmaps(VFIORegion *region,
     }
 
     region->nr_mmaps = j;
-    region->mmaps = g_realloc(region->mmaps, j * sizeof(VFIOMmap));
+    region->mmaps = g_renew(VFIOMmap, region->mmaps, j);
 
     return 0;
 }
@@ -938,7 +938,7 @@ static VFIOAddressSpace *vfio_get_address_space(AddressSpace *as)
     }
 
     /* No suitable VFIOAddressSpace, create a new one */
-    space = g_malloc0(sizeof(*space));
+    space = g_new0(VFIOAddressSpace, 1);
     space->as = as;
     QLIST_INIT(&space->containers);
 
@@ -987,7 +987,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,
         goto close_fd_exit;
     }
 
-    container = g_malloc0(sizeof(*container));
+    container = g_new0(VFIOContainer, 1);
     container->space = space;
     container->fd = fd;
     if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) ||
@@ -1202,7 +1202,7 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as, Error **errp)
         }
     }
 
-    group = g_malloc0(sizeof(*group));
+    group = g_new0(VFIOGroup, 1);
 
     snprintf(path, sizeof(path), "/dev/vfio/%d", groupid);
     group->fd = qemu_open(path, O_RDWR);
hw/vfio/pci-quirks.c +9 -9
index 14291c2a16..b51ee60368 100644
@@ -288,7 +288,7 @@ static void vfio_vga_probe_ati_3c3_quirk(VFIOPCIDevice *vdev)
         return;
     }
 
-    quirk = g_malloc0(sizeof(*quirk));
+    quirk = g_new0(VFIOQuirk, 1);
     quirk->mem = g_new0(MemoryRegion, 1);
     quirk->nr_mem = 1;
 
@@ -323,7 +323,7 @@ static void vfio_probe_ati_bar4_quirk(VFIOPCIDevice *vdev, int nr)
         return;
     }
 
-    quirk = g_malloc0(sizeof(*quirk));
+    quirk = g_new0(VFIOQuirk, 1);
     quirk->mem = g_new0(MemoryRegion, 2);
     quirk->nr_mem = 2;
     window = quirk->data = g_malloc0(sizeof(*window) +
@@ -371,7 +371,7 @@ static void vfio_probe_ati_bar2_quirk(VFIOPCIDevice *vdev, int nr)
         return;
     }
 
-    quirk = g_malloc0(sizeof(*quirk));
+    quirk = g_new0(VFIOQuirk, 1);
     mirror = quirk->data = g_malloc0(sizeof(*mirror));
     mirror->mem = quirk->mem = g_new0(MemoryRegion, 1);
     quirk->nr_mem = 1;
@@ -547,7 +547,7 @@ static void vfio_vga_probe_nvidia_3d0_quirk(VFIOPCIDevice *vdev)
         return;
     }
 
-    quirk = g_malloc0(sizeof(*quirk));
+    quirk = g_new0(VFIOQuirk, 1);
     quirk->data = data = g_malloc0(sizeof(*data));
     quirk->mem = g_new0(MemoryRegion, 2);
     quirk->nr_mem = 2;
@@ -665,7 +665,7 @@ static void vfio_probe_nvidia_bar5_quirk(VFIOPCIDevice *vdev, int nr)
         return;
     }
 
-    quirk = g_malloc0(sizeof(*quirk));
+    quirk = g_new0(VFIOQuirk, 1);
     quirk->mem = g_new0(MemoryRegion, 4);
     quirk->nr_mem = 4;
     bar5 = quirk->data = g_malloc0(sizeof(*bar5) +
@@ -759,7 +759,7 @@ static void vfio_probe_nvidia_bar0_quirk(VFIOPCIDevice *vdev, int nr)
         return;
     }
 
-    quirk = g_malloc0(sizeof(*quirk));
+    quirk = g_new0(VFIOQuirk, 1);
     mirror = quirk->data = g_malloc0(sizeof(*mirror));
     mirror->mem = quirk->mem = g_new0(MemoryRegion, 1);
     quirk->nr_mem = 1;
@@ -942,7 +942,7 @@ static void vfio_probe_rtl8168_bar2_quirk(VFIOPCIDevice *vdev, int nr)
         return;
     }
 
-    quirk = g_malloc0(sizeof(*quirk));
+    quirk = g_new0(VFIOQuirk, 1);
     quirk->mem = g_new0(MemoryRegion, 2);
     quirk->nr_mem = 2;
     quirk->data = rtl = g_malloc0(sizeof(*rtl));
@@ -1500,7 +1500,7 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
     }
 
     /* Setup our quirk to munge GTT addresses to the VM allocated buffer */
-    quirk = g_malloc0(sizeof(*quirk));
+    quirk = g_new0(VFIOQuirk, 1);
     quirk->mem = g_new0(MemoryRegion, 2);
     quirk->nr_mem = 2;
     igd = quirk->data = g_malloc0(sizeof(*igd));
@@ -1553,7 +1553,7 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
      * memory region must be written to the device BDSM regsiter at PCI
      * config offset 0x5C.
      */
-    bdsm_size = g_malloc(sizeof(*bdsm_size));
+    bdsm_size = g_new(uint64_t, 1);
     *bdsm_size = cpu_to_le64((ggms_mb + gms_mb) * 1024 * 1024);
     fw_cfg_add_file(fw_cfg_find(), "etc/igd-bdsm-size",
                     bdsm_size, sizeof(*bdsm_size));
hw/vfio/pci.c +3 -4
index 9e86db7c3b..15b82b2942 100644
@@ -1395,7 +1395,7 @@ static void vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
     table = le32_to_cpu(table);
     pba = le32_to_cpu(pba);
 
-    msix = g_malloc0(sizeof(*msix));
+    msix = g_new0(VFIOMSIXInfo, 1);
     msix->table_bar = table & PCI_MSIX_FLAGS_BIRMASK;
     msix->table_offset = table & ~PCI_MSIX_FLAGS_BIRMASK;
     msix->pba_bar = pba & PCI_MSIX_FLAGS_BIRMASK;
@@ -1437,8 +1437,7 @@ static int vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp)
     int ret;
     Error *err = NULL;
 
-    vdev->msix->pending = g_malloc0(BITS_TO_LONGS(vdev->msix->entries) *
-                                    sizeof(unsigned long));
+    vdev->msix->pending = g_new0(unsigned long, BITS_TO_LONGS(vdev->msix->entries));
     ret = msix_init(&vdev->pdev, vdev->msix->entries,
                     vdev->bars[vdev->msix->table_bar].region.mem,
                     vdev->msix->table_bar, vdev->msix->table_offset,
@@ -2076,7 +2075,7 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single)
     }
     vdev->vbasedev.needs_reset = false;
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(struct vfio_pci_hot_reset_info, 1);
     info->argsz = sizeof(*info);
 
     ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info);
hw/vfio/platform.c +3 -3
index da84abf4fc..547225037f 100644
@@ -55,7 +55,7 @@ static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev,
     SysBusDevice *sbdev = SYS_BUS_DEVICE(vdev);
     VFIOINTp *intp;
 
-    intp = g_malloc0(sizeof(*intp));
+    intp = g_new0(VFIOINTp, 1);
     intp->vdev = vdev;
     intp->pin = info.index;
     intp->flags = info.flags;
@@ -65,7 +65,7 @@ static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev,
     sysbus_init_irq(sbdev, &intp->qemuirq);
 
     /* Get an eventfd for trigger */
-    intp->interrupt = g_malloc0(sizeof(EventNotifier));
+    intp->interrupt = g_new0(EventNotifier, 1);
     ret = event_notifier_init(intp->interrupt, 0);
     if (ret) {
         g_free(intp->interrupt);
@@ -76,7 +76,7 @@ static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev,
     }
     if (vfio_irq_is_automasked(intp)) {
         /* Get an eventfd for resample/unmask */
-        intp->unmask = g_malloc0(sizeof(EventNotifier));
+        intp->unmask = g_new0(EventNotifier, 1);
         ret = event_notifier_init(intp->unmask, 0);
         if (ret) {
             g_free(intp->interrupt);
Signature · 1 line
2.14.2
#55 lore raw

PATCH 39/88 hw/i386: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: renamed PC -> hw/i386, split of target/i386/cpu.c, added more changes]
---
 hw/i386/acpi-build.c  | 4 ++--
 hw/i386/amd_iommu.c   | 4 ++--
 hw/i386/intel_iommu.c | 2 +-
 hw/i386/pc.c          | 8 ++++----
 hw/i386/pc_sysfw.c    | 6 +++---
 5 files changed, 12 insertions(+), 12 deletions(-)
hw/i386/acpi-build.c +2 -2
index 2af37a9129..1aff7b4d2f 100644
@@ -777,7 +777,7 @@ static void crs_range_insert(GPtrArray *ranges, uint64_t base, uint64_t limit)
 {
     CrsRangeEntry *entry;
 
-    entry = g_malloc(sizeof(*entry));
+    entry = g_new(CrsRangeEntry, 1);
     entry->base = base;
     entry->limit = limit;
 
@@ -2877,7 +2877,7 @@ void acpi_setup(void)
         return;
     }
 
-    build_state = g_malloc0(sizeof *build_state);
+    build_state = g_new0(AcpiBuildState, 1);
 
     acpi_build_tables_init(&tables);
     acpi_build(&tables, MACHINE(pcms));
hw/i386/amd_iommu.c +2 -2
index 334938a280..f871025376 100644
@@ -1033,13 +1033,13 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn)
 
     /* allocate memory during the first run */
     if (!iommu_as) {
-        iommu_as = g_malloc0(sizeof(AMDVIAddressSpace *) * PCI_DEVFN_MAX);
+        iommu_as = g_new0(AMDVIAddressSpace *, PCI_DEVFN_MAX);
         s->address_spaces[bus_num] = iommu_as;
     }
 
     /* set up AMD-Vi region */
     if (!iommu_as[devfn]) {
-        iommu_as[devfn] = g_malloc0(sizeof(AMDVIAddressSpace));
+        iommu_as[devfn] = g_new0(AMDVIAddressSpace, 1);
         iommu_as[devfn]->bus_num = (uint8_t)bus_num;
         iommu_as[devfn]->devfn = (uint8_t)devfn;
         iommu_as[devfn]->iommu_state = s;
hw/i386/intel_iommu.c +1 -1
index 3a5bb0bc2e..62c94008ad 100644
@@ -2708,7 +2708,7 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus, int devfn)
 
     if (!vtd_dev_as) {
         snprintf(name, sizeof(name), "intel_iommu_devfn_%d", devfn);
-        vtd_bus->dev_as[devfn] = vtd_dev_as = g_malloc0(sizeof(VTDAddressSpace));
+        vtd_bus->dev_as[devfn] = vtd_dev_as = g_new0(VTDAddressSpace, 1);
 
         vtd_dev_as->bus = bus;
         vtd_dev_as->devfn = (uint8_t)devfn;
hw/i386/pc.c +4 -4
index 05985d4927..393aefdc4c 100644
@@ -1175,7 +1175,7 @@ static void pc_build_feature_control_file(PCMachineState *pcms)
         return;
     }
 
-    val = g_malloc(sizeof(*val));
+    val = g_new(uint64_t, 1);
     *val = cpu_to_le64(feature_control_bits | FEATURE_CONTROL_LOCKED);
     fw_cfg_add_file(pcms->fw_cfg, "etc/msr_feature_control", val, sizeof(*val));
 }
@@ -1336,11 +1336,11 @@ void pc_memory_init(PCMachineState *pcms,
      * aliases to address portions of it, mostly for backwards compatibility
      * with older qemus that used qemu_ram_alloc().
      */
-    ram = g_malloc(sizeof(*ram));
+    ram = g_new(MemoryRegion, 1);
     memory_region_allocate_system_memory(ram, NULL, "pc.ram",
                                          machine->ram_size);
     *ram_memory = ram;
-    ram_below_4g = g_malloc(sizeof(*ram_below_4g));
+    ram_below_4g = g_new(MemoryRegion, 1);
     memory_region_init_alias(ram_below_4g, NULL, "ram-below-4g", ram,
                              0, pcms->below_4g_mem_size);
     memory_region_add_subregion(system_memory, 0, ram_below_4g);
@@ -1408,7 +1408,7 @@ void pc_memory_init(PCMachineState *pcms,
     /* Initialize PC system firmware */
     pc_system_firmware_init(rom_memory, !pcmc->pci_enabled);
 
-    option_rom_mr = g_malloc(sizeof(*option_rom_mr));
+    option_rom_mr = g_new(MemoryRegion, 1);
     memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
                            &error_fatal);
     if (pcmc->pci_enabled) {
hw/i386/pc_sysfw.c +3 -3
index 6b183747fc..d80cb17d70 100644
@@ -56,7 +56,7 @@ static void pc_isa_bios_init(MemoryRegion *rom_memory,
 
     /* map the last 128KB of the BIOS in ISA space */
     isa_bios_size = MIN(flash_size, 128 * 1024);
-    isa_bios = g_malloc(sizeof(*isa_bios));
+    isa_bios = g_new(MemoryRegion, 1);
     memory_region_init_ram(isa_bios, NULL, "isa-bios", isa_bios_size,
                            &error_fatal);
     memory_region_add_subregion_overlap(rom_memory,
@@ -193,7 +193,7 @@ static void old_pc_system_rom_init(MemoryRegion *rom_memory, bool isapc_ram_fw)
         (bios_size % 65536) != 0) {
         goto bios_error;
     }
-    bios = g_malloc(sizeof(*bios));
+    bios = g_new(MemoryRegion, 1);
     memory_region_init_ram(bios, NULL, "pc.bios", bios_size, &error_fatal);
     if (!isapc_ram_fw) {
         memory_region_set_readonly(bios, true);
@@ -211,7 +211,7 @@ static void old_pc_system_rom_init(MemoryRegion *rom_memory, bool isapc_ram_fw)
     if (isa_bios_size > (128 * 1024)) {
         isa_bios_size = 128 * 1024;
     }
-    isa_bios = g_malloc(sizeof(*isa_bios));
+    isa_bios = g_new(MemoryRegion, 1);
     memory_region_init_alias(isa_bios, NULL, "isa-bios", bios,
                              bios_size - isa_bios_size, isa_bios_size);
     memory_region_add_subregion_overlap(rom_memory,
Signature · 1 line
2.14.2
#56 lore raw

PATCH 40/88 hw/xen: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: replaced g_new0() -> g_new() in xen_remap_bucket() (no bzero required),

      renamed X86 -> hw/xen and few other changes]
---
 hw/9pfs/xen-9p-backend.c   |  2 +-
 hw/display/xenfb.c         |  4 ++--
 hw/i386/xen/xen-hvm.c      | 10 +++++-----
 hw/i386/xen/xen-mapcache.c | 14 +++++++-------
 hw/xen/xen_pvdev.c         |  2 +-
 5 files changed, 16 insertions(+), 16 deletions(-)
hw/9pfs/xen-9p-backend.c +1 -1
index ee87f08926..d76fa0df8e 100644
@@ -365,7 +365,7 @@ static int xen_9pfs_connect(struct XenDevice *xendev)
         return -1;
     }
 
-    xen_9pdev->rings = g_malloc0(xen_9pdev->num_rings * sizeof(Xen9pfsRing));
+    xen_9pdev->rings = g_new0(Xen9pfsRing, xen_9pdev->num_rings);
     for (i = 0; i < xen_9pdev->num_rings; i++) {
         char *str;
         int ring_order;
hw/display/xenfb.c +2 -2
index 8e2547ac05..5b5fa34131 100644
@@ -479,8 +479,8 @@ static int xenfb_map_fb(struct XenFB *xenfb)
     n_fbdirs = xenfb->fbpages * mode / 8;
     n_fbdirs = DIV_ROUND_UP(n_fbdirs, XC_PAGE_SIZE);
 
-    pgmfns = g_malloc0(sizeof(xen_pfn_t) * n_fbdirs);
-    fbmfns = g_malloc0(sizeof(xen_pfn_t) * xenfb->fbpages);
+    pgmfns = g_new0(xen_pfn_t, n_fbdirs);
+    fbmfns = g_new0(xen_pfn_t, xenfb->fbpages);
 
     xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);
     map = xenforeignmemory_map(xen_fmem, xenfb->c.xendev.dom,
hw/i386/xen/xen-hvm.c +5 -5
index d9ccd5d0d6..37a4e1cd6c 100644
@@ -376,7 +376,7 @@ go_physmap:
 
     mr_name = memory_region_name(mr);
 
-    physmap = g_malloc(sizeof(XenPhysmap));
+    physmap = g_new(XenPhysmap, 1);
 
     physmap->start_addr = start_addr;
     physmap->size = size;
@@ -1188,7 +1188,7 @@ static void xen_read_physmap(XenIOState *state)
         return;
 
     for (i = 0; i < num; i++) {
-        physmap = g_malloc(sizeof (XenPhysmap));
+        physmap = g_new(XenPhysmap, 1);
         physmap->phys_offset = strtoull(entries[i], NULL, 16);
         snprintf(path, sizeof(path),
                 "/local/domain/0/device-model/%d/physmap/%s/start_addr",
@@ -1240,7 +1240,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
     evtchn_port_t bufioreq_evtchn;
     XenIOState *state;
 
-    state = g_malloc0(sizeof (XenIOState));
+    state = g_new0(XenIOState, 1);
 
     state->xce_handle = xenevtchn_open(NULL, 0);
     if (state->xce_handle == NULL) {
@@ -1321,7 +1321,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
     }
 
     /* Note: cpus is empty at this point in init */
-    state->cpu_by_vcpu_id = g_malloc0(max_cpus * sizeof(CPUState *));
+    state->cpu_by_vcpu_id = g_new0(CPUState *, max_cpus);
 
     rc = xen_set_ioreq_server_state(xen_domid, state->ioservid, true);
     if (rc < 0) {
@@ -1330,7 +1330,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
         goto err;
     }
 
-    state->ioreq_local_port = g_malloc0(max_cpus * sizeof (evtchn_port_t));
+    state->ioreq_local_port = g_new0(evtchn_port_t, max_cpus);
 
     /* FIXME: how about if we overflow the page here? */
     for (i = 0; i < max_cpus; i++) {
hw/i386/xen/xen-mapcache.c +7 -7
index baab93b614..93cba7fb83 100644
@@ -109,7 +109,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;
@@ -165,8 +165,7 @@ 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));
+    err = g_new0(int, nb_pfn);
 
     if (entry->vaddr_base != NULL) {
         if (!(entry->flags & XEN_MAPCACHE_ENTRY_DUMMY)) {
@@ -180,6 +179,7 @@ static void xen_remap_bucket(MapCacheEntry *entry,
     g_free(entry->valid_mapping);
     entry->valid_mapping = NULL;
 
+    pfns = g_new(xen_pfn_t, nb_pfn);
     for (i = 0; i < nb_pfn; i++) {
         pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + i;
     }
@@ -212,8 +212,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;
@@ -300,7 +300,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) {
@@ -334,7 +334,7 @@ tryagain:
 
     mapcache->last_entry = entry;
     if (lock) {
-        MapCacheRev *reventry = g_malloc0(sizeof(MapCacheRev));
+        MapCacheRev *reventry = g_new0(MapCacheRev, 1);
         entry->lock++;
         reventry->dma = dma;
         reventry->vaddr_req = mapcache->last_entry->vaddr_base + address_offset;
hw/xen/xen_pvdev.c +1 -1
index aed783e844..8c1c14fb60 100644
@@ -43,7 +43,7 @@ static void xenstore_cleanup_dir(char *dir)
 {
     struct xs_dirs *d;
 
-    d = g_malloc(sizeof(*d));
+    d = g_new(struct xs_dirs, 1);
     d->xs_dir = dir;
     QTAILQ_INSERT_TAIL(&xs_cleanup, d, list);
 }
Signature · 1 line
2.14.2
Reviewed-by on v1 40/88
#57 lore raw

Re: [Qemu-devel] [PATCH 40/88] hw/xen: use g_new() family of functions

Quoted 6 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: replaced g_new0() -> g_new() in xen_remap_bucket() (no bzero required),

      renamed X86 -> hw/xen and few other changes]

Thanks,

Signature · 1 line
Anthony PERARD
#58 lore raw

PATCH 41/88 target/i386: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
[PMD: added more changes and hax]
---
 target/i386/cpu.c     | 6 +++---
 target/i386/hax-all.c | 4 ++--
 target/i386/hax-mem.c | 2 +-
 target/i386/hyperv.c  | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
target/i386/cpu.c +3 -3
index 98732cd65f..236a4115cd 100644
@@ -2344,7 +2344,7 @@ static void x86_cpu_definition_entry(gpointer data, gpointer user_data)
     CpuDefinitionInfoList *entry;
     CpuDefinitionInfo *info;
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(CpuDefinitionInfo, 1);
     info->name = x86_cpu_class_get_model_name(cc);
     x86_cpu_class_check_missing_features(cc, &info->unavailable_features);
     info->has_unavailable_features = true;
@@ -2353,7 +2353,7 @@ static void x86_cpu_definition_entry(gpointer data, gpointer user_data)
     info->has_migration_safe = true;
     info->q_static = cc->static_model;
 
-    entry = g_malloc0(sizeof(*entry));
+    entry = g_new0(CpuDefinitionInfoList, 1);
     entry->value = info;
     entry->next = *cpu_list;
     *cpu_list = entry;
@@ -3933,7 +3933,7 @@ static GuestPanicInformation *x86_cpu_get_crash_info(CPUState *cs)
     GuestPanicInformation *panic_info = NULL;
 
     if (env->features[FEAT_HYPERV_EDX] & HV_GUEST_CRASH_MSR_AVAILABLE) {
-        panic_info = g_malloc0(sizeof(GuestPanicInformation));
+        panic_info = g_new0(GuestPanicInformation, 1);
 
         panic_info->type = GUEST_PANIC_INFORMATION_TYPE_HYPER_V;
 
target/i386/hax-all.c +2 -2
index 3ce6950296..8f4368fe01 100644
@@ -155,7 +155,7 @@ int hax_vcpu_create(int id)
         return 0;
     }
 
-    vcpu = g_malloc(sizeof(struct hax_vcpu_state));
+    vcpu = g_new(struct hax_vcpu_state, 1);
     if (!vcpu) {
         fprintf(stderr, "Failed to alloc vcpu state\n");
         return -ENOMEM;
@@ -251,7 +251,7 @@ struct hax_vm *hax_vm_create(struct hax_state *hax)
         return hax->vm;
     }
 
-    vm = g_malloc(sizeof(struct hax_vm));
+    vm = g_new(struct hax_vm, 1);
     if (!vm) {
         return NULL;
     }
target/i386/hax-mem.c +1 -1
index 27a0d214f2..826f7ca501 100644
@@ -82,7 +82,7 @@ static void hax_insert_mapping_before(HAXMapping *next, uint64_t start_pa,
 {
     HAXMapping *entry;
 
-    entry = g_malloc0(sizeof(*entry));
+    entry = g_new0(HAXMapping, 1);
     entry->start_pa = start_pa;
     entry->size = size;
     entry->host_va = host_va;
target/i386/hyperv.c +1 -1
index a050c9d2d1..a427602e58 100644
@@ -78,7 +78,7 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vcpu_id, uint32_t sint,
     HvSintRoute *sint_route;
     int r, gsi;
 
-    sint_route = g_malloc0(sizeof(*sint_route));
+    sint_route = g_new0(HvSintRoute, 1);
     r = event_notifier_init(&sint_route->sint_set_notifier, false);
     if (r) {
         goto err;
Signature · 1 line
2.14.2
#59 lore raw

PATCH 42/88 XTFPGA: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 hw/xtensa/xtfpga.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/xtensa/xtfpga.c +1 -1
index a19ccebdba..c54a09df83 100644
@@ -115,7 +115,7 @@ static const MemoryRegionOps lx60_fpga_ops = {
 static Lx60FpgaState *lx60_fpga_init(MemoryRegion *address_space,
         hwaddr base)
 {
-    Lx60FpgaState *s = g_malloc(sizeof(Lx60FpgaState));
+    Lx60FpgaState *s = g_new(Lx60FpgaState, 1);
 
     memory_region_init_io(&s->iomem, NULL, &lx60_fpga_ops, s,
             "lx60.fpga", 0x10000);
Signature · 1 line
2.14.2
#60 lore raw

PATCH 43/88 hw/core: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: added changes in hw/core/qdev.c]
---
 hw/core/irq.c    | 2 +-
 hw/core/ptimer.c | 2 +-
 hw/core/qdev.c   | 2 +-
 hw/core/reset.c  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
hw/core/irq.c +1 -1
index b98d1d69f5..d9b13b1762 100644
@@ -115,7 +115,7 @@ static void qemu_splitirq(void *opaque, int line, int level)
 
 qemu_irq qemu_irq_split(qemu_irq irq1, qemu_irq irq2)
 {
-    qemu_irq *s = g_malloc0(2 * sizeof(qemu_irq));
+    qemu_irq *s = g_new0(qemu_irq, 2);
     s[0] = irq1;
     s[1] = irq2;
     return qemu_allocate_irq(qemu_splitirq, s, 0);
hw/core/ptimer.c +1 -1
index 7221c68a98..ef4a6646ed 100644
@@ -349,7 +349,7 @@ ptimer_state *ptimer_init(QEMUBH *bh, uint8_t policy_mask)
 {
     ptimer_state *s;
 
-    s = (ptimer_state *)g_malloc0(sizeof(ptimer_state));
+    s = g_new0(ptimer_state, 1);
     s->bh = bh;
     s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, ptimer_tick, s);
     s->policy_mask = policy_mask;
hw/core/qdev.c +1 -1
index 606ab53c42..7b92af1013 100644
@@ -378,7 +378,7 @@ static NamedGPIOList *qdev_get_named_gpio_list(DeviceState *dev,
         }
     }
 
-    ngl = g_malloc0(sizeof(*ngl));
+    ngl = g_new0(NamedGPIOList, 1);
     ngl->name = g_strdup(name);
     QLIST_INSERT_HEAD(&dev->gpios, ngl, node);
     return ngl;
hw/core/reset.c +1 -1
index 84c8869371..01d86c3a95 100644
@@ -40,7 +40,7 @@ static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
 
 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
 {
-    QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
+    QEMUResetEntry *re = g_new0(QEMUResetEntry, 1);
 
     re->func = func;
     re->opaque = opaque;
Signature · 1 line
2.14.2
#61 lore raw

PATCH 44/88 hw/core/loader: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 hw/core/loader.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/core/loader.c +3 -3
index 4593061445..def4766dbb 100644
@@ -899,7 +899,7 @@ int rom_add_file(const char *file, const char *fw_dir,
         return -1;
     }
 
-    rom = g_malloc0(sizeof(*rom));
+    rom = g_new0(Rom, 1);
     rom->name = g_strdup(file);
     rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);
     rom->as = as;
@@ -996,7 +996,7 @@ MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len,
     Rom *rom;
     MemoryRegion *mr = NULL;
 
-    rom           = g_malloc0(sizeof(*rom));
+    rom           = g_new0(Rom, 1);
     rom->name     = g_strdup(name);
     rom->as       = as;
     rom->addr     = addr;
@@ -1039,7 +1039,7 @@ int rom_add_elf_program(const char *name, void *data, size_t datasize,
 {
     Rom *rom;
 
-    rom           = g_malloc0(sizeof(*rom));
+    rom = g_new0(Rom, 1);
     rom->name     = g_strdup(name);
     rom->addr     = addr;
     rom->datasize = datasize;
Signature · 1 line
2.14.2
Reviewed-by on v1 44/88
#62 lore raw

Re: [Qemu-devel] [PATCH 44/88] hw/core/loader: use g_new() family of functions

Quoted 1 line · Philippe Mathieu-Daudé

Thanks,
Alistair

Quoted 39 lines
---
 hw/core/loader.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/core/loader.c +3 -4
index 4593061445..def4766dbb 100644
@@ -899,7 +899,7 @@ int rom_add_file(const char *file, const char *fw_dir,
         return -1;
     }
 
-    rom = g_malloc0(sizeof(*rom));
+    rom = g_new0(Rom, 1);
     rom->name = g_strdup(file);
     rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);
     rom->as = as;
@@ -996,7 +996,7 @@ MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len,
     Rom *rom;
     MemoryRegion *mr = NULL;
 
-    rom           = g_malloc0(sizeof(*rom));
+    rom           = g_new0(Rom, 1);
     rom->name     = g_strdup(name);
     rom->as       = as;
     rom->addr     = addr;
@@ -1039,7 +1039,7 @@ int rom_add_elf_program(const char *name, void *data, size_t datasize,
 {
     Rom *rom;
 
-    rom           = g_malloc0(sizeof(*rom));
+    rom = g_new0(Rom, 1);
     rom->name     = g_strdup(name);
     rom->addr     = addr;
     rom->datasize = datasize;
--

2.14.2

#63 lore raw

PATCH 45/88 hw/display: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: squashed pxa2xx_lcd.c]

---
Andrzej should the tc6393xb files go under the PXA2XX section in MAINTAINERS?

 hw/display/pxa2xx_lcd.c | 2 +-
 hw/display/tc6393xb.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/display/pxa2xx_lcd.c +1 -1
index 845521c5b2..0ca997cae2 100644
@@ -1006,7 +1006,7 @@ PXA2xxLCDState *pxa2xx_lcdc_init(MemoryRegion *sysmem,
     PXA2xxLCDState *s;
     DisplaySurface *surface;
 
-    s = (PXA2xxLCDState *) g_malloc0(sizeof(PXA2xxLCDState));
+    s = g_new0(PXA2xxLCDState, 1);
     s->invalidated = 1;
     s->irq = irq;
     s->sysmem = sysmem;
hw/display/tc6393xb.c +1 -1
index 74d10af3d4..2bd73a27e0 100644
@@ -570,7 +570,7 @@ TC6393xbState *tc6393xb_init(MemoryRegion *sysmem, uint32_t base, qemu_irq irq)
         },
     };
 
-    s = (TC6393xbState *) g_malloc0(sizeof(TC6393xbState));
+    s = g_new0(TC6393xbState, 1);
     s->irq = irq;
     s->gpio_in = qemu_allocate_irqs(tc6393xb_gpio_set, s, TC6393XB_GPIOS);
 
Signature · 1 line
2.14.2
#64 lore raw

PATCH 46/88 hw/display/vga: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

---
Gerd: should those files go under Graphics section in MAINTAINERS?

 hw/display/vga-isa-mm.c | 6 +++---
 hw/display/vga.c        | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
hw/display/vga-isa-mm.c +3 -3
index 51ccbccc41..7af72864df 100644
@@ -105,12 +105,12 @@ static void vga_mm_init(ISAVGAMMState *s, hwaddr vram_base,
     MemoryRegion *s_ioport_ctrl, *vga_io_memory;
 
     s->it_shift = it_shift;
-    s_ioport_ctrl = g_malloc(sizeof(*s_ioport_ctrl));
+    s_ioport_ctrl = g_new(MemoryRegion, 1);
     memory_region_init_io(s_ioport_ctrl, NULL, &vga_mm_ctrl_ops, s,
                           "vga-mm-ctrl", 0x100000);
     memory_region_set_flush_coalesced(s_ioport_ctrl);
 
-    vga_io_memory = g_malloc(sizeof(*vga_io_memory));
+    vga_io_memory = g_new(MemoryRegion, 1);
     /* XXX: endianness? */
     memory_region_init_io(vga_io_memory, NULL, &vga_mem_ops, &s->vga,
                           "vga-mem", 0x20000);
@@ -130,7 +130,7 @@ int isa_vga_mm_init(hwaddr vram_base,
 {
     ISAVGAMMState *s;
 
-    s = g_malloc0(sizeof(*s));
+    s = g_new0(ISAVGAMMState, 1);
 
     s->vga.vram_size_mb = VGA_RAM_SIZE >> 20;
     vga_common_init(&s->vga, NULL, true);
hw/display/vga.c +1 -1
index ed24ef7076..bdefa60f30 100644
@@ -2236,7 +2236,7 @@ MemoryRegion *vga_init_io(VGACommonState *s, Object *obj,
     *vga_ports = vga_portio_list;
     *vbe_ports = vbe_portio_list;
 
-    vga_mem = g_malloc(sizeof(*vga_mem));
+    vga_mem = g_new(MemoryRegion, 1);
     memory_region_init_io(vga_mem, obj, &vga_mem_ops, s,
                           "vga-lowmem", 0x20000);
     memory_region_set_flush_coalesced(vga_mem);
Signature · 1 line
2.14.2
#65 lore raw

PATCH 47/88 hw/i2c: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 hw/i2c/bitbang_i2c.c | 2 +-
 hw/i2c/core.c        | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
hw/i2c/bitbang_i2c.c +1 -1
index 8be88ee265..20a9deef1a 100644
@@ -186,7 +186,7 @@ bitbang_i2c_interface *bitbang_i2c_init(I2CBus *bus)
 {
     bitbang_i2c_interface *s;
 
-    s = g_malloc0(sizeof(bitbang_i2c_interface));
+    s = g_new0(bitbang_i2c_interface, 1);
 
     s->bus = bus;
     s->last_data = 1;
hw/i2c/core.c +2 -2
index 59068f157e..be84d6735f 100644
@@ -132,7 +132,7 @@ int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv)
             DeviceState *qdev = kid->child;
             I2CSlave *candidate = I2C_SLAVE(qdev);
             if ((candidate->address == address) || (bus->broadcast)) {
-                node = g_malloc(sizeof(struct I2CNode));
+                node = g_new(struct I2CNode, 1);
                 node->elt = candidate;
                 QLIST_INSERT_HEAD(&bus->current_devs, node, next);
                 if (!bus->broadcast) {
@@ -258,7 +258,7 @@ static int i2c_slave_post_load(void *opaque, int version_id)
     bus = I2C_BUS(qdev_get_parent_bus(DEVICE(dev)));
     if ((bus->saved_address == dev->address) ||
         (bus->saved_address == I2C_BROADCAST)) {
-        node = g_malloc(sizeof(struct I2CNode));
+        node = g_new(struct I2CNode, 1);
         node->elt = dev;
         QLIST_INSERT_HEAD(&bus->current_devs, node, next);
     }
Signature · 1 line
2.14.2
#66 lore raw

PATCH 48/88 hw/input: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: squashed hw/input/pxa2xx_keypad.c]

---
Andrzej: can you add an entry for tsc2005.c in MAINTAINERS? (or tell me where)

 hw/input/pckbd.c         | 2 +-
 hw/input/ps2.c           | 4 ++--
 hw/input/pxa2xx_keypad.c | 2 +-
 hw/input/tsc2005.c       | 3 +--
 4 files changed, 5 insertions(+), 6 deletions(-)
hw/input/pckbd.c +1 -1
index c479f827b6..ef9e055b1d 100644
@@ -465,7 +465,7 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
                    MemoryRegion *region, ram_addr_t size,
                    hwaddr mask)
 {
-    KBDState *s = g_malloc0(sizeof(KBDState));
+    KBDState *s = g_new0(KBDState, 1);
 
     s->irq_kbd = kbd_irq;
     s->irq_mouse = mouse_irq;
hw/input/ps2.c +2 -2
index dff3f1e024..3e8f5ee98d 100644
@@ -1296,7 +1296,7 @@ static QemuInputHandler ps2_keyboard_handler = {
 
 void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg)
 {
-    PS2KbdState *s = (PS2KbdState *)g_malloc0(sizeof(PS2KbdState));
+    PS2KbdState *s = g_new0(PS2KbdState, 1);
 
     trace_ps2_kbd_init(s);
     s->common.update_irq = update_irq;
@@ -1318,7 +1318,7 @@ static QemuInputHandler ps2_mouse_handler = {
 
 void *ps2_mouse_init(void (*update_irq)(void *, int), void *update_arg)
 {
-    PS2MouseState *s = (PS2MouseState *)g_malloc0(sizeof(PS2MouseState));
+    PS2MouseState *s = g_new0(PS2MouseState, 1);
 
     trace_ps2_mouse_init(s);
     s->common.update_irq = update_irq;
hw/input/pxa2xx_keypad.c +1 -1
index 2b70bbb95c..016b095e94 100644
@@ -310,7 +310,7 @@ PXA2xxKeyPadState *pxa27x_keypad_init(MemoryRegion *sysmem,
 {
     PXA2xxKeyPadState *s;
 
-    s = (PXA2xxKeyPadState *) g_malloc0(sizeof(PXA2xxKeyPadState));
+    s = g_new0(PXA2xxKeyPadState, 1);
     s->irq = irq;
 
     memory_region_init_io(&s->iomem, NULL, &pxa2xx_keypad_ops, s,
hw/input/tsc2005.c +1 -2
index eb5320af40..34dd4ea0da 100644
@@ -485,8 +485,7 @@ void *tsc2005_init(qemu_irq pintdav)
 {
     TSC2005State *s;
 
-    s = (TSC2005State *)
-            g_malloc0(sizeof(TSC2005State));
+    s = g_new0(TSC2005State, 1);
     s->x = 400;
     s->y = 240;
     s->pressure = false;
Signature · 1 line
2.14.2
#67 lore raw

PATCH 49/88 hw/misc: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: added hw/misc/pvpanic.c]
---
 hw/misc/applesmc.c | 2 +-
 hw/misc/pvpanic.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/misc/applesmc.c +1 -1
index 7be8b5f13c..12e32b107e 100644
@@ -252,7 +252,7 @@ static void applesmc_add_key(AppleSMCState *s, const char *key,
 {
     struct AppleSMCData *def;
 
-    def = g_malloc0(sizeof(struct AppleSMCData));
+    def = g_new0(struct AppleSMCData, 1);
     def->key = key;
     def->len = len;
     def->data = data;
hw/misc/pvpanic.c +1 -1
index 2b1e9a6450..dc51e4386c 100644
@@ -95,7 +95,7 @@ static void pvpanic_isa_realizefn(DeviceState *dev, Error **errp)
         return;
     }
 
-    pvpanic_port = g_malloc(sizeof(*pvpanic_port));
+    pvpanic_port = g_new(uint16_t, 1);
     *pvpanic_port = cpu_to_le16(s->ioport);
     fw_cfg_add_file(fw_cfg, "etc/pvpanic-port", pvpanic_port,
                     sizeof(*pvpanic_port));
Signature · 1 line
2.14.2
Reviewed-by on v1 49/88
#68 lore raw

Re: [Qemu-devel] [PATCH 49/88] hw/misc: use g_new() family of functions

Quoted 39 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: added hw/misc/pvpanic.c]
---
 hw/misc/applesmc.c | 2 +-
 hw/misc/pvpanic.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/misc/applesmc.c +1 -1
index 7be8b5f13c..12e32b107e 100644
@@ -252,7 +252,7 @@ static void applesmc_add_key(AppleSMCState *s, const char *key,
 {
     struct AppleSMCData *def;
 
-    def = g_malloc0(sizeof(struct AppleSMCData));
+    def = g_new0(struct AppleSMCData, 1);
     def->key = key;
     def->len = len;
     def->data = data;
hw/misc/pvpanic.c +1 -1
index 2b1e9a6450..dc51e4386c 100644
@@ -95,7 +95,7 @@ static void pvpanic_isa_realizefn(DeviceState *dev, Error **errp)
         return;
     }
 
-    pvpanic_port = g_malloc(sizeof(*pvpanic_port));
+    pvpanic_port = g_new(uint16_t, 1);
     *pvpanic_port = cpu_to_le16(s->ioport);
     fw_cfg_add_file(fw_cfg, "etc/pvpanic-port", pvpanic_port,
                     sizeof(*pvpanic_port));
Signature · 1 line
2.14.2
#69 lore raw

PATCH 50/88 ivshmem: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 hw/misc/ivshmem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/misc/ivshmem.c +2 -2
index b3ef3ec1e3..9dd432a295 100644
@@ -429,7 +429,7 @@ static void resize_peers(IVShmemState *s, int nb_peers)
     assert(nb_peers > old_nb_peers);
     IVSHMEM_DPRINTF("bumping storage to %d peers\n", nb_peers);
 
-    s->peers = g_realloc(s->peers, nb_peers * sizeof(Peer));
+    s->peers = g_renew(Peer, s->peers, nb_peers);
     s->nb_peers = nb_peers;
 
     for (i = old_nb_peers; i < nb_peers; i++) {
@@ -753,7 +753,7 @@ static void ivshmem_reset(DeviceState *d)
 static int ivshmem_setup_interrupts(IVShmemState *s, Error **errp)
 {
     /* allocate QEMU callback data for receiving interrupts */
-    s->msi_vectors = g_malloc0(s->vectors * sizeof(MSIVector));
+    s->msi_vectors = g_new0(MSIVector, s->vectors);
 
     if (ivshmem_has_feature(s, IVSHMEM_MSI)) {
         if (msix_init_exclusive_bar(PCI_DEVICE(s), s->vectors, 1, errp)) {
Signature · 1 line
2.14.2
#70 lore raw

PATCH 51/88 hw/timer: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 hw/timer/slavio_timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/slavio_timer.c +1 -1
index a8cc9c0148..6d0282a788 100644
@@ -385,7 +385,7 @@ static void slavio_timer_init(Object *obj)
         uint64_t size;
         char timer_name[20];
 
-        tc = g_malloc0(sizeof(TimerContext));
+        tc = g_new0(TimerContext, 1);
         tc->s = s;
         tc->timer_index = i;
 
Signature · 1 line
2.14.2
Reviewed-by on v1 51/88
#71 lore raw

Re: [Qemu-devel] [PATCH 51/88] hw/timer: use g_new() family of functions

Quoted 25 lines · 在 2017年10月7日,上午7:49,Philippe Mathieu-Daudé <[email protected]> 写道:

From: Marc-André Lureau <[email protected]>

---
hw/timer/slavio_timer.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/slavio_timer.c +1 -1
index a8cc9c0148..6d0282a788 100644
@@ -385,7 +385,7 @@ static void slavio_timer_init(Object *obj)
      uint64_t size;
      char timer_name[20];
 
-        tc = g_malloc0(sizeof(TimerContext));
+        tc = g_new0(TimerContext, 1);
      tc->s = s;
      tc->timer_index = i;
 
Signature · 1 line
2.14.2
Reviewed-by on v1 51/88
#72 lore raw

Re: [Qemu-devel] [PATCH 51/88] hw/timer: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
Quoted 25 lines · 在 2017年10月7日,上午7:49,Philippe Mathieu-Daudé <[email protected]> 写道:

From: Marc-André Lureau <[email protected]>

---
hw/timer/slavio_timer.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/slavio_timer.c +1 -1
index a8cc9c0148..6d0282a788 100644
@@ -385,7 +385,7 @@ static void slavio_timer_init(Object *obj)
     uint64_t size;
     char timer_name[20];
 
-        tc = g_malloc0(sizeof(TimerContext));
+        tc = g_new0(TimerContext, 1);
     tc->s = s;
     tc->timer_index = i;
 
Signature · 1 line
2.14.2

Resend due to email blocks.

#73 lore raw

PATCH 52/88 i.MX31: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 hw/misc/imx6_src.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/imx6_src.c +1 -1
index cfb08710fb..9342bce6de 100644
@@ -149,7 +149,7 @@ static void imx6_defer_clear_reset_bit(int cpuid,
         return;
     }
 
-    ri = g_malloc(sizeof(struct SRCSCRResetInfo));
+    ri = g_new(struct SRCSCRResetInfo, 1);
     ri->s = s;
     ri->reset_bit = reset_shift;
 
Signature · 1 line
2.14.2
#74 lore raw

PATCH 53/88 iSCSI: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 block/iscsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/iscsi.c +1 -1
index 4683f3b244..f9f910168d 100644
@@ -1001,7 +1001,7 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
         return NULL;
     }
 
-    acb->task = malloc(sizeof(struct scsi_task));
+    acb->task = g_new(struct scsi_task, 1);
     if (acb->task == NULL) {
         error_report("iSCSI: Failed to allocate task for scsi command. %s",
                      iscsi_get_error(iscsi));
Signature · 1 line
2.14.2
#75 lore raw

PATCH 54/88 KVM: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 accel/kvm/kvm-all.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
accel/kvm/kvm-all.c +4 -4
index 90c88b517d..12568d703c 100644
@@ -278,7 +278,7 @@ int kvm_destroy_vcpu(CPUState *cpu)
         goto err;
     }
 
-    vcpu = g_malloc0(sizeof(*vcpu));
+    vcpu = g_new0(struct KVMParkedVcpu, 1);
     vcpu->vcpu_id = kvm_arch_vcpu_id(cpu);
     vcpu->kvm_fd = cpu->kvm_fd;
     QLIST_INSERT_HEAD(&kvm_state->kvm_parked_vcpus, vcpu, node);
@@ -865,7 +865,7 @@ void kvm_memory_listener_register(KVMState *s, KVMMemoryListener *kml,
 {
     int i;
 
-    kml->slots = g_malloc0(s->nr_slots * sizeof(KVMSlot));
+    kml->slots = g_new0(KVMSlot, s->nr_slots);
     kml->as_id = as_id;
 
     for (i = 0; i < s->nr_slots; i++) {
@@ -1129,7 +1129,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg)
             return virq;
         }
 
-        route = g_malloc0(sizeof(KVMMSIRoute));
+        route = g_new0(KVMMSIRoute, 1);
         route->kroute.gsi = virq;
         route->kroute.type = KVM_IRQ_ROUTING_MSI;
         route->kroute.flags = 0;
@@ -2243,7 +2243,7 @@ int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
             return 0;
         }
 
-        bp = g_malloc(sizeof(struct kvm_sw_breakpoint));
+        bp = g_new(struct kvm_sw_breakpoint, 1);
         bp->pc = addr;
         bp->use_count = 1;
         err = kvm_arch_insert_sw_breakpoint(cpu, bp);
Signature · 1 line
2.14.2
Reviewed-by on v1 54/88
#76 lore raw

Re: [PATCH 54/88] KVM: use g_new() family of functions

Quoted 52 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 accel/kvm/kvm-all.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
accel/kvm/kvm-all.c +4 -4
index 90c88b517d..12568d703c 100644
@@ -278,7 +278,7 @@ int kvm_destroy_vcpu(CPUState *cpu)
         goto err;
     }
 
-    vcpu = g_malloc0(sizeof(*vcpu));
+    vcpu = g_new0(struct KVMParkedVcpu, 1);
     vcpu->vcpu_id = kvm_arch_vcpu_id(cpu);
     vcpu->kvm_fd = cpu->kvm_fd;
     QLIST_INSERT_HEAD(&kvm_state->kvm_parked_vcpus, vcpu, node);
@@ -865,7 +865,7 @@ void kvm_memory_listener_register(KVMState *s, KVMMemoryListener *kml,
 {
     int i;
 
-    kml->slots = g_malloc0(s->nr_slots * sizeof(KVMSlot));
+    kml->slots = g_new0(KVMSlot, s->nr_slots);
     kml->as_id = as_id;
 
     for (i = 0; i < s->nr_slots; i++) {
@@ -1129,7 +1129,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg)
             return virq;
         }
 
-        route = g_malloc0(sizeof(KVMMSIRoute));
+        route = g_new0(KVMMSIRoute, 1);
         route->kroute.gsi = virq;
         route->kroute.type = KVM_IRQ_ROUTING_MSI;
         route->kroute.flags = 0;
@@ -2243,7 +2243,7 @@ int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
             return 0;
         }
 
-        bp = g_malloc(sizeof(struct kvm_sw_breakpoint));
+        bp = g_new(struct kvm_sw_breakpoint, 1);
         bp->pc = addr;
         bp->use_count = 1;
         err = kvm_arch_insert_sw_breakpoint(cpu, bp);
Signature · 1 line
2.14.2
#77 lore raw

PATCH 55/88 PReP: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 hw/ppc/prep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/prep.c +1 -1
index 94138a4e8c..c638d3d17a 100644
@@ -512,7 +512,7 @@ static void ppc_prep_init(MachineState *machine)
     int ppc_boot_device;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
 
-    sysctrl = g_malloc0(sizeof(sysctrl_t));
+    sysctrl = g_new0(sysctrl_t, 1);
 
     linux_boot = (kernel_filename != NULL);
 
Signature · 1 line
2.14.2
Acked-by on v1 55/88
#78 lore raw

Re: [Qemu-devel] [PATCH 55/88] PReP: use g_new() family of functions

Quoted 3 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

Quoted 17 lines
---
 hw/ppc/prep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/prep.c +1 -1
index 94138a4e8c..c638d3d17a 100644
@@ -512,7 +512,7 @@ static void ppc_prep_init(MachineState *machine)
     int ppc_boot_device;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
 
-    sysctrl = g_malloc0(sizeof(sysctrl_t));
+    sysctrl = g_new0(sysctrl_t, 1);
 
     linux_boot = (kernel_filename != NULL);
 
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#79 lore raw

PATCH 56/88 PowerPC: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: one more change in target/ppc/translate_init.c, added target/ppc/kvm.c]
---
 hw/ppc/ppc.c                |  8 ++++----
 hw/ppc/ppc_booke.c          |  4 ++--
 target/ppc/kvm.c            |  2 +-
 target/ppc/translate_init.c | 14 +++++++-------
 4 files changed, 14 insertions(+), 14 deletions(-)
hw/ppc/ppc.c +4 -4
index 05da316e0b..647d70fc13 100644
@@ -965,7 +965,7 @@ clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t freq)
     PowerPCCPU *cpu = ppc_env_get_cpu(env);
     ppc_tb_t *tb_env;
 
-    tb_env = g_malloc0(sizeof(ppc_tb_t));
+    tb_env = g_new0(ppc_tb_t, 1);
     env->tb_env = tb_env;
     tb_env->flags = PPC_DECR_UNDERFLOW_TRIGGERED;
     if (env->insns_flags & PPC_SEGMENT_64B) {
@@ -1224,10 +1224,10 @@ clk_setup_cb ppc_40x_timers_init (CPUPPCState *env, uint32_t freq,
     ppc_tb_t *tb_env;
     ppc40x_timer_t *ppc40x_timer;
 
-    tb_env = g_malloc0(sizeof(ppc_tb_t));
+    tb_env = g_new0(ppc_tb_t, 1);
     env->tb_env = tb_env;
     tb_env->flags = PPC_DECR_UNDERFLOW_TRIGGERED;
-    ppc40x_timer = g_malloc0(sizeof(ppc40x_timer_t));
+    ppc40x_timer = g_new0(ppc40x_timer_t, 1);
     tb_env->tb_freq = freq;
     tb_env->decr_freq = freq;
     tb_env->opaque = ppc40x_timer;
@@ -1332,7 +1332,7 @@ int ppc_dcr_init (CPUPPCState *env, int (*read_error)(int dcrn),
 {
     ppc_dcr_t *dcr_env;
 
-    dcr_env = g_malloc0(sizeof(ppc_dcr_t));
+    dcr_env = g_new0(ppc_dcr_t, 1);
     dcr_env->read_error = read_error;
     dcr_env->write_error = write_error;
     env->dcr_env = dcr_env;
hw/ppc/ppc_booke.c +2 -2
index 23bcf1b138..dafc6aa3fc 100644
@@ -339,8 +339,8 @@ void ppc_booke_timers_init(PowerPCCPU *cpu, uint32_t freq, uint32_t flags)
     booke_timer_t *booke_timer;
     int ret = 0;
 
-    tb_env      = g_malloc0(sizeof(ppc_tb_t));
-    booke_timer = g_malloc0(sizeof(booke_timer_t));
+    tb_env      = g_new0(ppc_tb_t, 1);
+    booke_timer = g_new0(booke_timer_t, 1);
 
     cpu->env.tb_env = tb_env;
     tb_env->flags = flags | PPC_TIMER_BOOKE | PPC_DECR_ZERO_TRIGGERED;
target/ppc/kvm.c +1 -1
index 171d3d8040..d8565fd4a3 100644
@@ -364,7 +364,7 @@ struct ppc_radix_page_info *kvm_get_radix_page_info(void)
     if (kvm_vm_ioctl(s, KVM_PPC_GET_RMMU_INFO, &rmmu_info)) {
         return NULL;
     }
-    radix_page_info = g_malloc0(sizeof(*radix_page_info));
+    radix_page_info = g_new0(struct ppc_radix_page_info, 1);
     radix_page_info->count = 0;
     for (i = 0; i < PPC_PAGE_SIZES_MAX_SZ; i++) {
         if (rmmu_info.ap_encodings[i]) {
target/ppc/translate_init.c +7 -7
index c6399a3a0d..850ff038ca 100644
@@ -9341,13 +9341,13 @@ static void init_ppc_proc(PowerPCCPU *cpu)
             nb_tlb *= 2;
         switch (env->tlb_type) {
         case TLB_6XX:
-            env->tlb.tlb6 = g_malloc0(nb_tlb * sizeof(ppc6xx_tlb_t));
+            env->tlb.tlb6 = g_new0(ppc6xx_tlb_t, nb_tlb);
             break;
         case TLB_EMB:
-            env->tlb.tlbe = g_malloc0(nb_tlb * sizeof(ppcemb_tlb_t));
+            env->tlb.tlbe = g_new0(ppcemb_tlb_t, nb_tlb);
             break;
         case TLB_MAS:
-            env->tlb.tlbm = g_malloc0(nb_tlb * sizeof(ppcmas_tlb_t));
+            env->tlb.tlbm = g_new0(ppcmas_tlb_t, nb_tlb);
             break;
         }
         /* Pre-compute some useful values */
@@ -10442,11 +10442,11 @@ static void ppc_cpu_defs_entry(gpointer data, gpointer user_data)
     }
 
     typename = object_class_get_name(oc);
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(CpuDefinitionInfo, 1);
     info->name = g_strndup(typename,
                            strlen(typename) - strlen(POWERPC_CPU_TYPE_SUFFIX));
 
-    entry = g_malloc0(sizeof(*entry));
+    entry = g_new0(CpuDefinitionInfoList, 1);
     entry->value = info;
     entry->next = *first;
     *first = entry;
@@ -10473,11 +10473,11 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
             continue;
         }
 
-        info = g_malloc0(sizeof(*info));
+        info = g_new0(CpuDefinitionInfo, 1);
         info->name = g_strdup(alias->alias);
         info->q_typename = g_strdup(object_class_get_name(oc));
 
-        entry = g_malloc0(sizeof(*entry));
+        entry = g_new0(CpuDefinitionInfoList, 1);
         entry->value = info;
         entry->next = cpu_list;
         cpu_list = entry;
Signature · 1 line
2.14.2
Acked-by on v1 56/88
#80 lore raw

Re: [Qemu-devel] [PATCH 56/88] PowerPC: use g_new() family of functions

Quoted 6 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: one more change in target/ppc/translate_init.c, added target/ppc/kvm.c]

Quoted 119 lines
---
 hw/ppc/ppc.c                |  8 ++++----
 hw/ppc/ppc_booke.c          |  4 ++--
 target/ppc/kvm.c            |  2 +-
 target/ppc/translate_init.c | 14 +++++++-------
 4 files changed, 14 insertions(+), 14 deletions(-)
hw/ppc/ppc.c +4 -4
index 05da316e0b..647d70fc13 100644
@@ -965,7 +965,7 @@ clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t freq)
     PowerPCCPU *cpu = ppc_env_get_cpu(env);
     ppc_tb_t *tb_env;
 
-    tb_env = g_malloc0(sizeof(ppc_tb_t));
+    tb_env = g_new0(ppc_tb_t, 1);
     env->tb_env = tb_env;
     tb_env->flags = PPC_DECR_UNDERFLOW_TRIGGERED;
     if (env->insns_flags & PPC_SEGMENT_64B) {
@@ -1224,10 +1224,10 @@ clk_setup_cb ppc_40x_timers_init (CPUPPCState *env, uint32_t freq,
     ppc_tb_t *tb_env;
     ppc40x_timer_t *ppc40x_timer;
 
-    tb_env = g_malloc0(sizeof(ppc_tb_t));
+    tb_env = g_new0(ppc_tb_t, 1);
     env->tb_env = tb_env;
     tb_env->flags = PPC_DECR_UNDERFLOW_TRIGGERED;
-    ppc40x_timer = g_malloc0(sizeof(ppc40x_timer_t));
+    ppc40x_timer = g_new0(ppc40x_timer_t, 1);
     tb_env->tb_freq = freq;
     tb_env->decr_freq = freq;
     tb_env->opaque = ppc40x_timer;
@@ -1332,7 +1332,7 @@ int ppc_dcr_init (CPUPPCState *env, int (*read_error)(int dcrn),
 {
     ppc_dcr_t *dcr_env;
 
-    dcr_env = g_malloc0(sizeof(ppc_dcr_t));
+    dcr_env = g_new0(ppc_dcr_t, 1);
     dcr_env->read_error = read_error;
     dcr_env->write_error = write_error;
     env->dcr_env = dcr_env;
hw/ppc/ppc_booke.c +2 -2
index 23bcf1b138..dafc6aa3fc 100644
@@ -339,8 +339,8 @@ void ppc_booke_timers_init(PowerPCCPU *cpu, uint32_t freq, uint32_t flags)
     booke_timer_t *booke_timer;
     int ret = 0;
 
-    tb_env      = g_malloc0(sizeof(ppc_tb_t));
-    booke_timer = g_malloc0(sizeof(booke_timer_t));
+    tb_env      = g_new0(ppc_tb_t, 1);
+    booke_timer = g_new0(booke_timer_t, 1);
 
     cpu->env.tb_env = tb_env;
     tb_env->flags = flags | PPC_TIMER_BOOKE | PPC_DECR_ZERO_TRIGGERED;
target/ppc/kvm.c +1 -1
index 171d3d8040..d8565fd4a3 100644
@@ -364,7 +364,7 @@ struct ppc_radix_page_info *kvm_get_radix_page_info(void)
     if (kvm_vm_ioctl(s, KVM_PPC_GET_RMMU_INFO, &rmmu_info)) {
         return NULL;
     }
-    radix_page_info = g_malloc0(sizeof(*radix_page_info));
+    radix_page_info = g_new0(struct ppc_radix_page_info, 1);
     radix_page_info->count = 0;
     for (i = 0; i < PPC_PAGE_SIZES_MAX_SZ; i++) {
         if (rmmu_info.ap_encodings[i]) {
target/ppc/translate_init.c +7 -7
index c6399a3a0d..850ff038ca 100644
@@ -9341,13 +9341,13 @@ static void init_ppc_proc(PowerPCCPU *cpu)
             nb_tlb *= 2;
         switch (env->tlb_type) {
         case TLB_6XX:
-            env->tlb.tlb6 = g_malloc0(nb_tlb * sizeof(ppc6xx_tlb_t));
+            env->tlb.tlb6 = g_new0(ppc6xx_tlb_t, nb_tlb);
             break;
         case TLB_EMB:
-            env->tlb.tlbe = g_malloc0(nb_tlb * sizeof(ppcemb_tlb_t));
+            env->tlb.tlbe = g_new0(ppcemb_tlb_t, nb_tlb);
             break;
         case TLB_MAS:
-            env->tlb.tlbm = g_malloc0(nb_tlb * sizeof(ppcmas_tlb_t));
+            env->tlb.tlbm = g_new0(ppcmas_tlb_t, nb_tlb);
             break;
         }
         /* Pre-compute some useful values */
@@ -10442,11 +10442,11 @@ static void ppc_cpu_defs_entry(gpointer data, gpointer user_data)
     }
 
     typename = object_class_get_name(oc);
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(CpuDefinitionInfo, 1);
     info->name = g_strndup(typename,
                            strlen(typename) - strlen(POWERPC_CPU_TYPE_SUFFIX));
 
-    entry = g_malloc0(sizeof(*entry));
+    entry = g_new0(CpuDefinitionInfoList, 1);
     entry->value = info;
     entry->next = *first;
     *first = entry;
@@ -10473,11 +10473,11 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
             continue;
         }
 
-        info = g_malloc0(sizeof(*info));
+        info = g_new0(CpuDefinitionInfo, 1);
         info->name = g_strdup(alias->alias);
         info->q_typename = g_strdup(object_class_get_name(oc));
 
-        entry = g_malloc0(sizeof(*entry));
+        entry = g_new0(CpuDefinitionInfoList, 1);
         entry->value = info;
         entry->next = cpu_list;
         cpu_list = entry;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#81 lore raw

PATCH 57/88 ppc: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: replaced g_new0() -> g_new() in mac_newworld.c, added virtex_ml507]
---
 hw/intc/heathrow_pic.c | 2 +-
 hw/ppc/mac_newworld.c  | 5 ++---
 hw/ppc/mac_oldworld.c  | 2 +-
 hw/ppc/virtex_ml507.c  | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)
hw/intc/heathrow_pic.c +1 -1
index 171f5ed814..90c1e6a4b1 100644
@@ -201,7 +201,7 @@ qemu_irq *heathrow_pic_init(MemoryRegion **pmem,
 {
     HeathrowPICS *s;
 
-    s = g_malloc0(sizeof(HeathrowPICS));
+    s = g_new0(HeathrowPICS, 1);
     /* only 1 CPU */
     s->irqs = irqs[0];
     memory_region_init_io(&s->mem, NULL, &heathrow_pic_ops, s,
hw/ppc/mac_newworld.c +2 -3
index 6d0ace20ca..59cded95b8 100644
@@ -295,7 +295,7 @@ static void ppc_core99_init(MachineState *machine)
     memory_region_init_io(unin2_memory, NULL, &unin_ops, token, "unin", 0x1000);
     memory_region_add_subregion(get_system_memory(), 0xf3000000, unin2_memory);
 
-    openpic_irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
+    openpic_irqs = g_new0(qemu_irq *, smp_cpus);
     openpic_irqs[0] =
         g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
     for (i = 0; i < smp_cpus; i++) {
@@ -339,8 +339,6 @@ static void ppc_core99_init(MachineState *machine)
         }
     }
 
-    pic = g_new0(qemu_irq, 64);
-
     dev = qdev_create(NULL, TYPE_OPENPIC);
     qdev_prop_set_uint32(dev, "model", OPENPIC_MODEL_KEYLARGO);
     qdev_init_nofail(dev);
@@ -353,6 +351,7 @@ static void ppc_core99_init(MachineState *machine)
         }
     }
 
+    pic = g_new(qemu_irq, 64);
     for (i = 0; i < 64; i++) {
         pic[i] = qdev_get_gpio_in(dev, i);
     }
hw/ppc/mac_oldworld.c +1 -1
index bc7c8b7bd7..50ad9c56cb 100644
@@ -232,7 +232,7 @@ static void ppc_heathrow_init(MachineState *machine)
     memory_region_add_subregion(sysmem, 0xfe000000, isa);
 
     /* XXX: we register only 1 output pin for heathrow PIC */
-    heathrow_irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
+    heathrow_irqs = g_new0(qemu_irq *, smp_cpus);
     heathrow_irqs[0] =
         g_malloc0(smp_cpus * sizeof(qemu_irq) * 1);
     /* Connect the heathrow PIC outputs to the 6xx bus */
hw/ppc/virtex_ml507.c +1 -1
index ed9b406fd3..ed6e054611 100644
@@ -104,7 +104,7 @@ static PowerPCCPU *ppc440_init_xilinx(ram_addr_t *ram_size,
     ppc_dcr_init(env, NULL, NULL);
 
     /* interrupt controller */
-    irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+    irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
     irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
     irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
     ppcuic_init(env, irqs, 0x0C0, 0, 1);
Signature · 1 line
2.14.2
Acked-by on v1 57/88
#82 lore raw

Re: [Qemu-devel] [PATCH 57/88] ppc: use g_new() family of functions

Quoted 6 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: replaced g_new0() -> g_new() in mac_newworld.c, added virtex_ml507]

Quoted 76 lines
---
 hw/intc/heathrow_pic.c | 2 +-
 hw/ppc/mac_newworld.c  | 5 ++---
 hw/ppc/mac_oldworld.c  | 2 +-
 hw/ppc/virtex_ml507.c  | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)
hw/intc/heathrow_pic.c +1 -1
index 171f5ed814..90c1e6a4b1 100644
@@ -201,7 +201,7 @@ qemu_irq *heathrow_pic_init(MemoryRegion **pmem,
 {
     HeathrowPICS *s;
 
-    s = g_malloc0(sizeof(HeathrowPICS));
+    s = g_new0(HeathrowPICS, 1);
     /* only 1 CPU */
     s->irqs = irqs[0];
     memory_region_init_io(&s->mem, NULL, &heathrow_pic_ops, s,
hw/ppc/mac_newworld.c +2 -3
index 6d0ace20ca..59cded95b8 100644
@@ -295,7 +295,7 @@ static void ppc_core99_init(MachineState *machine)
     memory_region_init_io(unin2_memory, NULL, &unin_ops, token, "unin", 0x1000);
     memory_region_add_subregion(get_system_memory(), 0xf3000000, unin2_memory);
 
-    openpic_irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
+    openpic_irqs = g_new0(qemu_irq *, smp_cpus);
     openpic_irqs[0] =
         g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
     for (i = 0; i < smp_cpus; i++) {
@@ -339,8 +339,6 @@ static void ppc_core99_init(MachineState *machine)
         }
     }
 
-    pic = g_new0(qemu_irq, 64);
-
     dev = qdev_create(NULL, TYPE_OPENPIC);
     qdev_prop_set_uint32(dev, "model", OPENPIC_MODEL_KEYLARGO);
     qdev_init_nofail(dev);
@@ -353,6 +351,7 @@ static void ppc_core99_init(MachineState *machine)
         }
     }
 
+    pic = g_new(qemu_irq, 64);
     for (i = 0; i < 64; i++) {
         pic[i] = qdev_get_gpio_in(dev, i);
     }
hw/ppc/mac_oldworld.c +1 -1
index bc7c8b7bd7..50ad9c56cb 100644
@@ -232,7 +232,7 @@ static void ppc_heathrow_init(MachineState *machine)
     memory_region_add_subregion(sysmem, 0xfe000000, isa);
 
     /* XXX: we register only 1 output pin for heathrow PIC */
-    heathrow_irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
+    heathrow_irqs = g_new0(qemu_irq *, smp_cpus);
     heathrow_irqs[0] =
         g_malloc0(smp_cpus * sizeof(qemu_irq) * 1);
     /* Connect the heathrow PIC outputs to the 6xx bus */
hw/ppc/virtex_ml507.c +1 -1
index ed9b406fd3..ed6e054611 100644
@@ -104,7 +104,7 @@ static PowerPCCPU *ppc440_init_xilinx(ram_addr_t *ram_size,
     ppc_dcr_init(env, NULL, NULL);
 
     /* interrupt controller */
-    irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+    irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
     irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
     irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
     ppcuic_init(env, irqs, 0x0C0, 0, 1);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#83 lore raw

PATCH 58/88 ppc4xx: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: added more changes in hw/ppc/ppc405_uc.c and hw/ppc/ppc4xx_devs.c]
---
 hw/ppc/ppc405_boards.c |  4 ++--
 hw/ppc/ppc405_uc.c     | 24 ++++++++++++------------
 hw/ppc/ppc440_bamboo.c |  2 +-
 hw/ppc/ppc4xx_devs.c   |  6 +++---
 4 files changed, 18 insertions(+), 18 deletions(-)
hw/ppc/ppc405_boards.c +2 -2
index e92db2c66a..a812985baa 100644
@@ -169,7 +169,7 @@ static void ref405ep_fpga_init(MemoryRegion *sysmem, uint32_t base)
     ref405ep_fpga_t *fpga;
     MemoryRegion *fpga_memory = g_new(MemoryRegion, 1);
 
-    fpga = g_malloc0(sizeof(ref405ep_fpga_t));
+    fpga = g_new0(ref405ep_fpga_t, 1);
     memory_region_init_io(fpga_memory, NULL, &ref405ep_fpga_ops, fpga,
                           "fpga", 0x00000100);
     memory_region_add_subregion(sysmem, base, fpga_memory);
@@ -472,7 +472,7 @@ static void taihu_cpld_init(MemoryRegion *sysmem, uint32_t base)
     taihu_cpld_t *cpld;
     MemoryRegion *cpld_memory = g_new(MemoryRegion, 1);
 
-    cpld = g_malloc0(sizeof(taihu_cpld_t));
+    cpld = g_new0(taihu_cpld_t, 1);
     memory_region_init_io(cpld_memory, NULL, &taihu_cpld_ops, cpld, "cpld", 0x100);
     memory_region_add_subregion(sysmem, base, cpld_memory);
     qemu_register_reset(&taihu_cpld_reset, cpld);
hw/ppc/ppc405_uc.c +12 -12
index 8e58065f5f..02ab2a24ff 100644
@@ -181,7 +181,7 @@ void ppc4xx_plb_init(CPUPPCState *env)
 {
     ppc4xx_plb_t *plb;
 
-    plb = g_malloc0(sizeof(ppc4xx_plb_t));
+    plb = g_new0(ppc4xx_plb_t, 1);
     ppc_dcr_register(env, PLB3A0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
     ppc_dcr_register(env, PLB4A0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
     ppc_dcr_register(env, PLB0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
@@ -266,7 +266,7 @@ static void ppc4xx_pob_init(CPUPPCState *env)
 {
     ppc4xx_pob_t *pob;
 
-    pob = g_malloc0(sizeof(ppc4xx_pob_t));
+    pob = g_new0(ppc4xx_pob_t, 1);
     ppc_dcr_register(env, POB0_BEAR, pob, &dcr_read_pob, &dcr_write_pob);
     ppc_dcr_register(env, POB0_BESR0, pob, &dcr_read_pob, &dcr_write_pob);
     ppc_dcr_register(env, POB0_BESR1, pob, &dcr_read_pob, &dcr_write_pob);
@@ -397,7 +397,7 @@ static void ppc4xx_opba_init(hwaddr base)
 {
     ppc4xx_opba_t *opba;
 
-    opba = g_malloc0(sizeof(ppc4xx_opba_t));
+    opba = g_new0(ppc4xx_opba_t, 1);
 #ifdef DEBUG_OPBA
     printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
 #endif
@@ -595,7 +595,7 @@ void ppc405_ebc_init(CPUPPCState *env)
 {
     ppc4xx_ebc_t *ebc;
 
-    ebc = g_malloc0(sizeof(ppc4xx_ebc_t));
+    ebc = g_new0(ppc4xx_ebc_t, 1);
     qemu_register_reset(&ebc_reset, ebc);
     ppc_dcr_register(env, EBC0_CFGADDR,
                      ebc, &dcr_read_ebc, &dcr_write_ebc);
@@ -678,7 +678,7 @@ static void ppc405_dma_init(CPUPPCState *env, qemu_irq irqs[4])
 {
     ppc405_dma_t *dma;
 
-    dma = g_malloc0(sizeof(ppc405_dma_t));
+    dma = g_new0(ppc405_dma_t, 1);
     memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq));
     qemu_register_reset(&ppc405_dma_reset, dma);
     ppc_dcr_register(env, DMA0_CR0,
@@ -819,7 +819,7 @@ static void ppc405_gpio_init(hwaddr base)
 {
     ppc405_gpio_t *gpio;
 
-    gpio = g_malloc0(sizeof(ppc405_gpio_t));
+    gpio = g_new0(ppc405_gpio_t, 1);
 #ifdef DEBUG_GPIO
     printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
 #endif
@@ -981,7 +981,7 @@ static void ppc405_ocm_init(CPUPPCState *env)
 {
     ppc405_ocm_t *ocm;
 
-    ocm = g_malloc0(sizeof(ppc405_ocm_t));
+    ocm = g_new0(ppc405_ocm_t, 1);
     /* XXX: Size is 4096 or 0x04000000 */
     memory_region_init_ram(&ocm->isarc_ram, NULL, "ppc405.ocm", 4096,
                            &error_fatal);
@@ -1264,7 +1264,7 @@ static void ppc4xx_gpt_init(hwaddr base, qemu_irq irqs[5])
     ppc4xx_gpt_t *gpt;
     int i;
 
-    gpt = g_malloc0(sizeof(ppc4xx_gpt_t));
+    gpt = g_new0(ppc4xx_gpt_t, 1);
     for (i = 0; i < 5; i++) {
         gpt->irqs[i] = irqs[i];
     }
@@ -1590,7 +1590,7 @@ static void ppc405cr_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[7],
 {
     ppc405cr_cpc_t *cpc;
 
-    cpc = g_malloc0(sizeof(ppc405cr_cpc_t));
+    cpc = g_new0(ppc405cr_cpc_t, 1);
     memcpy(cpc->clk_setup, clk_setup,
            PPC405CR_CLK_NB * sizeof(clk_setup_t));
     cpc->sysclk = sysclk;
@@ -1640,7 +1640,7 @@ CPUPPCState *ppc405cr_init(MemoryRegion *address_space_mem,
     /* OBP arbitrer */
     ppc4xx_opba_init(0xef600600);
     /* Universal interrupt controller */
-    irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+    irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
     irqs[PPCUIC_OUTPUT_INT] =
         ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
     irqs[PPCUIC_OUTPUT_CINT] =
@@ -1934,7 +1934,7 @@ static void ppc405ep_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[8],
 {
     ppc405ep_cpc_t *cpc;
 
-    cpc = g_malloc0(sizeof(ppc405ep_cpc_t));
+    cpc = g_new0(ppc405ep_cpc_t, 1);
     memcpy(cpc->clk_setup, clk_setup,
            PPC405EP_CLK_NB * sizeof(clk_setup_t));
     cpc->jtagid = 0x20267049;
@@ -1997,7 +1997,7 @@ CPUPPCState *ppc405ep_init(MemoryRegion *address_space_mem,
     /* Initialize timers */
     ppc_booke_timers_init(cpu, sysclk, 0);
     /* Universal interrupt controller */
-    irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+    irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
     irqs[PPCUIC_OUTPUT_INT] =
         ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
     irqs[PPCUIC_OUTPUT_CINT] =
hw/ppc/ppc440_bamboo.c +1 -1
index f92d47f28d..f55071abaf 100644
@@ -200,7 +200,7 @@ static void bamboo_init(MachineState *machine)
     ppc_dcr_init(env, NULL, NULL);
 
     /* interrupt controller */
-    irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+    irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
     irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
     irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
     pic = ppcuic_init(env, irqs, 0x0C0, 0, 1);
hw/ppc/ppc4xx_devs.c +3 -3
index 6d7f7857fe..a5ea8f8a63 100644
@@ -300,7 +300,7 @@ qemu_irq *ppcuic_init (CPUPPCState *env, qemu_irq *irqs,
     ppcuic_t *uic;
     int i;
 
-    uic = g_malloc0(sizeof(ppcuic_t));
+    uic = g_new0(ppcuic_t, 1);
     uic->dcr_base = dcr_base;
     uic->irqs = irqs;
     if (has_vr)
@@ -648,7 +648,7 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,
 {
     ppc4xx_sdram_t *sdram;
 
-    sdram = g_malloc0(sizeof(ppc4xx_sdram_t));
+    sdram = g_new0(ppc4xx_sdram_t, 1);
     sdram->irq = irq;
     sdram->nbanks = nbanks;
     sdram->ram_memories = ram_memories;
@@ -911,7 +911,7 @@ void ppc4xx_mal_init(CPUPPCState *env, uint8_t txcnum, uint8_t rxcnum,
     int i;
 
     assert(txcnum <= 32 && rxcnum <= 32);
-    mal = g_malloc0(sizeof(*mal));
+    mal = g_new0(ppc4xx_mal_t, 1);
     mal->txcnum = txcnum;
     mal->rxcnum = rxcnum;
     mal->txctpr = g_new0(uint32_t, txcnum);
Signature · 1 line
2.14.2
Acked-by on v1 58/88
#84 lore raw

Re: [Qemu-devel] [PATCH 58/88] ppc4xx: use g_new() family of functions

Quoted 5 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: added more changes in hw/ppc/ppc405_uc.c and hw/ppc/ppc4xx_devs.c]
Quoted 185 lines
---
 hw/ppc/ppc405_boards.c |  4 ++--
 hw/ppc/ppc405_uc.c     | 24 ++++++++++++------------
 hw/ppc/ppc440_bamboo.c |  2 +-
 hw/ppc/ppc4xx_devs.c   |  6 +++---
 4 files changed, 18 insertions(+), 18 deletions(-)
hw/ppc/ppc405_boards.c +2 -2
index e92db2c66a..a812985baa 100644
@@ -169,7 +169,7 @@ static void ref405ep_fpga_init(MemoryRegion *sysmem, uint32_t base)
     ref405ep_fpga_t *fpga;
     MemoryRegion *fpga_memory = g_new(MemoryRegion, 1);
 
-    fpga = g_malloc0(sizeof(ref405ep_fpga_t));
+    fpga = g_new0(ref405ep_fpga_t, 1);
     memory_region_init_io(fpga_memory, NULL, &ref405ep_fpga_ops, fpga,
                           "fpga", 0x00000100);
     memory_region_add_subregion(sysmem, base, fpga_memory);
@@ -472,7 +472,7 @@ static void taihu_cpld_init(MemoryRegion *sysmem, uint32_t base)
     taihu_cpld_t *cpld;
     MemoryRegion *cpld_memory = g_new(MemoryRegion, 1);
 
-    cpld = g_malloc0(sizeof(taihu_cpld_t));
+    cpld = g_new0(taihu_cpld_t, 1);
     memory_region_init_io(cpld_memory, NULL, &taihu_cpld_ops, cpld, "cpld", 0x100);
     memory_region_add_subregion(sysmem, base, cpld_memory);
     qemu_register_reset(&taihu_cpld_reset, cpld);
hw/ppc/ppc405_uc.c +12 -12
index 8e58065f5f..02ab2a24ff 100644
@@ -181,7 +181,7 @@ void ppc4xx_plb_init(CPUPPCState *env)
 {
     ppc4xx_plb_t *plb;
 
-    plb = g_malloc0(sizeof(ppc4xx_plb_t));
+    plb = g_new0(ppc4xx_plb_t, 1);
     ppc_dcr_register(env, PLB3A0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
     ppc_dcr_register(env, PLB4A0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
     ppc_dcr_register(env, PLB0_ACR, plb, &dcr_read_plb, &dcr_write_plb);
@@ -266,7 +266,7 @@ static void ppc4xx_pob_init(CPUPPCState *env)
 {
     ppc4xx_pob_t *pob;
 
-    pob = g_malloc0(sizeof(ppc4xx_pob_t));
+    pob = g_new0(ppc4xx_pob_t, 1);
     ppc_dcr_register(env, POB0_BEAR, pob, &dcr_read_pob, &dcr_write_pob);
     ppc_dcr_register(env, POB0_BESR0, pob, &dcr_read_pob, &dcr_write_pob);
     ppc_dcr_register(env, POB0_BESR1, pob, &dcr_read_pob, &dcr_write_pob);
@@ -397,7 +397,7 @@ static void ppc4xx_opba_init(hwaddr base)
 {
     ppc4xx_opba_t *opba;
 
-    opba = g_malloc0(sizeof(ppc4xx_opba_t));
+    opba = g_new0(ppc4xx_opba_t, 1);
 #ifdef DEBUG_OPBA
     printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
 #endif
@@ -595,7 +595,7 @@ void ppc405_ebc_init(CPUPPCState *env)
 {
     ppc4xx_ebc_t *ebc;
 
-    ebc = g_malloc0(sizeof(ppc4xx_ebc_t));
+    ebc = g_new0(ppc4xx_ebc_t, 1);
     qemu_register_reset(&ebc_reset, ebc);
     ppc_dcr_register(env, EBC0_CFGADDR,
                      ebc, &dcr_read_ebc, &dcr_write_ebc);
@@ -678,7 +678,7 @@ static void ppc405_dma_init(CPUPPCState *env, qemu_irq irqs[4])
 {
     ppc405_dma_t *dma;
 
-    dma = g_malloc0(sizeof(ppc405_dma_t));
+    dma = g_new0(ppc405_dma_t, 1);
     memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq));
     qemu_register_reset(&ppc405_dma_reset, dma);
     ppc_dcr_register(env, DMA0_CR0,
@@ -819,7 +819,7 @@ static void ppc405_gpio_init(hwaddr base)
 {
     ppc405_gpio_t *gpio;
 
-    gpio = g_malloc0(sizeof(ppc405_gpio_t));
+    gpio = g_new0(ppc405_gpio_t, 1);
 #ifdef DEBUG_GPIO
     printf("%s: offset " TARGET_FMT_plx "\n", __func__, base);
 #endif
@@ -981,7 +981,7 @@ static void ppc405_ocm_init(CPUPPCState *env)
 {
     ppc405_ocm_t *ocm;
 
-    ocm = g_malloc0(sizeof(ppc405_ocm_t));
+    ocm = g_new0(ppc405_ocm_t, 1);
     /* XXX: Size is 4096 or 0x04000000 */
     memory_region_init_ram(&ocm->isarc_ram, NULL, "ppc405.ocm", 4096,
                            &error_fatal);
@@ -1264,7 +1264,7 @@ static void ppc4xx_gpt_init(hwaddr base, qemu_irq irqs[5])
     ppc4xx_gpt_t *gpt;
     int i;
 
-    gpt = g_malloc0(sizeof(ppc4xx_gpt_t));
+    gpt = g_new0(ppc4xx_gpt_t, 1);
     for (i = 0; i < 5; i++) {
         gpt->irqs[i] = irqs[i];
     }
@@ -1590,7 +1590,7 @@ static void ppc405cr_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[7],
 {
     ppc405cr_cpc_t *cpc;
 
-    cpc = g_malloc0(sizeof(ppc405cr_cpc_t));
+    cpc = g_new0(ppc405cr_cpc_t, 1);
     memcpy(cpc->clk_setup, clk_setup,
            PPC405CR_CLK_NB * sizeof(clk_setup_t));
     cpc->sysclk = sysclk;
@@ -1640,7 +1640,7 @@ CPUPPCState *ppc405cr_init(MemoryRegion *address_space_mem,
     /* OBP arbitrer */
     ppc4xx_opba_init(0xef600600);
     /* Universal interrupt controller */
-    irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+    irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
     irqs[PPCUIC_OUTPUT_INT] =
         ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
     irqs[PPCUIC_OUTPUT_CINT] =
@@ -1934,7 +1934,7 @@ static void ppc405ep_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[8],
 {
     ppc405ep_cpc_t *cpc;
 
-    cpc = g_malloc0(sizeof(ppc405ep_cpc_t));
+    cpc = g_new0(ppc405ep_cpc_t, 1);
     memcpy(cpc->clk_setup, clk_setup,
            PPC405EP_CLK_NB * sizeof(clk_setup_t));
     cpc->jtagid = 0x20267049;
@@ -1997,7 +1997,7 @@ CPUPPCState *ppc405ep_init(MemoryRegion *address_space_mem,
     /* Initialize timers */
     ppc_booke_timers_init(cpu, sysclk, 0);
     /* Universal interrupt controller */
-    irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+    irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
     irqs[PPCUIC_OUTPUT_INT] =
         ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
     irqs[PPCUIC_OUTPUT_CINT] =
hw/ppc/ppc440_bamboo.c +1 -1
index f92d47f28d..f55071abaf 100644
@@ -200,7 +200,7 @@ static void bamboo_init(MachineState *machine)
     ppc_dcr_init(env, NULL, NULL);
 
     /* interrupt controller */
-    irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
+    irqs = g_new0(qemu_irq, PPCUIC_OUTPUT_NB);
     irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
     irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
     pic = ppcuic_init(env, irqs, 0x0C0, 0, 1);
hw/ppc/ppc4xx_devs.c +3 -3
index 6d7f7857fe..a5ea8f8a63 100644
@@ -300,7 +300,7 @@ qemu_irq *ppcuic_init (CPUPPCState *env, qemu_irq *irqs,
     ppcuic_t *uic;
     int i;
 
-    uic = g_malloc0(sizeof(ppcuic_t));
+    uic = g_new0(ppcuic_t, 1);
     uic->dcr_base = dcr_base;
     uic->irqs = irqs;
     if (has_vr)
@@ -648,7 +648,7 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,
 {
     ppc4xx_sdram_t *sdram;
 
-    sdram = g_malloc0(sizeof(ppc4xx_sdram_t));
+    sdram = g_new0(ppc4xx_sdram_t, 1);
     sdram->irq = irq;
     sdram->nbanks = nbanks;
     sdram->ram_memories = ram_memories;
@@ -911,7 +911,7 @@ void ppc4xx_mal_init(CPUPPCState *env, uint8_t txcnum, uint8_t rxcnum,
     int i;
 
     assert(txcnum <= 32 && rxcnum <= 32);
-    mal = g_malloc0(sizeof(*mal));
+    mal = g_new0(ppc4xx_mal_t, 1);
     mal->txcnum = txcnum;
     mal->rxcnum = rxcnum;
     mal->txctpr = g_new0(uint32_t, txcnum);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#85 lore raw

PATCH 59/88 ppce500: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: replaced g_new0() -> g_new() since no bzero() required]
---
 hw/ppc/e500.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
hw/ppc/e500.c +3 -4
index db0e49ab8f..b396fd1a22 100644
@@ -737,8 +737,6 @@ static qemu_irq *ppce500_init_mpic(MachineState *machine, PPCE500Params *params,
     SysBusDevice *s;
     int i;
 
-    mpic = g_new0(qemu_irq, 256);
-
     if (kvm_enabled()) {
         Error *err = NULL;
 
@@ -756,6 +754,7 @@ static qemu_irq *ppce500_init_mpic(MachineState *machine, PPCE500Params *params,
         dev = ppce500_init_mpic_qemu(params, irqs);
     }
 
+    mpic = g_new(qemu_irq, 256);
     for (i = 0; i < 256; i++) {
         mpic[i] = qdev_get_gpio_in(dev, i);
     }
@@ -808,7 +807,7 @@ void ppce500_init(MachineState *machine, PPCE500Params *params)
         machine->cpu_model = "e500v2_v30";
     }
 
-    irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
+    irqs = g_new0(qemu_irq *, smp_cpus);
     irqs[0] = g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
     for (i = 0; i < smp_cpus; i++) {
         PowerPCCPU *cpu;
@@ -844,7 +843,7 @@ void ppce500_init(MachineState *machine, PPCE500Params *params)
         if (!i) {
             /* Primary CPU */
             struct boot_info *boot_info;
-            boot_info = g_malloc0(sizeof(struct boot_info));
+            boot_info = g_new0(struct boot_info, 1);
             qemu_register_reset(ppce500_cpu_reset, cpu);
             env->load_info = boot_info;
         } else {
Signature · 1 line
2.14.2
Acked-by on v1 59/88
#86 lore raw

Re: [Qemu-devel] [PATCH 59/88] ppce500: use g_new() family of functions

Quoted 5 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: replaced g_new0() -> g_new() since no bzero() required]
Quoted 43 lines
---
 hw/ppc/e500.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
hw/ppc/e500.c +3 -4
index db0e49ab8f..b396fd1a22 100644
@@ -737,8 +737,6 @@ static qemu_irq *ppce500_init_mpic(MachineState *machine, PPCE500Params *params,
     SysBusDevice *s;
     int i;
 
-    mpic = g_new0(qemu_irq, 256);
-
     if (kvm_enabled()) {
         Error *err = NULL;
 
@@ -756,6 +754,7 @@ static qemu_irq *ppce500_init_mpic(MachineState *machine, PPCE500Params *params,
         dev = ppce500_init_mpic_qemu(params, irqs);
     }
 
+    mpic = g_new(qemu_irq, 256);
     for (i = 0; i < 256; i++) {
         mpic[i] = qdev_get_gpio_in(dev, i);
     }
@@ -808,7 +807,7 @@ void ppce500_init(MachineState *machine, PPCE500Params *params)
         machine->cpu_model = "e500v2_v30";
     }
 
-    irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
+    irqs = g_new0(qemu_irq *, smp_cpus);
     irqs[0] = g_malloc0(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
     for (i = 0; i < smp_cpus; i++) {
         PowerPCCPU *cpu;
@@ -844,7 +843,7 @@ void ppce500_init(MachineState *machine, PPCE500Params *params)
         if (!i) {
             /* Primary CPU */
             struct boot_info *boot_info;
-            boot_info = g_malloc0(sizeof(struct boot_info));
+            boot_info = g_new0(struct boot_info, 1);
             qemu_register_reset(ppce500_cpu_reset, cpu);
             env->load_info = boot_info;
         } else {
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#87 lore raw

PATCH 60/88 sPAPR: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: one more change in hw/ppc/spapr_events.c,
added hw/intc/xics_kvm.c and tests/libqos/pci-spapr.c]

---
 hw/intc/xics.c           | 2 +-
 hw/intc/xics_kvm.c       | 4 ++--
 hw/ppc/spapr.c           | 2 +-
 hw/ppc/spapr_events.c    | 4 ++--
 hw/ppc/spapr_iommu.c     | 2 +-
 hw/ppc/spapr_pci.c       | 2 +-
 tests/libqos/pci-spapr.c | 2 +-
 7 files changed, 9 insertions(+), 9 deletions(-)
hw/intc/xics.c +1 -1
index cc9816e7f2..e7e1605a1c 100644
@@ -603,7 +603,7 @@ static void ics_simple_realize(ICSState *ics, Error **errp)
         error_setg(errp, "Number of interrupts needs to be greater 0");
         return;
     }
-    ics->irqs = g_malloc0(ics->nr_irqs * sizeof(ICSIRQState));
+    ics->irqs = g_new0(ICSIRQState, ics->nr_irqs);
     ics->qirqs = qemu_allocate_irqs(ics_simple_set_irq, ics, ics->nr_irqs);
 
     qemu_register_reset(ics_simple_reset, ics);
hw/intc/xics_kvm.c +2 -2
index 3091ad3ac2..e6742b0118 100644
@@ -143,7 +143,7 @@ static void icp_kvm_realize(ICPState *icp, Error **errp)
                    strerror(errno));
         return;
     }
-    enabled_icp = g_malloc(sizeof(*enabled_icp));
+    enabled_icp = g_new(KVMEnabledICP, 1);
     enabled_icp->vcpu_id = vcpu_id;
     QLIST_INSERT_HEAD(&kvm_enabled_icps, enabled_icp, node);
 }
@@ -334,7 +334,7 @@ static void ics_kvm_realize(ICSState *ics, Error **errp)
         error_setg(errp, "Number of interrupts needs to be greater 0");
         return;
     }
-    ics->irqs = g_malloc0(ics->nr_irqs * sizeof(ICSIRQState));
+    ics->irqs = g_new0(ICSIRQState, ics->nr_irqs);
     ics->qirqs = qemu_allocate_irqs(ics_kvm_set_irq, ics, ics->nr_irqs);
 
     qemu_register_reset(ics_kvm_reset, ics);
hw/ppc/spapr.c +1 -1
index ff87f155d5..53492595f2 100644
@@ -2988,7 +2988,7 @@ static sPAPRDIMMState *spapr_pending_dimm_unplugs_add(sPAPRMachineState *spapr,
      */
     ds = spapr_pending_dimm_unplugs_find(spapr, dimm);
     if (!ds) {
-        ds = g_malloc0(sizeof(sPAPRDIMMState));
+        ds = g_new0(sPAPRDIMMState, 1);
         ds->nr_lmbs = nr_lmbs;
         ds->dimm = dimm;
         QTAILQ_INSERT_HEAD(&spapr->pending_dimm_unplugs, ds, next);
hw/ppc/spapr_events.c +2 -2
index e377fc7dde..0ff4c2404f 100644
@@ -437,7 +437,7 @@ static void spapr_powerdown_req(Notifier *n, void *opaque)
     struct epow_extended_log *new_epow;
 
     entry = g_new(sPAPREventLogEntry, 1);
-    new_epow = g_malloc0(sizeof(*new_epow));
+    new_epow = g_new0(struct epow_extended_log, 1);
     entry->extended_log = new_epow;
 
     v6hdr = &new_epow->v6hdr;
@@ -490,7 +490,7 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,
     struct rtas_event_log_v6_hp *hp;
 
     entry = g_new(sPAPREventLogEntry, 1);
-    new_hp = g_malloc0(sizeof(struct hp_extended_log));
+    new_hp = g_new0(struct hp_extended_log, 1);
     entry->extended_log = new_hp;
 
     v6hdr = &new_hp->v6hdr;
hw/ppc/spapr_iommu.c +1 -1
index 5ccd785d5a..36cf3d6908 100644
@@ -93,7 +93,7 @@ static uint64_t *spapr_tce_alloc_table(uint32_t liobn,
 
     if (!table) {
         *fd = -1;
-        table = g_malloc0(nb_table * sizeof(uint64_t));
+        table = g_new0(uint64_t, nb_table);
     }
 
     trace_spapr_iommu_new_table(liobn, table, *fd);
hw/ppc/spapr_pci.c +1 -1
index 5049ced4e8..4ec31f65c5 100644
@@ -1825,7 +1825,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) {
tests/libqos/pci-spapr.c +1 -1
index 2043f1e123..e3816ec29f 100644
@@ -158,7 +158,7 @@ QPCIBus *qpci_init_spapr(QGuestAllocator *alloc)
 {
     QPCIBusSPAPR *ret;
 
-    ret = g_malloc(sizeof(*ret));
+    ret = g_new(QPCIBusSPAPR, 1);
 
     ret->alloc = alloc;
 
Signature · 1 line
2.14.2
#88 lore raw

PATCH 61/88 tests: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: split of some files in other commits of the same series, add libqtest.c]
---
 tests/ahci-test.c     | 4 ++--
 tests/fw_cfg-test.c   | 4 ++--
 tests/libqos/ahci.c   | 2 +-
 tests/libqos/libqos.c | 2 +-
 tests/libqos/malloc.c | 6 +++---
 tests/libqtest.c      | 2 +-
 tests/pc-cpu-test.c   | 2 +-
 7 files changed, 11 insertions(+), 11 deletions(-)
tests/ahci-test.c +2 -2
index 999121bb7c..cb84edc8fb 100644
@@ -155,7 +155,7 @@ static AHCIQState *ahci_vboot(const char *cli, va_list ap)
 {
     AHCIQState *s;
 
-    s = g_malloc0(sizeof(AHCIQState));
+    s = g_new0(AHCIQState, 1);
     s->parent = qtest_pc_vboot(cli, ap);
     alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT);
 
@@ -1806,7 +1806,7 @@ static void create_ahci_io_test(enum IOMode type, enum AddrMode addr,
     char *name;
     AHCIIOTestOptions *opts;
 
-    opts = g_malloc(sizeof(AHCIIOTestOptions));
+    opts = g_new(AHCIIOTestOptions, 1);
     opts->length = len;
     opts->address_type = addr;
     opts->io_type = type;
tests/fw_cfg-test.c +2 -2
index 688342bed5..81f45bdfc8 100644
@@ -79,8 +79,8 @@ static void test_fw_cfg_numa(void)
 
     g_assert_cmpint(qfw_cfg_get_u64(fw_cfg, FW_CFG_NUMA), ==, nb_nodes);
 
-    cpu_mask = g_malloc0(sizeof(uint64_t) * max_cpus);
-    node_mask = g_malloc0(sizeof(uint64_t) * nb_nodes);
+    cpu_mask = g_new0(uint64_t, max_cpus);
+    node_mask = g_new0(uint64_t, nb_nodes);
 
     qfw_cfg_read_data(fw_cfg, cpu_mask, sizeof(uint64_t) * max_cpus);
     qfw_cfg_read_data(fw_cfg, node_mask, sizeof(uint64_t) * nb_nodes);
tests/libqos/ahci.c +1 -1
index 1ca7f456b5..13c0749582 100644
@@ -843,7 +843,7 @@ AHCICommand *ahci_command_create(uint8_t command_name)
     AHCICommand *cmd;
 
     g_assert(props);
-    cmd = g_malloc0(sizeof(AHCICommand));
+    cmd = g_new0(AHCICommand, 1);
     g_assert(!(props->dma && props->pio));
     g_assert(!(props->lba28 && props->lba48));
     g_assert(!(props->read && props->write));
tests/libqos/libqos.c +1 -1
index 6226546c28..991bc1aec2 100644
@@ -17,7 +17,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
 {
     char *cmdline;
 
-    struct QOSState *qs = g_malloc(sizeof(QOSState));
+    struct QOSState *qs = g_new(QOSState, 1);
 
     cmdline = g_strdup_vprintf(cmdline_fmt, ap);
     qs->qts = qtest_start(cmdline);
tests/libqos/malloc.c +3 -3
index b8eff5f495..ac05874b0a 100644
@@ -129,7 +129,7 @@ static MemBlock *mlist_new(uint64_t addr, uint64_t size)
     if (!size) {
         return NULL;
     }
-    block = g_malloc0(sizeof(MemBlock));
+    block = g_new0(MemBlock, 1);
 
     block->addr = addr;
     block->size = size;
@@ -305,8 +305,8 @@ QGuestAllocator *alloc_init(uint64_t start, uint64_t end)
     s->start = start;
     s->end = end;
 
-    s->used = g_malloc(sizeof(MemList));
-    s->free = g_malloc(sizeof(MemList));
+    s->used = g_new(MemList, 1);
+    s->free = g_new(MemList, 1);
     QTAILQ_INIT(s->used);
     QTAILQ_INIT(s->free);
 
tests/libqtest.c +1 -1
index cbd709470b..adf71188b6 100644
@@ -171,7 +171,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     gchar *command;
     const char *qemu_binary = qtest_qemu_binary();
 
-    s = g_malloc(sizeof(*s));
+    s = g_new(QTestState, 1);
 
     socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
     qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
tests/pc-cpu-test.c +1 -1
index c4211a4e85..11d3e810ef 100644
@@ -87,7 +87,7 @@ static void add_pc_test_case(const char *mname)
     if (!g_str_has_prefix(mname, "pc-")) {
         return;
     }
-    data = g_malloc(sizeof(PCTestData));
+    data = g_new(PCTestData, 1);
     data->machine = g_strdup(mname);
     data->cpu_model = "Haswell"; /* 1.3+ theoretically */
     data->sockets = 1;
Signature · 1 line
2.14.2
Reviewed-by on v1 61/88
#89 lore raw

Re: [Qemu-devel] [PATCH 61/88] tests: use g_new() family of functions

Quoted 5 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: split of some files in other commits of the same series, add libqtest.c]
Quoted 9 lines
---
 tests/ahci-test.c     | 4 ++--
 tests/fw_cfg-test.c   | 4 ++--
 tests/libqos/ahci.c   | 2 +-
 tests/libqos/libqos.c | 2 +-
 tests/libqos/malloc.c | 6 +++---
 tests/libqtest.c      | 2 +-
 tests/pc-cpu-test.c   | 2 +-
 7 files changed, 11 insertions(+), 11 deletions(-)
Acked-by on v1 61/88
#90 lore raw

Re: [Qemu-devel] [PATCH 61/88] tests: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
Quoted 5 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: split of some files in other commits of the same series, add libqtest.c]

I think you don't need to add a maintainer's note here unless you changed something after it was posted to the list.

Quoted 1 line

---

You can put a V2 notice down here instead.

Quoted 123 lines
 tests/ahci-test.c     | 4 ++--
 tests/fw_cfg-test.c   | 4 ++--
 tests/libqos/ahci.c   | 2 +-
 tests/libqos/libqos.c | 2 +-
 tests/libqos/malloc.c | 6 +++---
 tests/libqtest.c      | 2 +-
 tests/pc-cpu-test.c   | 2 +-
 7 files changed, 11 insertions(+), 11 deletions(-)
tests/ahci-test.c +2 -2
index 999121bb7c..cb84edc8fb 100644
@@ -155,7 +155,7 @@ static AHCIQState *ahci_vboot(const char *cli, va_list ap)
 {
     AHCIQState *s;
 
-    s = g_malloc0(sizeof(AHCIQState));
+    s = g_new0(AHCIQState, 1);
     s->parent = qtest_pc_vboot(cli, ap);
     alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT);
 
@@ -1806,7 +1806,7 @@ static void create_ahci_io_test(enum IOMode type, enum AddrMode addr,
     char *name;
     AHCIIOTestOptions *opts;
 
-    opts = g_malloc(sizeof(AHCIIOTestOptions));
+    opts = g_new(AHCIIOTestOptions, 1);
     opts->length = len;
     opts->address_type = addr;
     opts->io_type = type;
tests/fw_cfg-test.c +2 -2
index 688342bed5..81f45bdfc8 100644
@@ -79,8 +79,8 @@ static void test_fw_cfg_numa(void)
 
     g_assert_cmpint(qfw_cfg_get_u64(fw_cfg, FW_CFG_NUMA), ==, nb_nodes);
 
-    cpu_mask = g_malloc0(sizeof(uint64_t) * max_cpus);
-    node_mask = g_malloc0(sizeof(uint64_t) * nb_nodes);
+    cpu_mask = g_new0(uint64_t, max_cpus);
+    node_mask = g_new0(uint64_t, nb_nodes);
 
     qfw_cfg_read_data(fw_cfg, cpu_mask, sizeof(uint64_t) * max_cpus);
     qfw_cfg_read_data(fw_cfg, node_mask, sizeof(uint64_t) * nb_nodes);
tests/libqos/ahci.c +1 -1
index 1ca7f456b5..13c0749582 100644
@@ -843,7 +843,7 @@ AHCICommand *ahci_command_create(uint8_t command_name)
     AHCICommand *cmd;
 
     g_assert(props);
-    cmd = g_malloc0(sizeof(AHCICommand));
+    cmd = g_new0(AHCICommand, 1);
     g_assert(!(props->dma && props->pio));
     g_assert(!(props->lba28 && props->lba48));
     g_assert(!(props->read && props->write));
tests/libqos/libqos.c +1 -1
index 6226546c28..991bc1aec2 100644
@@ -17,7 +17,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
 {
     char *cmdline;
 
-    struct QOSState *qs = g_malloc(sizeof(QOSState));
+    struct QOSState *qs = g_new(QOSState, 1);
 
     cmdline = g_strdup_vprintf(cmdline_fmt, ap);
     qs->qts = qtest_start(cmdline);
tests/libqos/malloc.c +3 -3
index b8eff5f495..ac05874b0a 100644
@@ -129,7 +129,7 @@ static MemBlock *mlist_new(uint64_t addr, uint64_t size)
     if (!size) {
         return NULL;
     }
-    block = g_malloc0(sizeof(MemBlock));
+    block = g_new0(MemBlock, 1);
 
     block->addr = addr;
     block->size = size;
@@ -305,8 +305,8 @@ QGuestAllocator *alloc_init(uint64_t start, uint64_t end)
     s->start = start;
     s->end = end;
 
-    s->used = g_malloc(sizeof(MemList));
-    s->free = g_malloc(sizeof(MemList));
+    s->used = g_new(MemList, 1);
+    s->free = g_new(MemList, 1);
     QTAILQ_INIT(s->used);
     QTAILQ_INIT(s->free);
 
tests/libqtest.c +1 -1
index cbd709470b..adf71188b6 100644
@@ -171,7 +171,7 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args)
     gchar *command;
     const char *qemu_binary = qtest_qemu_binary();
 
-    s = g_malloc(sizeof(*s));
+    s = g_new(QTestState, 1);
 
     socket_path = g_strdup_printf("/tmp/qtest-%d.sock", getpid());
     qmp_socket_path = g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
tests/pc-cpu-test.c +1 -1
index c4211a4e85..11d3e810ef 100644
@@ -87,7 +87,7 @@ static void add_pc_test_case(const char *mname)
     if (!g_str_has_prefix(mname, "pc-")) {
         return;
     }
-    data = g_malloc(sizeof(PCTestData));
+    data = g_new(PCTestData, 1);
     data->machine = g_strdup(mname);
     data->cpu_model = "Haswell"; /* 1.3+ theoretically */
     data->sockets = 1;
#91 lore raw

PATCH 62/88 user: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: added linux-user/elfload.c]
---
 linux-user/elfload.c | 2 +-
 thunk.c              | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
linux-user/elfload.c +1 -1
index 79062882ba..0a826071e9 100644
@@ -3014,7 +3014,7 @@ static void fill_thread_info(struct elf_note_info *info, const CPUArchState *env
     TaskState *ts = (TaskState *)cpu->opaque;
     struct elf_thread_status *ets;
 
-    ets = g_malloc0(sizeof (*ets));
+    ets = g_new0(struct elf_thread_status, 1);
     ets->num_notes = 1; /* only prstatus is dumped */
     fill_prstatus(&ets->prstatus, ts, 0);
     elf_core_copy_regs(&ets->prstatus.pr_reg, env);
thunk.c +1 -1
index d5d8645cd4..17f3d320bb 100644
@@ -89,7 +89,7 @@ void thunk_register_struct(int id, const char *name, const argtype *types)
     for(i = 0;i < 2; i++) {
         offset = 0;
         max_align = 1;
-        se->field_offsets[i] = malloc(nb_fields * sizeof(int));
+        se->field_offsets[i] = g_new(int, nb_fields);
         type_ptr = se->field_types;
         for(j = 0;j < nb_fields; j++) {
             size = thunk_type_size(type_ptr, i);
Signature · 1 line
2.14.2
#92 lore raw

PATCH 63/88 bsd-user/syscall: fix a memory leak on EFAULT, use g_new()

In reply to Philippe Mathieu-Daudé

---
Kamil are you interested in maintaining bsd-user? :)

 bsd-user/syscall.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
bsd-user/syscall.c +2 -1
index 66492aaf5d..9120cea61e 100644
@@ -227,7 +227,7 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
     void *hnamep, *holdp, *hnewp = NULL;
     size_t holdlen;
     abi_ulong oldlen = 0;
-    int32_t *snamep = g_malloc(sizeof(int32_t) * namelen), *p, *q, i;
+    int32_t *snamep, *p, *q, i;
     uint32_t kind = 0;
 
     if (oldlenp)
@@ -239,6 +239,7 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
     if (!(holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0)))
         return -TARGET_EFAULT;
     holdlen = oldlen;
+    snamep = g_new(int32_t, namelen);
     for (p = hnamep, q = snamep, i = 0; i < namelen; p++, i++)
        *q++ = tswap32(*p);
     oidfmt(snamep, namelen, NULL, &kind);
Signature · 1 line
2.14.2
#93 lore raw

Re: [Qemu-devel] [Qemu-trivial] [PATCH 63/88] bsd-user/syscall: fix a memory leak on EFAULT, use g_new()

Quoted 4 lines · Philippe Mathieu-Daudé

---
Kamil are you interested in maintaining bsd-user? :)

Long term yes, short term I'm occupied full-time on getting modern debuggers as fully-functional and as fully-featured on NetBSD as possible.

( http://blog.netbsd.org/tnf/entry/eurobsdcon_2017_paris_report )

Quoted 25 lines
 bsd-user/syscall.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
bsd-user/syscall.c +2 -1
index 66492aaf5d..9120cea61e 100644
@@ -227,7 +227,7 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
     void *hnamep, *holdp, *hnewp = NULL;
     size_t holdlen;
     abi_ulong oldlen = 0;
-    int32_t *snamep = g_malloc(sizeof(int32_t) * namelen), *p, *q, i;
+    int32_t *snamep, *p, *q, i;
     uint32_t kind = 0;
 
     if (oldlenp)
@@ -239,6 +239,7 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
     if (!(holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0)))
         return -TARGET_EFAULT;
     holdlen = oldlen;
+    snamep = g_new(int32_t, namelen);
     for (p = hnamep, q = snamep, i = 0; i < namelen; p++, i++)
        *q++ = tswap32(*p);
     oidfmt(snamep, namelen, NULL, &kind);
#94 lore raw

Re: [Qemu-devel] [PATCH 63/88] bsd-user/syscall: fix a memory leak on EFAULT, use g_new()

In reply to Philippe Mathieu-Daudé

Hi Michael,

Since there is no bsd-user maintainers, can you take this single patch for 2.11? It fixes a memory leak.

Regards,

Phil.

Quoted 29 lines · Philippe Mathieu-Daudé

---
Kamil are you interested in maintaining bsd-user? :)

 bsd-user/syscall.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
bsd-user/syscall.c +2 -1
index 66492aaf5d..9120cea61e 100644
@@ -227,7 +227,7 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
     void *hnamep, *holdp, *hnewp = NULL;
     size_t holdlen;
     abi_ulong oldlen = 0;
-    int32_t *snamep = g_malloc(sizeof(int32_t) * namelen), *p, *q, i;
+    int32_t *snamep, *p, *q, i;
     uint32_t kind = 0;
 
     if (oldlenp)
@@ -239,6 +239,7 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
     if (!(holdp = lock_user(VERIFY_WRITE, oldp, oldlen, 0)))
         return -TARGET_EFAULT;
     holdlen = oldlen;
+    snamep = g_new(int32_t, namelen);
     for (p = hnamep, q = snamep, i = 0; i < namelen; p++, i++)
        *q++ = tswap32(*p);
     oidfmt(snamep, namelen, NULL, &kind);
#95 lore raw

PATCH 64/88 user: use g_strfreev()

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 bsd-user/main.c   | 6 +-----
 linux-user/main.c | 6 +-----
 2 files changed, 2 insertions(+), 10 deletions(-)
bsd-user/main.c +1 -5
index 836daac15c..fb0a4e48cb 100644
@@ -947,11 +947,7 @@ int main(int argc, char **argv)
         _exit(1);
     }
 
-    for (wrk = target_environ; *wrk; wrk++) {
-        g_free(*wrk);
-    }
-
-    g_free(target_environ);
+    g_strfreev(target_environ);
 
     if (qemu_loglevel_mask(CPU_LOG_PAGE)) {
         qemu_log("guest_base  0x%lx\n", guest_base);
linux-user/main.c +1 -5
index 829f974662..f1e799f570 100644
@@ -4426,11 +4426,7 @@ int main(int argc, char **argv, char **envp)
         _exit(EXIT_FAILURE);
     }
 
-    for (wrk = target_environ; *wrk; wrk++) {
-        g_free(*wrk);
-    }
-
-    g_free(target_environ);
+    g_strfreev(target_environ);
 
     if (qemu_loglevel_mask(CPU_LOG_PAGE)) {
         qemu_log("guest_base  0x%lx\n", guest_base);
Signature · 1 line
2.14.2
#96 lore raw

PATCH 65/88 util: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: more changes in util/envlist.c, more files updated]
---
 util/acl.c         | 6 +++---
 util/envlist.c     | 6 +++---
 util/error.c       | 2 +-
 util/iohandler.c   | 2 +-
 util/module.c      | 4 ++--
 util/qemu-option.c | 8 ++++----
 util/qht.c         | 2 +-
 7 files changed, 15 insertions(+), 15 deletions(-)
util/acl.c +3 -3
index c105addadc..f5d8295fe2 100644
@@ -56,7 +56,7 @@ qemu_acl *qemu_acl_init(const char *aclname)
     if (acl)
         return acl;
 
-    acl = g_malloc(sizeof(*acl));
+    acl = g_new(qemu_acl, 1);
     acl->aclname = g_strdup(aclname);
     /* Deny by default, so there is no window of "open
      * access" between QEMU starting, and the user setting
@@ -117,7 +117,7 @@ int qemu_acl_append(qemu_acl *acl,
 {
     qemu_acl_entry *entry;
 
-    entry = g_malloc(sizeof(*entry));
+    entry = g_new(qemu_acl_entry, 1);
     entry->match = g_strdup(match);
     entry->deny = deny;
 
@@ -146,7 +146,7 @@ int qemu_acl_insert(qemu_acl *acl,
         i++;
         if (i == index) {
             qemu_acl_entry *entry;
-            entry = g_malloc(sizeof(*entry));
+            entry = g_new(qemu_acl_entry, 1);
             entry->match = g_strdup(match);
             entry->deny = deny;
 
util/envlist.c +3 -3
index 1eeb7fca87..5934095b7d 100644
@@ -24,7 +24,7 @@ envlist_create(void)
 {
 	envlist_t *envlist;
 
-	envlist = g_malloc(sizeof(*envlist));
+	envlist = g_new(envlist_t, 1);
 
 	QLIST_INIT(&envlist->el_entries);
 	envlist->el_count = 0;
@@ -158,7 +158,7 @@ envlist_setenv(envlist_t *envlist, const char *env)
 		envlist->el_count++;
 	}
 
-	entry = g_malloc(sizeof(*entry));
+	entry = g_new(struct envlist_entry, 1);
 	entry->ev_var = g_strdup(env);
 	QLIST_INSERT_HEAD(&envlist->el_entries, entry, ev_link);
 
@@ -218,7 +218,7 @@ envlist_to_environ(const envlist_t *envlist, size_t *count)
 	struct envlist_entry *entry;
 	char **env, **penv;
 
-	penv = env = g_malloc((envlist->el_count + 1) * sizeof(char *));
+	penv = env = g_new(char *, envlist->el_count + 1);
 
 	for (entry = envlist->el_entries.lh_first; entry != NULL;
 	    entry = entry->ev_link.le_next) {
util/error.c +1 -1
index 3efdd69162..cfb829b1f8 100644
@@ -56,7 +56,7 @@ static void error_setv(Error **errp,
     }
     assert(*errp == NULL);
 
-    err = g_malloc0(sizeof(*err));
+    err = g_new0(Error, 1);
     err->msg = g_strdup_vprintf(fmt, ap);
     if (suffix) {
         char *msg = err->msg;
util/iohandler.c +1 -1
index 623b55b9ec..518922dcea 100644
@@ -128,7 +128,7 @@ int qemu_add_child_watch(pid_t pid)
             return 1;
         }
     }
-    rec = g_malloc0(sizeof(ChildProcessRecord));
+    rec = g_new0(ChildProcessRecord, 1);
     rec->pid = pid;
     QLIST_INSERT_HEAD(&child_watches, rec, next);
     return 0;
util/module.c +2 -2
index c90973721f..1533dbdc63 100644
@@ -65,7 +65,7 @@ void register_module_init(void (*fn)(void), module_init_type type)
     ModuleEntry *e;
     ModuleTypeList *l;
 
-    e = g_malloc0(sizeof(*e));
+    e = g_new0(ModuleEntry, 1);
     e->init = fn;
     e->type = type;
 
@@ -80,7 +80,7 @@ void register_dso_module_init(void (*fn)(void), module_init_type type)
 
     init_lists();
 
-    e = g_malloc0(sizeof(*e));
+    e = g_new0(ModuleEntry, 1);
     e->init = fn;
     e->type = type;
 
util/qemu-option.c +4 -4
index 9b1dc8093b..8a121bfc40 100644
@@ -534,7 +534,7 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
         return;
     }
 
-    opt = g_malloc0(sizeof(*opt));
+    opt = g_new0(QemuOpt, 1);
     opt->name = g_strdup(name);
     opt->opts = opts;
     if (prepend) {
@@ -564,7 +564,7 @@ void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val,
     QemuOpt *opt;
     const QemuOptDesc *desc = opts->list->desc;
 
-    opt = g_malloc0(sizeof(*opt));
+    opt = g_new0(QemuOpt, 1);
     opt->desc = find_desc_by_name(desc, name);
     if (!opt->desc && !opts_accepts_any(opts)) {
         error_setg(errp, QERR_INVALID_PARAMETER, name);
@@ -585,7 +585,7 @@ void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val,
     QemuOpt *opt;
     const QemuOptDesc *desc = opts->list->desc;
 
-    opt = g_malloc0(sizeof(*opt));
+    opt = g_new0(QemuOpt, 1);
     opt->desc = find_desc_by_name(desc, name);
     if (!opt->desc && !opts_accepts_any(opts)) {
         error_setg(errp, QERR_INVALID_PARAMETER, name);
@@ -665,7 +665,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
             return opts;
         }
     }
-    opts = g_malloc0(sizeof(*opts));
+    opts = g_new0(QemuOpts, 1);
     opts->id = g_strdup(id);
     opts->list = list;
     loc_save(&opts->loc);
util/qht.c +1 -1
index ff4d2e6974..c5d153d573 100644
@@ -331,7 +331,7 @@ static struct qht_map *qht_map_create(size_t n_buckets)
     struct qht_map *map;
     size_t i;
 
-    map = g_malloc(sizeof(*map));
+    map = g_new(struct qht_map, 1);
     map->n_buckets = n_buckets;
 
     map->n_added_buckets = 0;
Signature · 1 line
2.14.2
#97 lore raw

PATCH 66/88 util/qemu-thread-win32: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 util/qemu-thread-win32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
util/qemu-thread-win32.c +1 -1
index 94f3491a87..098fddb2af 100644
@@ -394,7 +394,7 @@ void qemu_thread_create(QemuThread *thread, const char *name,
     HANDLE hThread;
     struct QemuThreadData *data;
 
-    data = g_malloc(sizeof *data);
+    data = g_new(struct QemuThreadData, 1);
     data->start_routine = start_routine;
     data->arg = arg;
     data->mode = mode;
Signature · 1 line
2.14.2
Reviewed-by on v1 66/88
#98 lore raw

Re: [Qemu-devel] [PATCH 66/88] util/qemu-thread-win32: use g_new() family of functions

Am 07.10.2017 um 01:50 schrieb Philippe Mathieu-Daudé:

Quoted 11 lines
---
 util/qemu-thread-win32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
util/qemu-thread-win32.c +0 -0
index 94f3491a87..098fddb2af 100644

util/qemu-thread-win32.c void qemu_thread_create(QemuThread *thread, const char *name, · line 400

Quoted 8 lines
util/qemu-thread-win32.c +1 -1
@@ -394,7 +394,7 @@ void qemu_thread_create(QemuThread *thread, const char *name,
     HANDLE hThread;
     struct QemuThreadData *data;
 
-    data = g_malloc(sizeof *data);
+    data = g_new(struct QemuThreadData, 1);
     data->start_routine = start_routine;
     data->arg = arg;
     data->mode = mode;

Maybe you can use this simplified variant:

    QemuThreadData *data = g_new(QemuThreadData, 1);

Stefan

#99 lore raw

PATCH 67/88 util/coroutine: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 util/coroutine-sigaltstack.c | 2 +-
 util/coroutine-ucontext.c    | 2 +-
 util/coroutine-win32.c       | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
util/coroutine-sigaltstack.c +1 -1
index f6fc49a0e5..4fe4bbf1b5 100644
@@ -163,7 +163,7 @@ Coroutine *qemu_coroutine_new(void)
      * sigaltstack way of manipulating stacks.
      */
 
-    co = g_malloc0(sizeof(*co));
+    co = g_new0(CoroutineSigAltStack, 1);
     co->stack_size = COROUTINE_STACK_SIZE;
     co->stack = qemu_alloc_stack(&co->stack_size);
     co->base.entry_arg = &old_env; /* stash away our jmp_buf */
util/coroutine-ucontext.c +1 -1
index 6621f3f692..c14dca19b4 100644
@@ -100,7 +100,7 @@ Coroutine *qemu_coroutine_new(void)
         abort();
     }
 
-    co = g_malloc0(sizeof(*co));
+    co = g_new0(CoroutineUContext, 1);
     co->stack_size = COROUTINE_STACK_SIZE;
     co->stack = qemu_alloc_stack(&co->stack_size);
     co->base.entry_arg = &old_env; /* stash away our jmp_buf */
util/coroutine-win32.c +1 -1
index de6bd4fd3e..6762ff83c2 100644
@@ -74,7 +74,7 @@ Coroutine *qemu_coroutine_new(void)
     const size_t stack_size = COROUTINE_STACK_SIZE;
     CoroutineWin32 *co;
 
-    co = g_malloc0(sizeof(*co));
+    co = g_new0(CoroutineWin32, 1);
     co->fiber = CreateFiber(stack_size, coroutine_trampoline, &co->base);
     return &co->base;
 }
Signature · 1 line
2.14.2
#100 lore raw

PATCH 68/88 virtio: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 hw/char/virtio-serial-bus.c | 6 ++----
 hw/display/virtio-gpu.c     | 4 ++--
 hw/net/virtio-net.c         | 4 ++--
 hw/virtio/vhost.c           | 2 +-
 hw/virtio/virtio-crypto.c   | 2 +-
 hw/virtio/virtio.c          | 2 +-
 tests/libqos/virtio-mmio.c  | 4 ++--
 tests/libqos/virtio-pci.c   | 4 ++--
 8 files changed, 13 insertions(+), 15 deletions(-)
hw/char/virtio-serial-bus.c +2 -4
index 9470bd7be7..fe739bb773 100644
@@ -1054,10 +1054,8 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
     QTAILQ_INIT(&vser->ports);
 
     vser->bus.max_nr_ports = vser->serial.max_virtserial_ports;
-    vser->ivqs = g_malloc(vser->serial.max_virtserial_ports
-                          * sizeof(VirtQueue *));
-    vser->ovqs = g_malloc(vser->serial.max_virtserial_ports
-                          * sizeof(VirtQueue *));
+    vser->ivqs = g_new(VirtQueue *, vser->serial.max_virtserial_ports);
+    vser->ovqs = g_new(VirtQueue *, vser->serial.max_virtserial_ports);
 
     /* Add a queue for host to guest transfers for port 0 (backward compat) */
     vser->ivqs[0] = virtio_add_queue(vdev, 128, handle_input);
hw/display/virtio-gpu.c +2 -2
index 43bbe09ea0..fb3884220b 100644
@@ -676,9 +676,9 @@ int virtio_gpu_create_mapping_iov(struct virtio_gpu_resource_attach_backing *ab,
         return -1;
     }
 
-    *iov = g_malloc0(sizeof(struct iovec) * ab->nr_entries);
+    *iov = g_new0(struct iovec, ab->nr_entries);
     if (addr) {
-        *addr = g_malloc0(sizeof(uint64_t) * ab->nr_entries);
+        *addr = g_new0(uint64_t, ab->nr_entries);
     }
     for (i = 0; i < ab->nr_entries; i++) {
         uint64_t a = le64_to_cpu(ents[i].addr);
hw/net/virtio-net.c +2 -2
index 150fd0748e..ce488b63d5 100644
@@ -359,7 +359,7 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc)
     strList *str_list, *entry;
     int i;
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(RxFilterInfo, 1);
     info->name = g_strdup(nc->name);
     info->promiscuous = n->promisc;
 
@@ -1978,7 +1978,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
         virtio_cleanup(vdev);
         return;
     }
-    n->vqs = g_malloc0(sizeof(VirtIONetQueue) * n->max_queues);
+    n->vqs = g_new0(VirtIONetQueue, n->max_queues);
     n->curr_queues = 1;
     n->tx_timeout = n->net_conf.txtimer;
 
hw/virtio/vhost.c +1 -1
index 5fd69f0b2e..f4abc1d26d 100644
@@ -742,7 +742,7 @@ static void vhost_iommu_region_add(MemoryListener *listener,
         return;
     }
 
-    iommu = g_malloc0(sizeof(*iommu));
+    iommu = g_new0(struct vhost_iommu, 1);
     end = int128_add(int128_make64(section->offset_within_region),
                      section->size);
     end = int128_sub(end, int128_one());
hw/virtio/virtio-crypto.c +1 -1
index 19c82e0432..9544ea92ef 100644
@@ -798,7 +798,7 @@ static void virtio_crypto_device_realize(DeviceState *dev, Error **errp)
 
     virtio_init(vdev, "virtio-crypto", VIRTIO_ID_CRYPTO, vcrypto->config_size);
     vcrypto->curr_queues = 1;
-    vcrypto->vqs = g_malloc0(sizeof(VirtIOCryptoQueue) * vcrypto->max_queues);
+    vcrypto->vqs = g_new0(VirtIOCryptoQueue, vcrypto->max_queues);
     for (i = 0; i < vcrypto->max_queues; i++) {
         vcrypto->vqs[i].dataq =
                  virtio_add_queue(vdev, 1024, virtio_crypto_handle_dataq_bh);
hw/virtio/virtio.c +1 -1
index 311929e9df..9a38fe695a 100644
@@ -2245,7 +2245,7 @@ void virtio_init(VirtIODevice *vdev, const char *name,
     atomic_set(&vdev->isr, 0);
     vdev->queue_sel = 0;
     vdev->config_vector = VIRTIO_NO_VECTOR;
-    vdev->vq = g_malloc0(sizeof(VirtQueue) * VIRTIO_QUEUE_MAX);
+    vdev->vq = g_new0(VirtQueue, VIRTIO_QUEUE_MAX);
     vdev->vm_running = runstate_is_running();
     vdev->broken = false;
     for (i = 0; i < VIRTIO_QUEUE_MAX; i++) {
tests/libqos/virtio-mmio.c +2 -2
index 7aa8383338..a48fecab63 100644
@@ -127,7 +127,7 @@ static QVirtQueue *qvirtio_mmio_virtqueue_setup(QVirtioDevice *d,
     QVirtQueue *vq;
     uint64_t addr;
 
-    vq = g_malloc0(sizeof(*vq));
+    vq = g_new0(QVirtQueue, 1);
     qvirtio_mmio_queue_select(d, index);
     writel(dev->addr + QVIRTIO_MMIO_QUEUE_ALIGN, dev->page_size);
 
@@ -191,7 +191,7 @@ QVirtioMMIODevice *qvirtio_mmio_init_device(uint64_t addr, uint32_t page_size)
 {
     QVirtioMMIODevice *dev;
     uint32_t magic;
-    dev = g_malloc0(sizeof(*dev));
+    dev = g_new0(QVirtioMMIODevice, 1);
 
     magic = readl(addr + QVIRTIO_MMIO_MAGIC_VALUE);
     g_assert(magic == ('v' | 'i' << 8 | 'r' << 16 | 't' << 24));
tests/libqos/virtio-pci.c +2 -2
index 7ac15c04e1..02d5e0853e 100644
@@ -38,7 +38,7 @@ void qvirtio_pci_device_free(QVirtioPCIDevice *dev)
 static QVirtioPCIDevice *qpcidevice_to_qvirtiodevice(QPCIDevice *pdev)
 {
     QVirtioPCIDevice *vpcidev;
-    vpcidev = g_malloc0(sizeof(*vpcidev));
+    vpcidev = g_new0(QVirtioPCIDevice, 1);
 
     if (pdev) {
         vpcidev->pdev = pdev;
@@ -229,7 +229,7 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,
     uint64_t addr;
     QVirtQueuePCI *vqpci;
 
-    vqpci = g_malloc0(sizeof(*vqpci));
+    vqpci = g_new0(QVirtQueuePCI, 1);
     feat = qvirtio_pci_get_guest_features(d);
 
     qvirtio_pci_queue_select(d, index);
Signature · 1 line
2.14.2
#101 lore raw

PATCH 69/88 virtio-9p: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: added 2 more uses in hw/9pfs/9p-synth.c]
---
 hw/9pfs/9p-handle.c | 2 +-
 hw/9pfs/9p-proxy.c  | 2 +-
 hw/9pfs/9p-synth.c  | 8 ++++----
 hw/9pfs/9p.c        | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
hw/9pfs/9p-handle.c +1 -1
index 9875f1894c..357ced3079 100644
@@ -609,7 +609,7 @@ static int handle_init(FsContext *ctx)
     int ret, mnt_id;
     struct statfs stbuf;
     struct file_handle fh;
-    struct handle_data *data = g_malloc(sizeof(struct handle_data));
+    struct handle_data *data = g_new(struct handle_data, 1);
 
     data->mountfd = open(ctx->fs_root, O_DIRECTORY);
     if (data->mountfd < 0) {
hw/9pfs/9p-proxy.c +1 -1
index 28b20a7c3d..2de303d713 100644
@@ -1136,7 +1136,7 @@ static int proxy_parse_opts(QemuOpts *opts, struct FsDriverEntry *fs)
 
 static int proxy_init(FsContext *ctx)
 {
-    V9fsProxy *proxy = g_malloc(sizeof(V9fsProxy));
+    V9fsProxy *proxy = g_new(V9fsProxy, 1);
     int sock_id;
 
     if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) {
hw/9pfs/9p-synth.c +4 -4
index df0a8de08a..3aa69cf465 100644
@@ -43,7 +43,7 @@ static V9fsSynthNode *v9fs_add_dir_node(V9fsSynthNode *parent, int mode,
 
     /* Add directory type and remove write bits */
     mode = ((mode & 0777) | S_IFDIR) & ~(S_IWUSR | S_IWGRP | S_IWOTH);
-    node = g_malloc0(sizeof(V9fsSynthNode));
+    node = g_new0(V9fsSynthNode, 1);
     if (attr) {
         /* We are adding .. or . entries */
         node->attr = attr;
@@ -124,7 +124,7 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
     }
     /* Add file type and remove write bits */
     mode = ((mode & 0777) | S_IFREG);
-    node = g_malloc0(sizeof(V9fsSynthNode));
+    node = g_new0(V9fsSynthNode, 1);
     node->attr         = &node->actual_attr;
     node->attr->inode  = synth_node_count++;
     node->attr->nlink  = 1;
@@ -180,7 +180,7 @@ static int synth_opendir(FsContext *ctx,
     V9fsSynthOpenState *synth_open;
     V9fsSynthNode *node = *(V9fsSynthNode **)fs_path->data;
 
-    synth_open = g_malloc(sizeof(*synth_open));
+    synth_open = g_new(V9fsSynthOpenState, 1);
     synth_open->node = node;
     node->open_count++;
     fs->private = synth_open;
@@ -264,7 +264,7 @@ static int synth_open(FsContext *ctx, V9fsPath *fs_path,
     V9fsSynthOpenState *synth_open;
     V9fsSynthNode *node = *(V9fsSynthNode **)fs_path->data;
 
-    synth_open = g_malloc(sizeof(*synth_open));
+    synth_open = g_new(V9fsSynthOpenState, 1);
     synth_open->node = node;
     node->open_count++;
     fs->private = synth_open;
hw/9pfs/9p.c +1 -1
index 23ac7bb532..510867b4dc 100644
@@ -298,7 +298,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid)
             return NULL;
         }
     }
-    f = g_malloc0(sizeof(V9fsFidState));
+    f = g_new0(V9fsFidState, 1);
     f->fid = fid;
     f->fid_type = P9_FID_NONE;
     f->ref = 1;
Signature · 1 line
2.14.2
Acked-by on v1 69/88
#102 lore raw

Re: [Qemu-devel] [PATCH 69/88] virtio-9p: use g_new() family of functions

Quoted 6 lines · On Fri, 6 Oct 2017 20:50:04 -0300 Philippe Mathieu-Daudé <[email protected]>…

From: Marc-André Lureau <[email protected]>

[PMD: added 2 more uses in hw/9pfs/9p-synth.c]

---

Quoted 85 lines
 hw/9pfs/9p-handle.c | 2 +-
 hw/9pfs/9p-proxy.c  | 2 +-
 hw/9pfs/9p-synth.c  | 8 ++++----
 hw/9pfs/9p.c        | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
hw/9pfs/9p-handle.c +1 -1
index 9875f1894c..357ced3079 100644
@@ -609,7 +609,7 @@ static int handle_init(FsContext *ctx)
     int ret, mnt_id;
     struct statfs stbuf;
     struct file_handle fh;
-    struct handle_data *data = g_malloc(sizeof(struct handle_data));
+    struct handle_data *data = g_new(struct handle_data, 1);
 
     data->mountfd = open(ctx->fs_root, O_DIRECTORY);
     if (data->mountfd < 0) {
hw/9pfs/9p-proxy.c +1 -1
index 28b20a7c3d..2de303d713 100644
@@ -1136,7 +1136,7 @@ static int proxy_parse_opts(QemuOpts *opts, struct FsDriverEntry *fs)
 
 static int proxy_init(FsContext *ctx)
 {
-    V9fsProxy *proxy = g_malloc(sizeof(V9fsProxy));
+    V9fsProxy *proxy = g_new(V9fsProxy, 1);
     int sock_id;
 
     if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) {
hw/9pfs/9p-synth.c +4 -4
index df0a8de08a..3aa69cf465 100644
@@ -43,7 +43,7 @@ static V9fsSynthNode *v9fs_add_dir_node(V9fsSynthNode *parent, int mode,
 
     /* Add directory type and remove write bits */
     mode = ((mode & 0777) | S_IFDIR) & ~(S_IWUSR | S_IWGRP | S_IWOTH);
-    node = g_malloc0(sizeof(V9fsSynthNode));
+    node = g_new0(V9fsSynthNode, 1);
     if (attr) {
         /* We are adding .. or . entries */
         node->attr = attr;
@@ -124,7 +124,7 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
     }
     /* Add file type and remove write bits */
     mode = ((mode & 0777) | S_IFREG);
-    node = g_malloc0(sizeof(V9fsSynthNode));
+    node = g_new0(V9fsSynthNode, 1);
     node->attr         = &node->actual_attr;
     node->attr->inode  = synth_node_count++;
     node->attr->nlink  = 1;
@@ -180,7 +180,7 @@ static int synth_opendir(FsContext *ctx,
     V9fsSynthOpenState *synth_open;
     V9fsSynthNode *node = *(V9fsSynthNode **)fs_path->data;
 
-    synth_open = g_malloc(sizeof(*synth_open));
+    synth_open = g_new(V9fsSynthOpenState, 1);
     synth_open->node = node;
     node->open_count++;
     fs->private = synth_open;
@@ -264,7 +264,7 @@ static int synth_open(FsContext *ctx, V9fsPath *fs_path,
     V9fsSynthOpenState *synth_open;
     V9fsSynthNode *node = *(V9fsSynthNode **)fs_path->data;
 
-    synth_open = g_malloc(sizeof(*synth_open));
+    synth_open = g_new(V9fsSynthOpenState, 1);
     synth_open->node = node;
     node->open_count++;
     fs->private = synth_open;
hw/9pfs/9p.c +1 -1
index 23ac7bb532..510867b4dc 100644
@@ -298,7 +298,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid)
             return NULL;
         }
     }
-    f = g_malloc0(sizeof(V9fsFidState));
+    f = g_new0(V9fsFidState, 1);
     f->fid = fid;
     f->fid_type = P9_FID_NONE;
     f->ref = 1;
#103 lore raw

PATCH 70/88 block: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 block/backup.c         |  2 +-
 block/blkdebug.c       |  4 ++--
 block/commit.c         |  2 +-
 block/linux-aio.c      |  2 +-
 block/mirror.c         |  2 +-
 block/qapi.c           |  4 ++--
 block/qcow2-refcount.c | 12 +++++-------
 block/qed-l2-cache.c   |  2 +-
 block/sheepdog.c       |  2 +-
 block/stream.c         |  2 +-
 block/vhdx.c           |  2 +-
 block/win32-aio.c      |  2 +-
 12 files changed, 18 insertions(+), 20 deletions(-)
block/backup.c +1 -1
index 06ddbfd03d..cd73e7d905 100644
@@ -514,7 +514,7 @@ static void coroutine_fn backup_run(void *opaque)
     qemu_co_rwlock_unlock(&job->flush_rwlock);
     g_free(job->done_bitmap);
 
-    data = g_malloc(sizeof(*data));
+    data = g_new(BackupCompleteData, 1);
     data->ret = ret;
     block_job_defer_to_main_loop(&job->common, backup_complete, data);
 }
block/blkdebug.c +2 -2
index 46e53f2f09..4d05bcb1d9 100644
@@ -175,7 +175,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error **errp)
     }
 
     /* Set attributes common for all actions */
-    rule = g_malloc0(sizeof(*rule));
+    rule = g_new(struct BlkdebugRule, 1);
     *rule = (struct BlkdebugRule) {
         .event  = event,
         .action = d->action,
@@ -727,7 +727,7 @@ static int blkdebug_debug_breakpoint(BlockDriverState *bs, const char *event,
         return -ENOENT;
     }
 
-    rule = g_malloc(sizeof(*rule));
+    rule = g_new(struct BlkdebugRule, 1);
     *rule = (struct BlkdebugRule) {
         .event  = blkdebug_event,
         .action = ACTION_SUSPEND,
block/commit.c +1 -1
index 5036eec434..e698311d5f 100644
@@ -210,7 +210,7 @@ static void coroutine_fn commit_run(void *opaque)
 out:
     qemu_vfree(buf);
 
-    data = g_malloc(sizeof(*data));
+    data = g_new(CommitCompleteData, 1);
     data->ret = ret;
     block_job_defer_to_main_loop(&s->common, commit_complete, data);
 }
block/linux-aio.c +1 -1
index 88b8d55ec7..e5a9d7fdeb 100644
@@ -474,7 +474,7 @@ LinuxAioState *laio_init(void)
 {
     LinuxAioState *s;
 
-    s = g_malloc0(sizeof(*s));
+    s = g_new0(LinuxAioState, 1);
     if (event_notifier_init(&s->e, false) < 0) {
         goto out_free_state;
     }
block/mirror.c +1 -1
index 153758ca9f..948e5321a7 100644
@@ -904,7 +904,7 @@ immediate_exit:
     g_free(s->in_flight_bitmap);
     bdrv_dirty_iter_free(s->dbi);
 
-    data = g_malloc(sizeof(*data));
+    data = g_new(MirrorExitData, 1);
     data->ret = ret;
 
     if (need_drain) {
block/qapi.c +2 -2
index 7fa2437923..808246bfc4 100644
@@ -455,7 +455,7 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs,
 {
     BlockStats *s = NULL;
 
-    s = g_malloc0(sizeof(*s));
+    s = g_new0(BlockStats, 1);
     s->stats = g_malloc0(sizeof(*s->stats));
 
     if (!bs) {
@@ -503,7 +503,7 @@ BlockInfoList *qmp_query_block(Error **errp)
             continue;
         }
 
-        info = g_malloc0(sizeof(*info));
+        info = g_new0(BlockInfoList, 1);
         bdrv_query_info(blk, &info->value, &local_err);
         if (local_err) {
             error_propagate(errp, local_err);
block/qcow2-refcount.c +5 -7
index aa3fd6cf17..dd2387d2bb 100644
@@ -755,7 +755,7 @@ static void update_refcount_discard(BlockDriverState *bs,
         }
     }
 
-    d = g_malloc(sizeof(*d));
+    d = g_new(Qcow2DiscardRegion, 1);
     *d = (Qcow2DiscardRegion) {
         .bs     = bs,
         .offset = offset,
@@ -2189,9 +2189,8 @@ write_refblocks:
 
             reftable_size = ROUND_UP((refblock_index + 1) * sizeof(uint64_t),
                                      s->cluster_size) / sizeof(uint64_t);
-            new_on_disk_reftable = g_try_realloc(on_disk_reftable,
-                                                 reftable_size *
-                                                 sizeof(uint64_t));
+            new_on_disk_reftable = g_try_renew(uint64_t, on_disk_reftable,
+                                               reftable_size);
             if (!new_on_disk_reftable) {
                 res->check_errors++;
                 ret = -ENOMEM;
@@ -2656,8 +2655,7 @@ static int alloc_refblock(BlockDriverState *bs, uint64_t **reftable,
             return -ENOTSUP;
         }
 
-        new_reftable = g_try_realloc(*reftable, new_reftable_size *
-                                                sizeof(uint64_t));
+        new_reftable = g_try_renew(uint64_t, *reftable, new_reftable_size);
         if (!new_reftable) {
             error_setg(errp, "Failed to increase reftable buffer size");
             return -ENOMEM;
@@ -3119,7 +3117,7 @@ int qcow2_shrink_reftable(BlockDriverState *bs)
 {
     BDRVQcow2State *s = bs->opaque;
     uint64_t *reftable_tmp =
-        g_malloc(s->refcount_table_size * sizeof(uint64_t));
+        g_new(uint64_t, s->refcount_table_size);
     int i, ret;
 
     for (i = 0; i < s->refcount_table_size; i++) {
block/qed-l2-cache.c +1 -1
index b548362398..48689a6650 100644
@@ -90,7 +90,7 @@ CachedL2Table *qed_alloc_l2_cache_entry(L2TableCache *l2_cache)
 {
     CachedL2Table *entry;
 
-    entry = g_malloc0(sizeof(*entry));
+    entry = g_new0(CachedL2Table, 1);
     entry->ref++;
 
     trace_qed_alloc_l2_cache_entry(l2_cache, entry);
block/sheepdog.c +1 -1
index 696a71442a..1f67ed43ca 100644
@@ -467,7 +467,7 @@ static inline AIOReq *alloc_aio_req(BDRVSheepdogState *s, SheepdogAIOCB *acb,
 {
     AIOReq *aio_req;
 
-    aio_req = g_malloc(sizeof(*aio_req));
+    aio_req = g_new(AIOReq, 1);
     aio_req->aiocb = acb;
     aio_req->iov_offset = iov_offset;
     aio_req->oid = oid;
block/stream.c +1 -1
index e6f72346e5..2b4c67de41 100644
@@ -202,7 +202,7 @@ static void coroutine_fn stream_run(void *opaque)
 
 out:
     /* Modify backing chain and close BDSes in main loop */
-    data = g_malloc(sizeof(*data));
+    data = g_new(StreamCompleteData, 1);
     data->ret = ret;
     block_job_defer_to_main_loop(&s->common, stream_complete, data);
 }
block/vhdx.c +1 -1
index 7ae4589879..8260fb46cd 100644
@@ -244,7 +244,7 @@ static void vhdx_region_register(BDRVVHDXState *s,
 {
     VHDXRegionEntry *r;
 
-    r = g_malloc0(sizeof(*r));
+    r = g_new0(VHDXRegionEntry, 1);
 
     r->start = start;
     r->end = start + length;
block/win32-aio.c +1 -1
index 3be8f458fa..dfa062562f 100644
@@ -190,7 +190,7 @@ QEMUWin32AIOState *win32_aio_init(void)
 {
     QEMUWin32AIOState *s;
 
-    s = g_malloc0(sizeof(*s));
+    s = g_new0(QEMUWin32AIOState, 1);
     if (event_notifier_init(&s->e, false) < 0) {
         goto out_free_state;
     }
Signature · 1 line
2.14.2
#104 lore raw

PATCH 71/88 block: avoid use of g_new0()

In reply to Philippe Mathieu-Daudé
---
 block/qcow2.c | 2 +-
 block/vhdx.c  | 9 +++++----
 2 files changed, 6 insertions(+), 5 deletions(-)
block/qcow2.c +1 -1
index f63d1831f8..3e7d6c81be 100644
@@ -2738,7 +2738,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
 
     /* Write the header */
     QEMU_BUILD_BUG_ON((1 << MIN_CLUSTER_BITS) < sizeof(*header));
-    header = g_malloc0(cluster_size);
+    header = g_malloc(cluster_size);
     *header = (QCowHeader) {
         .magic                      = cpu_to_be32(QCOW_MAGIC),
         .version                    = cpu_to_be32(version),
block/vhdx.c +5 -4
index 8260fb46cd..91e532df8a 100644
@@ -244,10 +244,11 @@ static void vhdx_region_register(BDRVVHDXState *s,
 {
     VHDXRegionEntry *r;
 
-    r = g_new0(VHDXRegionEntry, 1);
-
-    r->start = start;
-    r->end = start + length;
+    r = g_new(VHDXRegionEntry, 1);
+    *r = (VHDXRegionEntry) {
+        .start = start,
+        .end = start + length,
+    };
 
     QLIST_INSERT_HEAD(&s->regions, r, entries);
 }
Signature · 1 line
2.14.2
#105 lore raw

Re: [Qemu-devel] [PATCH 71/88] block: avoid use of g_new0()

Quoted 11 lines · Philippe Mathieu-Daudé
---
 block/qcow2.c | 2 +-
 block/vhdx.c  | 9 +++++----
 2 files changed, 6 insertions(+), 5 deletions(-)
block/qcow2.c +0 -0
index f63d1831f8..3e7d6c81be 100644

block/qcow2.c static int qcow2_create2(const char *filename, int64_t total_size, · line 2741

Quoted 5 lines
block/qcow2.c +1 -1
@@ -2738,7 +2738,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
 
     /* Write the header */
     QEMU_BUILD_BUG_ON((1 << MIN_CLUSTER_BITS) < sizeof(*header));
-    header = g_malloc0(cluster_size);
+    header = g_malloc(cluster_size);

self-NACK since this is wrong.

Quoted 9 lines
block/qcow2.c +0 -0
     *header = (QCowHeader) {
         .magic                      = cpu_to_be32(QCOW_MAGIC),
         .version                    = cpu_to_be32(version),
block/vhdx.c +0 -0
index 8260fb46cd..91e532df8a 100644
@@ -244,10 +244,11 @@ static void vhdx_region_register(BDRVVHDXState *s,
 {

block/vhdx.c static void vhdx_region_register(BDRVVHDXState *s, · line 250

Quoted 10 lines
block/vhdx.c +4 -4
     VHDXRegionEntry *r;
 
-    r = g_new0(VHDXRegionEntry, 1);
-
-    r->start = start;
-    r->end = start + length;
+    r = g_new(VHDXRegionEntry, 1);
+    *r = (VHDXRegionEntry) {
+        .start = start,
+        .end = start + length,

this is not wrong since all members are initialized, but it is not good code practice (if the VHDXRegionEntry structure is expanded with another member).

Quoted 5 lines
block/vhdx.c +1 -0
+    };
 
     QLIST_INSERT_HEAD(&s->regions, r, entries);
 }
#106 lore raw

PATCH 72/88 hw/block/nvme: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 hw/block/nvme.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/block/nvme.c +2 -2
index 9aa32692a3..ff712fa8cc 100644
@@ -454,7 +454,7 @@ static uint16_t nvme_create_sq(NvmeCtrl *n, NvmeCmd *cmd)
     if (!(NVME_SQ_FLAGS_PC(qflags))) {
         return NVME_INVALID_FIELD | NVME_DNR;
     }
-    sq = g_malloc0(sizeof(*sq));
+    sq = g_new0(NvmeSQueue, 1);
     nvme_init_sq(sq, n, prp1, sqid, cqid, qsize + 1);
     return NVME_SUCCESS;
 }
@@ -532,7 +532,7 @@ static uint16_t nvme_create_cq(NvmeCtrl *n, NvmeCmd *cmd)
         return NVME_INVALID_FIELD | NVME_DNR;
     }
 
-    cq = g_malloc0(sizeof(*cq));
+    cq = g_new0(NvmeCQueue, 1);
     nvme_init_cq(cq, n, prp1, cqid, vector, qsize + 1,
         NVME_CQ_FLAGS_IEN(qflags));
     return NVME_SUCCESS;
Signature · 1 line
2.14.2
#107 lore raw

PATCH 73/88 hw/block/xen_disk: avoid use of g_new0()

In reply to Philippe Mathieu-Daudé

From: Jan Beulich <[email protected]>

Prefer g_new() / g_new0() to be farther backwards compatible with older glib versions. As there's no point in zeroing the allocation here (the loop right afterwards fully initializes the memory), use the former.

---
 hw/block/xen_disk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/xen_disk.c +1 -1
index 536e2ee735..6d2fd4d284 100644
@@ -1232,7 +1232,7 @@ static int blk_connect(struct XenDevice *xendev)
         return -1;
     }
 
-    domids = g_new0(uint32_t, blkdev->nr_ring_ref);
+    domids = g_new(uint32_t, blkdev->nr_ring_ref);
     for (i = 0; i < blkdev->nr_ring_ref; i++) {
         domids[i] = blkdev->xendev.dom;
     }
Signature · 1 line
2.14.2
#108 lore raw

PATCH 74/88 balloon: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
balloon.c +1 -1
index 1d720fff81..d77918fd37 100644
@@ -97,7 +97,7 @@ BalloonInfo *qmp_query_balloon(Error **errp)
         return NULL;
     }
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(BalloonInfo, 1);
     balloon_stat_fn(balloon_opaque, info);
     return info;
 }
Signature · 1 line
2.14.2
#109 lore raw

PATCH 75/88 decnumber: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 libdecnumber/decNumber.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
libdecnumber/decNumber.c +4 -4
index 8c197023f4..2d13198730 100644
@@ -4089,7 +4089,7 @@ static decNumber * decAddOp(decNumber *res, const decNumber *lhs,
       acc=accbuff;			/* assume use local buffer */
       if (need*sizeof(Unit)>sizeof(accbuff)) {
 	/* printf("malloc add %ld %ld\n", need, sizeof(accbuff)); */
-	allocacc=(Unit *)malloc(need*sizeof(Unit));
+	allocacc=g_new(uint16_t, need);
 	if (allocacc==NULL) {		/* hopeless -- abandon */
 	  *status|=DEC_Insufficient_storage;
 	  break;}
@@ -4452,7 +4452,7 @@ static decNumber * decDivideOp(decNumber *res,
     acclength=D2U(reqdigits+DECDPUN);	/* in Units */
     if (acclength*sizeof(Unit)>sizeof(accbuff)) {
       /* printf("malloc dvacc %ld units\n", acclength); */
-      allocacc=(Unit *)malloc(acclength*sizeof(Unit));
+      allocacc=g_new(uint16_t, acclength);
       if (allocacc==NULL) {		/* hopeless -- abandon */
 	*status|=DEC_Insufficient_storage;
 	break;}
@@ -4477,7 +4477,7 @@ static decNumber * decDivideOp(decNumber *res,
     if (!(op&DIVIDE)) var1units++;
     if ((var1units+1)*sizeof(Unit)>sizeof(varbuff)) {
       /* printf("malloc dvvar %ld units\n", var1units+1); */
-      varalloc=(Unit *)malloc((var1units+1)*sizeof(Unit));
+      varalloc=g_new(uint16_t, (var1units+1));
       if (varalloc==NULL) {		/* hopeless -- abandon */
 	*status|=DEC_Insufficient_storage;
 	break;}
@@ -6314,7 +6314,7 @@ static Int decUnitCompare(const Unit *a, Int alength,
   need+=2;
   acc=accbuff;				/* assume use local buffer */
   if (need*sizeof(Unit)>sizeof(accbuff)) {
-    allocacc=(Unit *)malloc(need*sizeof(Unit));
+    allocacc=g_new(uint16_t, need);
     if (allocacc==NULL) return BADINT;	/* hopeless -- abandon */
     acc=allocacc;
     }
Signature · 1 line
2.14.2
#110 lore raw

PATCH 76/88 dma: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

[PMD: added hw/dma/etraxfs_dma.c]
---
 dma-helpers.c        | 4 ++--
 hw/dma/etraxfs_dma.c | 2 +-
 hw/dma/rc4030.c      | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
dma-helpers.c +2 -2
index 2d7e02d35e..e327fc21c4 100644
@@ -40,7 +40,7 @@ int dma_memory_set(AddressSpace *as, dma_addr_t addr, uint8_t c, dma_addr_t len)
 void qemu_sglist_init(QEMUSGList *qsg, DeviceState *dev, int alloc_hint,
                       AddressSpace *as)
 {
-    qsg->sg = g_malloc(alloc_hint * sizeof(ScatterGatherEntry));
+    qsg->sg = g_new(ScatterGatherEntry, alloc_hint);
     qsg->nsg = 0;
     qsg->nalloc = alloc_hint;
     qsg->size = 0;
@@ -53,7 +53,7 @@ void qemu_sglist_add(QEMUSGList *qsg, dma_addr_t base, dma_addr_t len)
 {
     if (qsg->nsg == qsg->nalloc) {
         qsg->nalloc = 2 * qsg->nalloc + 1;
-        qsg->sg = g_realloc(qsg->sg, qsg->nalloc * sizeof(ScatterGatherEntry));
+        qsg->sg = g_renew(ScatterGatherEntry, qsg->sg, qsg->nalloc);
     }
     qsg->sg[qsg->nsg].base = base;
     qsg->sg[qsg->nsg].len = len;
hw/dma/etraxfs_dma.c +1 -1
index d5650eb885..97951a2abe 100644
@@ -768,7 +768,7 @@ void *etraxfs_dmac_init(hwaddr base, int nr_channels)
 {
 	struct fs_dma_ctrl *ctrl = NULL;
 
-	ctrl = g_malloc0(sizeof *ctrl);
+	ctrl = g_new0(struct fs_dma_ctrl, 1);
 
         ctrl->bh = qemu_bh_new(DMA_run, ctrl);
 
hw/dma/rc4030.c +2 -2
index 5d4833eeca..14bcab9fb3 100644
@@ -636,8 +636,8 @@ static rc4030_dma *rc4030_allocate_dmas(void *opaque, int n)
     struct rc4030DMAState *p;
     int i;
 
-    s = (rc4030_dma *)g_malloc0(sizeof(rc4030_dma) * n);
-    p = (struct rc4030DMAState *)g_malloc0(sizeof(struct rc4030DMAState) * n);
+    s = g_new0(rc4030_dma, n);
+    p = g_new0(struct rc4030DMAState, n);
     for (i = 0; i < n; i++) {
         p->opaque = opaque;
         p->n = i;
Signature · 1 line
2.14.2
#111 lore raw

PATCH 77/88 dump: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 dump.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
dump.c +5 -6
index 7ebcf553b2..884221a904 100644
@@ -1825,29 +1825,28 @@ void qmp_dump_guest_memory(bool paging, const char *file,
 DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp)
 {
     DumpGuestMemoryFormatList *item;
-    DumpGuestMemoryCapability *cap =
-                                  g_malloc0(sizeof(DumpGuestMemoryCapability));
+    DumpGuestMemoryCapability *cap = g_new0(DumpGuestMemoryCapability, 1);
 
     /* elf is always available */
-    item = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+    item = g_new0(DumpGuestMemoryFormatList, 1);
     cap->formats = item;
     item->value = DUMP_GUEST_MEMORY_FORMAT_ELF;
 
     /* kdump-zlib is always available */
-    item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+    item->next = g_new0(DumpGuestMemoryFormatList, 1);
     item = item->next;
     item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
 
     /* add new item if kdump-lzo is available */
 #ifdef CONFIG_LZO
-    item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+    item->next = g_new0(DumpGuestMemoryFormatList, 1);
     item = item->next;
     item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
 #endif
 
     /* add new item if kdump-snappy is available */
 #ifdef CONFIG_SNAPPY
-    item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+    item->next = g_new0(DumpGuestMemoryFormatList, 1);
     item = item->next;
     item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
 #endif
Signature · 1 line
2.14.2
#113 lore raw

PATCH 78/88 gdb: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

---
 gdbstub.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
gdbstub.c +2 -2
index 2a94030d3b..5f0d8af1c0 100644
@@ -1786,7 +1786,7 @@ static void gdb_accept(void)
     /* set short latency */
     socket_set_nodelay(fd);
 
-    s = g_malloc0(sizeof(GDBState));
+    s = g_new0(GDBState, 1);
     s->c_cpu = first_cpu;
     s->g_cpu = first_cpu;
     s->fd = fd;
@@ -1980,7 +1980,7 @@ int gdbserver_start(const char *device)
 
     s = gdbserver_state;
     if (!s) {
-        s = g_malloc0(sizeof(GDBState));
+        s = g_new0(GDBState, 1);
         gdbserver_state = s;
 
         qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL);
Signature · 1 line
2.14.2
Reviewed-by on v1 78/88
#114 lore raw

Re: [Qemu-devel] [PATCH 78/88] gdb: use g_new() family of functions

Quoted 3 lines · Philippe Mathieu-Daudé

From: Marc-André Lureau <[email protected]>

Quoted 18 lines
---
 gdbstub.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
gdbstub.c +1 -1
index 2a94030d3b..5f0d8af1c0 100644
@@ -1786,7 +1786,7 @@ static void gdb_accept(void)
     /* set short latency */
     socket_set_nodelay(fd);
 
-    s = g_malloc0(sizeof(GDBState));
+    s = g_new0(GDBState, 1);
     s->c_cpu = first_cpu;
     s->g_cpu = first_cpu;
     s->fd = fd;

gdbstub.c int gdbserver_start(const char *device) · line 1986

Quoted 8 lines
gdbstub.c +1 -1
@@ -1980,7 +1980,7 @@ int gdbserver_start(const char *device)
 
     s = gdbserver_state;
     if (!s) {
-        s = g_malloc0(sizeof(GDBState));
+        s = g_new0(GDBState, 1);
         gdbserver_state = s;
 
         qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL);

--
Alex Bennée

#115 lore raw

PATCH 79/88 hmp: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 hmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hmp.c +1 -1
index 739d330f4e..5157ac4223 100644
@@ -1917,7 +1917,7 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
             return;
         }
 
-        status = g_malloc0(sizeof(*status));
+        status = g_new0(HMPMigrationStatus, 1);
         status->mon = mon;
         status->is_block_migration = blk || inc;
         status->timer = timer_new_ms(QEMU_CLOCK_REALTIME, hmp_migrate_status_cb,
Signature · 1 line
2.14.2
#116 lore raw

PATCH 80/88 numa: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 numa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
numa.c +1 -1
index 100a67febf..35df996738 100644
@@ -66,7 +66,7 @@ void numa_set_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node)
         return;
     }
 
-    range = g_malloc0(sizeof(*range));
+    range = g_new0(struct numa_addr_range, 1);
     range->mem_start = addr;
     range->mem_end = addr + size - 1;
     QLIST_INSERT_HEAD(&numa_info[node].addr, range, entry);
Signature · 1 line
2.14.2
#117 lore raw

PATCH 81/88 hw/acpi: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 hw/acpi/vmgenid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/acpi/vmgenid.c +1 -1
index 2876d8a639..ced507d218 100644
@@ -269,7 +269,7 @@ GuidInfo *qmp_query_vm_generation_id(Error **errp)
     }
     vms = VMGENID(obj);
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(GuidInfo, 1);
     info->guid = qemu_uuid_unparse_strdup(&vms->guid);
     return info;
 }
Signature · 1 line
2.14.2
Reviewed-by on v1 81/88
#118 lore raw

Re: [Qemu-devel] [PATCH 81/88] hw/acpi: use g_new() family of functions

Quoted 4 lines · Philippe Mathieu-Daudé
Quoted 20 lines

---
hw/acpi/vmgenid.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
hw/acpi/vmgenid.c +1 -1
index 2876d8a639..ced507d218 100644
@@ -269,7 +269,7 @@ GuidInfo *qmp_query_vm_generation_id(Error **errp)
    }
    vms = VMGENID(obj);
 
-    info = g_malloc0(sizeof(*info));
+    info = g_new0(GuidInfo, 1);
    info->guid = qemu_uuid_unparse_strdup(&vms->guid);
    return info;
 }
Signature · 1 line
2.14.2
#119 lore raw

PATCH 82/88 hw/ipmi: use g_new() family of functions

In reply to Philippe Mathieu-Daudé

---
Shouldn't this file be under the PowerPC section of MAINTAINERS?

 hw/ipmi/ipmi_bmc_sim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ipmi/ipmi_bmc_sim.c +1 -1
index 277c28cb40..a68792a2cb 100644
@@ -1073,7 +1073,7 @@ static void send_msg(IPMIBmcSim *ibs,
         return;
     }
 
-    msg = g_malloc(sizeof(*msg));
+    msg = g_new(IPMIRcvBufEntry, 1);
     msg->buf[0] = ((netfn | 1) << 2) | rqLun; /* NetFN, and make a response */
     msg->buf[1] = ipmb_checksum(msg->buf, 1, 0);
     msg->buf[2] = cmd[0]; /* rsSA */
Signature · 1 line
2.14.2
#120 lore raw

PATCH 83/88 hw/pci: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 hw/pci/pci.c          | 2 +-
 hw/pci/pcie_port.c    | 2 +-
 tests/libqos/pci-pc.c | 2 +-
 tests/libqos/pci.c    | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
hw/pci/pci.c +1 -1
index 1e6fb88eba..32625d9fcc 100644
@@ -1644,7 +1644,7 @@ static PciMemoryRegionList *qmp_query_pci_regions(const PCIDevice *dev)
             continue;
         }
 
-        region = g_malloc0(sizeof(*region));
+        region = g_new0(PciMemoryRegionList, 1);
         region->value = g_malloc0(sizeof(*region->value));
 
         if (r->type & PCI_BASE_ADDRESS_SPACE_IO) {
hw/pci/pcie_port.c +1 -1
index 6432b9ac1f..236d8bc4db 100644
@@ -72,7 +72,7 @@ void pcie_chassis_create(uint8_t chassis_number)
     if (c) {
         return;
     }
-    c = g_malloc0(sizeof(*c));
+    c = g_new0(struct PCIEChassis, 1);
     c->number = chassis_number;
     QLIST_INIT(&c->slots);
     QLIST_INSERT_HEAD(&chassis, c, next);
tests/libqos/pci-pc.c +1 -1
index ded1c54c06..cde5e0a627 100644
@@ -119,7 +119,7 @@ QPCIBus *qpci_init_pc(QGuestAllocator *alloc)
 {
     QPCIBusPC *ret;
 
-    ret = g_malloc(sizeof(*ret));
+    ret = g_new(QPCIBusPC, 1);
 
     ret->bus.pio_readb = qpci_pc_pio_readb;
     ret->bus.pio_readw = qpci_pc_pio_readw;
tests/libqos/pci.c +1 -1
index 0b73cb23d0..9dd689c7b5 100644
@@ -54,7 +54,7 @@ QPCIDevice *qpci_device_find(QPCIBus *bus, int devfn)
 {
     QPCIDevice *dev;
 
-    dev = g_malloc0(sizeof(*dev));
+    dev = g_new0(QPCIDevice, 1);
     dev->bus = bus;
     dev->devfn = devfn;
 
Signature · 1 line
2.14.2
#121 lore raw

PATCH 84/88 hw/scsi: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 hw/scsi/vmw_pvscsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/scsi/vmw_pvscsi.c +1 -1
index d8079158ac..24d0306ede 100644
@@ -616,7 +616,7 @@ pvscsi_queue_pending_descriptor(PVSCSIState *s, SCSIDevice **d,
     PVSCSIRequest *pvscsi_req;
     uint8_t lun;
 
-    pvscsi_req = g_malloc0(sizeof(*pvscsi_req));
+    pvscsi_req = g_new0(PVSCSIRequest, 1);
     pvscsi_req->dev = s;
     pvscsi_req->req = *descr;
     pvscsi_req->cmp.context = pvscsi_req->req.context;
Signature · 1 line
2.14.2
#122 lore raw

PATCH 85/88 hw/usb: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 hw/usb/hcd-ehci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/hcd-ehci.c +1 -1
index 0134232627..34785923f3 100644
@@ -545,7 +545,7 @@ static EHCIQueue *ehci_alloc_queue(EHCIState *ehci, uint32_t addr, int async)
     EHCIQueueHead *head = async ? &ehci->aqueues : &ehci->pqueues;
     EHCIQueue *q;
 
-    q = g_malloc0(sizeof(*q));
+    q = g_new0(EHCIQueue, 1);
     q->ehci = ehci;
     q->qhaddr = addr;
     q->async = async;
Signature · 1 line
2.14.2
#123 lore raw

PATCH 86/88 net/hub: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 net/hub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/hub.c +1 -1
index 14b4eec68f..1c403859c6 100644
@@ -79,7 +79,7 @@ static NetHub *net_hub_new(int id)
 {
     NetHub *hub;
 
-    hub = g_malloc(sizeof(*hub));
+    hub = g_new(NetHub, 1);
     hub->id = id;
     hub->num_ports = 0;
     QLIST_INIT(&hub->ports);
Signature · 1 line
2.14.2
#124 lore raw

PATCH 87/88 hw/net/rocker: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 hw/net/rocker/rocker_of_dpa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/net/rocker/rocker_of_dpa.c +2 -2
index 191a58e0a7..990f4157a0 100644
@@ -2306,7 +2306,7 @@ static void of_dpa_flow_fill(void *cookie, void *value, void *user_data)
         return;
     }
 
-    new = g_malloc0(sizeof(*new));
+    new = g_new0(RockerOfDpaFlowList, 1);
     nflow = new->value = g_malloc0(sizeof(*nflow));
     nkey = nflow->key = g_malloc0(sizeof(*nkey));
     nmask = nflow->mask = g_malloc0(sizeof(*nmask));
@@ -2478,7 +2478,7 @@ static void of_dpa_group_fill(void *key, void *value, void *user_data)
         return;
     }
 
-    new = g_malloc0(sizeof(*new));
+    new = g_new0(RockerOfDpaGroupList, 1);
     ngroup = new->value = g_malloc0(sizeof(*ngroup));
 
     ngroup->id = group->id;
Signature · 1 line
2.14.2
#125 lore raw

PATCH 88/88 scripts/coverity-model: use g_new() family of functions

In reply to Philippe Mathieu-Daudé
---
 scripts/coverity-model.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coverity-model.c +1 -1
index c702804f41..de07bffb57 100644
@@ -363,7 +363,7 @@ int g_poll (GPollFD *fds, unsigned nfds, int timeout)
 typedef struct _GIOChannel GIOChannel;
 GIOChannel *g_io_channel_unix_new(int fd)
 {
-    GIOChannel *c = g_malloc0(sizeof(GIOChannel));
+    GIOChannel *c = g_new0(GIOChannel, 1);
     __coverity_escape__(fd);
     return c;
 }
Signature · 1 line
2.14.2
#126 lore raw

Re: [Qemu-devel] [PATCH 88/88] scripts/coverity-model: use g_new() family of functions

Please cc me on changes to stuff I maintain, as scripts/get_maintainer tells you :)

Quoted 10 lines · Philippe Mathieu-Daudé
---
 scripts/coverity-model.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/coverity-model.c +0 -0
index c702804f41..de07bffb57 100644

scripts/coverity-model.c int g_poll (GPollFD *fds, unsigned nfds, int timeout) · line 369

Quoted 8 lines
scripts/coverity-model.c +1 -1
@@ -363,7 +363,7 @@ int g_poll (GPollFD *fds, unsigned nfds, int timeout)
 typedef struct _GIOChannel GIOChannel;
 GIOChannel *g_io_channel_unix_new(int fd)
 {
-    GIOChannel *c = g_malloc0(sizeof(GIOChannel));
+    GIOChannel *c = g_new0(GIOChannel, 1);
     __coverity_escape__(fd);
     return c;
 }

Hmm.

The Coverity model carefully explains g_malloc0(). It doesn't explain g_new0(). With any luck, Coverity can see through g_new0() --- it's a macro in my <gmem.h>. But why complicate matters? The normal reason for changing g_malloc0() to g_new0() doesn't apply here. Let's leave the model alone.

#127 lore raw

Re: [Qemu-devel] [PATCH 88/88] scripts/coverity-model: use g_new() family of functions

Hi Markus,

Quoted 2 lines · Markus Armbruster

Please cc me on changes to stuff I maintain, as scripts/get_maintainer tells you :)

Oops I might have been a copy/paste error.

Quoted 5 lines
Quoted 3 lines · Philippe Mathieu-Daudé
---
 scripts/coverity-model.c | 2 +-

[...]

Quoted 8 lines

scripts/coverity-model.c int g_poll (GPollFD *fds, unsigned nfds, int timeout) · line 369

Quoted 7 lines

GIOChannel *g_io_channel_unix_new(int fd)
{

scripts/coverity-model.c +1 -1
-    GIOChannel *c = g_malloc0(sizeof(GIOChannel));
+    GIOChannel *c = g_new0(GIOChannel, 1);
     __coverity_escape__(fd);
     return c;
 }
Quoted 7 lines

Hmm.

The Coverity model carefully explains g_malloc0(). It doesn't explain g_new0(). With any luck, Coverity can see through g_new0() --- it's a macro in my <gmem.h>. But why complicate matters? The normal reason for changing g_malloc0() to g_new0() doesn't apply here. Let's leave the model alone.

Yes you are right.

#128 lore raw
In reply to Philippe Mathieu-Daudé

... and I obviously forgot to paste this...
(useful for Marc-André mostly)

[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively
001/88:[down] 'cocci: script to use g_new() & friends' 002/88:[down] 'cocci: add more g_new() transformations' 003/88:[down] 'cocci: extract typeof() from g_new()' 004/88:[down] 'cocci: avoid use of g_new0()'
005/88:[down] 'cocci: use g_strfreev()'
006/88:[down] 'ARM: use g_new() family of functions' 007/88:[0018] [FC] 'Audio: use g_new() family of functions' 008/88:[0002] [FC] 'BT: use g_new() family of functions' 009/88:[----] [--] 'Bootdevice: use g_new() family of functions' 010/88:[0006] [FC] 'Character devices: use g_new() family of functions' 011/88:[----] [--] 'Cryptodev Backends: use g_new() family of functions' 012/88:[down] 'backends/hostmem: use g_new() family of functions' 013/88:[0002] [FC] 'Dirty Bitmaps: use g_new() family of functions' 014/88:[down] 'ui/vnc: use g_new() family of functions' 015/88:[down] 'ui/spice: use g_new() family of functions' 016/88:[0022] [FC] 'Main loop: use g_new() family of functions' 017/88:[----] [--] 'Memory API: use g_new() family of functions' 018/88:[----] [--] 'memory: use g_new() family of functions' 019/88:[down] 'exec: use g_new() family of functions' 020/88:[0007] [FC] 'Migration: use g_new() family of functions' 021/88:[----] [--] 'NBD: use g_new() family of functions' 022/88:[0002] [FC] 'LM32: use g_new() family of functions' 023/88:[0009] [FC] 'M68K: use g_new() family of functions' 024/88:[0006] [FC] 'MIPS: use g_new() family of functions' 025/88:[0002] [FC] 'OpenRISC: use g_new() family of functions' 026/88:[0018] [FC] 'S390: use g_new() family of functions' 027/88:[0008] [FC] 'SH4: use g_new() family of functions' 028/88:[down] 'disas: use g_new() family of functions' 029/88:[0004] [FC] 'SPARC: use g_new() family of functions' 030/88:[0032] [FC] 'QEMU Guest Agent: use g_new() family of functions' 031/88:[0038] [FC] 'QMP: use g_new() family of functions' 032/88:[0016] [FC] 'QObject: use g_new() family of functions' 033/88:[down] 'qom: use g_new() family of functions' 034/88:[down] 'qapi: use g_new() family of functions' 035/88:[----] [--] 'Record/replay: use g_new() family of functions' 036/88:[0004] [FC] 'SLIRP: use g_new() family of functions' 037/88:[0002] [FC] 'TCG: use g_new() family of functions' 038/88:[0034] [FC] 'VFIO: use g_new() family of functions' 039/88:[down] 'hw/i386: use g_new() family of functions' 040/88:[down] 'hw/xen: use g_new() family of functions' 041/88:[down] 'target/i386: use g_new() family of functions' 042/88:[----] [--] 'XTFPGA: use g_new() family of functions' 043/88:[0002] [FC] 'hw/core: use g_new() family of functions' 044/88:[down] 'hw/core/loader: use g_new() family of functions' 045/88:[0002] [FC] 'hw/display: use g_new() family of functions' 046/88:[down] 'hw/display/vga: use g_new() family of functions' 047/88:[----] [--] 'hw/i2c: use g_new() family of functions' 048/88:[0002] [FC] 'hw/input: use g_new() family of functions' 049/88:[0002] [FC] 'hw/misc: use g_new() family of functions' 050/88:[----] [--] 'ivshmem: use g_new() family of functions' 051/88:[0002] [FC] 'hw/timer: use g_new() family of functions' 052/88:[----] [--] 'i.MX31: use g_new() family of functions' 053/88:[----] [--] 'iSCSI: use g_new() family of functions' 054/88:[0002] [FC] 'KVM: use g_new() family of functions' 055/88:[----] [--] 'PReP: use g_new() family of functions' 056/88:[0010] [FC] 'PowerPC: use g_new() family of functions' 057/88:[down] 'ppc: use g_new() family of functions' 058/88:[down] 'ppc4xx: use g_new() family of functions' 059/88:[0003] [FC] 'ppce500: use g_new() family of functions' 060/88:[0008] [FC] 'sPAPR: use g_new() family of functions' 061/88:[0020] [FC] 'tests: use g_new() family of functions' 062/88:[0002] [FC] 'user: use g_new() family of functions' 063/88:[down] 'bsd-user/syscall: fix a memory leak on EFAULT, use g_new()' 064/88:[----] [--] 'user: use g_strfreev()'
065/88:[0030] [FC] 'util: use g_new() family of functions' 066/88:[down] 'util/qemu-thread-win32: use g_new() family of functions' 067/88:[down] 'util/coroutine: use g_new() family of functions' 068/88:[0012] [FC] 'virtio: use g_new() family of functions' 069/88:[0004] [FC] 'virtio-9p: use g_new() family of functions' 070/88:[down] 'block: use g_new() family of functions' 071/88:[down] 'block: avoid use of g_new0()'
072/88:[down] 'hw/block/nvme: use g_new() family of functions' 073/88:[down] 'hw/block/xen_disk: avoid use of g_new0()' 074/88:[down] 'balloon: use g_new() family of functions' 075/88:[----] [--] 'decnumber: use g_new() family of functions' 076/88:[0002] [FC] 'dma: use g_new() family of functions' 077/88:[----] [--] 'dump: use g_new() family of functions' 078/88:[----] [--] 'gdb: use g_new() family of functions' 079/88:[down] 'hmp: use g_new() family of functions' 080/88:[down] 'numa: use g_new() family of functions' 081/88:[down] 'hw/acpi: use g_new() family of functions' 082/88:[down] 'hw/ipmi: use g_new() family of functions' 083/88:[down] 'hw/pci: use g_new() family of functions' 084/88:[down] 'hw/scsi: use g_new() family of functions' 085/88:[down] 'hw/usb: use g_new() family of functions' 086/88:[down] 'net/hub: use g_new() family of functions' 087/88:[down] 'hw/net/rocker: use g_new() family of functions' 088/88:[down] 'scripts/coverity-model: use g_new() family of functions'

Quoted 18 lines · Philippe Mathieu-Daudé

Hi,

This is a follow-up of Marc-André's clang-tidy series [1].
While chatting we realized we were trying to reach the same goal, Marc-André using clang-tidy and me using spatch; so he let me finish his series applying my changes over his.
I also included Jan's patch which fits well.

Summary:
- 1 bugfix (memory leak)
- few optimizations (avoid to zeroise when all memory is assigned)
- bunch of mechanical refactors

Regards,

Phil.

[1]: http://lists.nongnu.org/archive/html/qemu-devel/2017-09/msg00881.html

#129 lore raw
In reply to Philippe Mathieu-Daudé
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH 00/88] use g_new() family of functions

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
t [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
c804c28ce1 scripts/coverity-model: use g_new() family of functions b0e0658a5c hw/net/rocker: use g_new() family of functions 183562cc1d net/hub: use g_new() family of functions b9f50bfa72 hw/usb: use g_new() family of functions cff8a0d8e5 hw/scsi: use g_new() family of functions 071370df89 hw/pci: use g_new() family of functions 175fef7b9d hw/ipmi: use g_new() family of functions 5e8c9e184d hw/acpi: use g_new() family of functions 62ee9aea32 numa: use g_new() family of functions 57e59bd5a3 hmp: use g_new() family of functions
5736d72820 gdb: use g_new() family of functions
935c453c3e dump: use g_new() family of functions fe6b9cd532 dma: use g_new() family of functions
b80633b250 decnumber: use g_new() family of functions 330df41ca1 balloon: use g_new() family of functions 599de671cb hw/block/xen_disk: avoid use of g_new0() 21bb36804a hw/block/nvme: use g_new() family of functions 06226f3349 block: avoid use of g_new0()
ac1388fadb block: use g_new() family of functions 15186d5c50 virtio-9p: use g_new() family of functions 4db380eabf virtio: use g_new() family of functions 3e7a3445ce util/coroutine: use g_new() family of functions eb8027f518 util/qemu-thread-win32: use g_new() family of functions 6c3385656d util: use g_new() family of functions d4fcc9cbd7 user: use g_strfreev()
27cbb7ecf7 bsd-user/syscall: fix a memory leak on EFAULT, use g_new() 603f6d2797 user: use g_new() family of functions 8952c25f5d tests: use g_new() family of functions a76a1c1038 sPAPR: use g_new() family of functions 747d79335c ppce500: use g_new() family of functions d6737387c5 ppc4xx: use g_new() family of functions cc4e72bb73 ppc: use g_new() family of functions
f014ab5c23 PowerPC: use g_new() family of functions 1c7f285465 PReP: use g_new() family of functions a89817ffbd KVM: use g_new() family of functions
62e9ee5d6d iSCSI: use g_new() family of functions a5f0a975ad i.MX31: use g_new() family of functions e3c99cd21c hw/timer: use g_new() family of functions 57b0cb6f00 ivshmem: use g_new() family of functions ab0935ee66 hw/misc: use g_new() family of functions 51edcbd3d0 hw/input: use g_new() family of functions c5a983b01b hw/i2c: use g_new() family of functions 3d2167e517 hw/display/vga: use g_new() family of functions 6700833717 hw/display: use g_new() family of functions 3b6e0a9ba0 hw/core/loader: use g_new() family of functions 397f1320a0 hw/core: use g_new() family of functions 7fc29ad15d XTFPGA: use g_new() family of functions c9c7a78335 target/i386: use g_new() family of functions dcf5c388df hw/xen: use g_new() family of functions d359058b9c hw/i386: use g_new() family of functions 0f2bd5995e VFIO: use g_new() family of functions 6149f4936f TCG: use g_new() family of functions
2e7bd6ee2c SLIRP: use g_new() family of functions 48c3189a1e Record/replay: use g_new() family of functions eb4526cfb0 qapi: use g_new() family of functions 317f58f9f2 qom: use g_new() family of functions
f7c8362449 QObject: use g_new() family of functions 61a83549f4 QMP: use g_new() family of functions
3979392544 QEMU Guest Agent: use g_new() family of functions f00debd577 SPARC: use g_new() family of functions eb7a298007 disas: use g_new() family of functions 859752d9e4 SH4: use g_new() family of functions
875e2fd57b S390: use g_new() family of functions 18b1a93522 OpenRISC: use g_new() family of functions 98fc4795cd MIPS: use g_new() family of functions 13bc92e683 M68K: use g_new() family of functions 94928b9ef3 LM32: use g_new() family of functions 6014b8ee35 NBD: use g_new() family of functions
3e69886310 Migration: use g_new() family of functions 8920e8ca87 exec: use g_new() family of functions 701099c16e memory: use g_new() family of functions 5f388075f6 Memory API: use g_new() family of functions ccb604eee5 Main loop: use g_new() family of functions c294183f4e ui/spice: use g_new() family of functions 9c876c33e2 ui/vnc: use g_new() family of functions c943798f44 Dirty Bitmaps: use g_new() family of functions a19287589f backends/hostmem: use g_new() family of functions 1fbf4bcb17 Cryptodev Backends: use g_new() family of functions 91e8adaa1e Character devices: use g_new() family of functions 970467d2d3 Bootdevice: use g_new() family of functions debee4ea8b BT: use g_new() family of functions
94a157985c Audio: use g_new() family of functions 42db35f96b ARM: use g_new() family of functions
420a3342c4 cocci: use g_strfreev()
78845ef8df cocci: avoid use of g_new0()
f8c6a75cb5 cocci: extract typeof() from g_new()
97dbb2f234 cocci: add more g_new() transformations 8dbd9f91b4 cocci: script to use g_new() & friends

=== OUTPUT BEGIN ===
Checking PATCH 1/88: cocci: script to use g_new() & friends... Checking PATCH 2/88: cocci: add more g_new() transformations... Checking PATCH 3/88: cocci: extract typeof() from g_new()... Checking PATCH 4/88: cocci: avoid use of g_new0()...
Checking PATCH 5/88: cocci: use g_strfreev()...
Checking PATCH 6/88: ARM: use g_new() family of functions... Checking PATCH 7/88: Audio: use g_new() family of functions... Checking PATCH 8/88: BT: use g_new() family of functions... Checking PATCH 9/88: Bootdevice: use g_new() family of functions... Checking PATCH 10/88: Character devices: use g_new() family of functions... Checking PATCH 11/88: Cryptodev Backends: use g_new() family of functions... Checking PATCH 12/88: backends/hostmem: use g_new() family of functions... Checking PATCH 13/88: Dirty Bitmaps: use g_new() family of functions... Checking PATCH 14/88: ui/vnc: use g_new() family of functions... Checking PATCH 15/88: ui/spice: use g_new() family of functions... Checking PATCH 16/88: Main loop: use g_new() family of functions... Checking PATCH 17/88: Memory API: use g_new() family of functions... Checking PATCH 18/88: memory: use g_new() family of functions... Checking PATCH 19/88: exec: use g_new() family of functions... Checking PATCH 20/88: Migration: use g_new() family of functions... Checking PATCH 21/88: NBD: use g_new() family of functions... Checking PATCH 22/88: LM32: use g_new() family of functions... Checking PATCH 23/88: M68K: use g_new() family of functions... Checking PATCH 24/88: MIPS: use g_new() family of functions... Checking PATCH 25/88: OpenRISC: use g_new() family of functions... Checking PATCH 26/88: S390: use g_new() family of functions... Checking PATCH 27/88: SH4: use g_new() family of functions... Checking PATCH 28/88: disas: use g_new() family of functions...
ERROR: code indent should never use tabs
#38: FILE: disas/nios2.c:2628:
+^I new_hash = g_new(nios2_opcode_hash, 1);$

total: 1 errors, 0 warnings, 27 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 29/88: SPARC: use g_new() family of functions... Checking PATCH 30/88: QEMU Guest Agent: use g_new() family of functions... Checking PATCH 31/88: QMP: use g_new() family of functions... Checking PATCH 32/88: QObject: use g_new() family of functions... Checking PATCH 33/88: qom: use g_new() family of functions... Checking PATCH 34/88: qapi: use g_new() family of functions... Checking PATCH 35/88: Record/replay: use g_new() family of functions... Checking PATCH 36/88: SLIRP: use g_new() family of functions... Checking PATCH 37/88: TCG: use g_new() family of functions... Checking PATCH 38/88: VFIO: use g_new() family of functions...
WARNING: line over 80 characters
#176: FILE: hw/vfio/pci.c:1440:
+ vdev->msix->pending = g_new0(unsigned long, BITS_TO_LONGS(vdev->msix->entries));

total: 0 errors, 1 warnings, 169 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 39/88: hw/i386: use g_new() family of functions... Checking PATCH 40/88: hw/xen: use g_new() family of functions... Checking PATCH 41/88: target/i386: use g_new() family of functions... Checking PATCH 42/88: XTFPGA: use g_new() family of functions... Checking PATCH 43/88: hw/core: use g_new() family of functions... Checking PATCH 44/88: hw/core/loader: use g_new() family of functions... Checking PATCH 45/88: hw/display: use g_new() family of functions... Checking PATCH 46/88: hw/display/vga: use g_new() family of functions... Checking PATCH 47/88: hw/i2c: use g_new() family of functions... Checking PATCH 48/88: hw/input: use g_new() family of functions... Checking PATCH 49/88: hw/misc: use g_new() family of functions... Checking PATCH 50/88: ivshmem: use g_new() family of functions... Checking PATCH 51/88: hw/timer: use g_new() family of functions... Checking PATCH 52/88: i.MX31: use g_new() family of functions... Checking PATCH 53/88: iSCSI: use g_new() family of functions... Checking PATCH 54/88: KVM: use g_new() family of functions...
Checking PATCH 55/88: PReP: use g_new() family of functions... Checking PATCH 56/88: PowerPC: use g_new() family of functions... Checking PATCH 57/88: ppc: use g_new() family of functions...
Checking PATCH 58/88: ppc4xx: use g_new() family of functions... Checking PATCH 59/88: ppce500: use g_new() family of functions... Checking PATCH 60/88: sPAPR: use g_new() family of functions... Checking PATCH 61/88: tests: use g_new() family of functions... Checking PATCH 62/88: user: use g_new() family of functions... Checking PATCH 63/88: bsd-user/syscall: fix a memory leak on EFAULT, use g_new()... Checking PATCH 64/88: user: use g_strfreev()...
Checking PATCH 65/88: util: use g_new() family of functions...
ERROR: code indent should never use tabs
#54: FILE: util/envlist.c:27:
+^Ienvlist = g_new(envlist_t, 1);$

ERROR: code indent should never use tabs
#63: FILE: util/envlist.c:161:
+^Ientry = g_new(struct envlist_entry, 1);$

ERROR: code indent should never use tabs
#72: FILE: util/envlist.c:221:
+^Ipenv = env = g_new(char *, envlist->el_count + 1);$

total: 3 errors, 0 warnings, 120 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 66/88: util/qemu-thread-win32: use g_new() family of functions... Checking PATCH 67/88: util/coroutine: use g_new() family of functions... Checking PATCH 68/88: virtio: use g_new() family of functions... Checking PATCH 69/88: virtio-9p: use g_new() family of functions... Checking PATCH 70/88: block: use g_new() family of functions... Checking PATCH 71/88: block: avoid use of g_new0()...
Checking PATCH 72/88: hw/block/nvme: use g_new() family of functions... Checking PATCH 73/88: hw/block/xen_disk: avoid use of g_new0()... Checking PATCH 74/88: balloon: use g_new() family of functions... Checking PATCH 75/88: decnumber: use g_new() family of functions...
ERROR: code indent should never use tabs
#21: FILE: libdecnumber/decNumber.c:4092:
+^Iallocacc=g_new(uint16_t, need);$

ERROR: spaces required around that '=' (ctx:VxV)
#21: FILE: libdecnumber/decNumber.c:4092:
+ allocacc=g_new(uint16_t, need);
^

ERROR: spaces required around that '=' (ctx:VxV)
#30: FILE: libdecnumber/decNumber.c:4455:

+      allocacc=g_new(uint16_t, acclength);
               ^

ERROR: spaces required around that '=' (ctx:VxV)
#39: FILE: libdecnumber/decNumber.c:4480:

+      varalloc=g_new(uint16_t, (var1units+1));
               ^

ERROR: spaces required around that '+' (ctx:VxV)
#39: FILE: libdecnumber/decNumber.c:4480:

+      varalloc=g_new(uint16_t, (var1units+1));
                                          ^

ERROR: spaces required around that '=' (ctx:VxV)
#48: FILE: libdecnumber/decNumber.c:6317:

+    allocacc=g_new(uint16_t, need);
             ^

total: 6 errors, 0 warnings, 32 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 76/88: dma: use g_new() family of functions...
ERROR: code indent should never use tabs
#45: FILE: hw/dma/etraxfs_dma.c:771:
+^Ictrl = g_new0(struct fs_dma_ctrl, 1);$

total: 1 errors, 0 warnings, 34 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Checking PATCH 77/88: dump: use g_new() family of functions... Checking PATCH 78/88: gdb: use g_new() family of functions... Checking PATCH 79/88: hmp: use g_new() family of functions... Checking PATCH 80/88: numa: use g_new() family of functions... Checking PATCH 81/88: hw/acpi: use g_new() family of functions... Checking PATCH 82/88: hw/ipmi: use g_new() family of functions... Checking PATCH 83/88: hw/pci: use g_new() family of functions... Checking PATCH 84/88: hw/scsi: use g_new() family of functions... Checking PATCH 85/88: hw/usb: use g_new() family of functions... Checking PATCH 86/88: net/hub: use g_new() family of functions... Checking PATCH 87/88: hw/net/rocker: use g_new() family of functions... Checking PATCH 88/88: scripts/coverity-model: use g_new() family of functions... === OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]