qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Daniel Henrique Barboza" <danielhb413@gmail.com>,
	kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Christian Schoenebeck" <qemu_oss@crudebyte.com>,
	"Yuval Shaia" <yuval.shaia.ml@gmail.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Klaus Jensen" <its@irrelevant.dk>,
	"KONRAD Frederic" <frederic.konrad@adacore.com>,
	"Konstantin Kostiuk" <kkostiuk@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Ani Sinha" <ani@anisinha.ca>,
	"Reinoud Zandijk" <reinoud@netbsd.org>,
	"Eric Blake" <eblake@redhat.com>,
	"Sunil Muthuswamy" <sunilmut@microsoft.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	xen-devel@lists.xenproject.org,
	"Yoshinori Sato" <ysato@users.sourceforge.jp>,
	"Juan Quintela" <quintela@redhat.com>,
	"John Snow" <jsnow@redhat.com>, "Paul Durrant" <paul@xen.org>,
	"Magnus Damm" <magnus.damm@gmail.com>,
	"Kamil Rytarowski" <kamil@netbsd.org>,
	"Gonglei (Arei)" <arei.gonglei@huawei.com>,
	"Hervé Poussineau" <hpoussin@reactos.org>,
	"Michael Roth" <michael.roth@amd.com>,
	"Anthony Perard" <anthony.perard@citrix.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Artyom Tarasenko" <atar4qemu@gmail.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
	"Amit Shah" <amit@kernel.org>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	haxm-team@intel.com,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Greg Kurz" <groug@kaod.org>,
	"Fabien Chouteau" <chouteau@adacore.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Eric Auger" <eric.auger@redhat.com>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	qemu-arm@nongnu.org, "Cédric Le Goater" <clg@kaod.org>,
	"Pavel Dovgalyuk" <pavel.dovgaluk@ispras.ru>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Keith Busch" <kbusch@kernel.org>,
	qemu-ppc@nongnu.org, "David Hildenbrand" <david@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	qemu-block@nongnu.org, "Max Filippov" <jcmvbkbc@gmail.com>,
	qemu-s390x@nongnu.org, "Patrick Venture" <venture@google.com>,
	"Cornelia Huck" <cohuck@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Jean-Christophe Dubois" <jcd@tribudubois.net>,
	"Corey Minyard" <cminyard@mvista.com>,
	"Wenchao Wang" <wenchao.wang@intel.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Colin Xu" <colin.xu@intel.com>
Subject: [PATCH 0/3] Use g_new() & friends where that makes obvious
Date: Mon, 14 Mar 2022 17:01:05 +0100	[thread overview]
Message-ID: <20220314160108.1440470-1-armbru@redhat.com> (raw)

g_new(T, n) is neater than g_malloc(sizeof(T) * n).  It's also safer,
for two reasons.  One, it catches multiplication overflowing size_t.
Two, it returns T * rather than void *, which lets the compiler catch
more type errors.

This series only touches allocations with size arguments of the form
sizeof(T).  It's mechanical, except for a tiny fix in PATCH 2.

PATCH 1 adds the Coccinelle script.

PATCH 2 cleans up the virtio-9p subsystem, and fixes a harmless typing
error uncovered by the cleanup.

PATCH 3 cleans up everything else.  I started to split it up, but
splitting is a lot of decisions, and I just can't see the value.

For instance, MAINTAINERS tells me to split for subsystem "virtio",
patching

    hw/char/virtio-serial-bus.c
    hw/display/virtio-gpu.c
    hw/net/virtio-net.c
    hw/virtio/virtio-crypto.c
    hw/virtio/virtio-iommu.c
    hw/virtio/virtio.c

But it also tells me to split for subsystem "Character devices",
patching

    hw/char/parallel.c                       |  2 +-
    hw/char/riscv_htif.c                     |  2 +-
    hw/char/virtio-serial-bus.c              |  6 +-

and for subsystem "Network devices", patching

    hw/net/virtio-net.c

and for subsystem "virtio-gpu", patching

    hw/display/virtio-gpu.c

I guess I'd go with "virtio".  Six files down, 103 to go.  Thanks, but
no thanks.

Since the transformation is local to a function call, dropping is
completely safe.  We can deal with conflicts by dropping conflicting
hunks, with "git-pull -s recursive -X ours".  Or drop entire files
with conflicts.

If you want me to split off certain parts, please tell me exactly what
you want split off, and I'll gladly do the splitting.  I don't mind
the splitting part, I do mind the *thinking* part.

Markus Armbruster (3):
  scripts/coccinelle: New use-g_new-etc.cocci
  9pfs: Use g_new() & friends where that makes obvious sense
  Use g_new() & friends where that makes obvious sense

 scripts/coccinelle/use-g_new-etc.cocci   | 75 ++++++++++++++++++++++++
 include/qemu/timer.h                     |  2 +-
 accel/kvm/kvm-all.c                      |  6 +-
 accel/tcg/tcg-accel-ops-mttcg.c          |  2 +-
 accel/tcg/tcg-accel-ops-rr.c             |  4 +-
 audio/audio.c                            |  4 +-
 audio/audio_legacy.c                     |  6 +-
 audio/dsoundaudio.c                      |  2 +-
 audio/jackaudio.c                        |  6 +-
 audio/paaudio.c                          |  4 +-
 backends/cryptodev.c                     |  2 +-
 contrib/vhost-user-gpu/vhost-user-gpu.c  |  2 +-
 cpus-common.c                            |  4 +-
 dump/dump.c                              |  2 +-
 hw/9pfs/9p-proxy.c                       |  2 +-
 hw/9pfs/9p-synth.c                       |  4 +-
 hw/9pfs/9p.c                             |  8 +--
 hw/9pfs/codir.c                          |  6 +-
 hw/acpi/hmat.c                           |  2 +-
 hw/audio/intel-hda.c                     |  2 +-
 hw/char/parallel.c                       |  2 +-
 hw/char/riscv_htif.c                     |  2 +-
 hw/char/virtio-serial-bus.c              |  6 +-
 hw/core/irq.c                            |  2 +-
 hw/core/reset.c                          |  2 +-
 hw/display/pxa2xx_lcd.c                  |  2 +-
 hw/display/tc6393xb.c                    |  2 +-
 hw/display/virtio-gpu.c                  |  4 +-
 hw/display/xenfb.c                       |  4 +-
 hw/dma/rc4030.c                          |  4 +-
 hw/i2c/core.c                            |  4 +-
 hw/i2c/i2c_mux_pca954x.c                 |  2 +-
 hw/i386/amd_iommu.c                      |  4 +-
 hw/i386/intel_iommu.c                    |  2 +-
 hw/i386/xen/xen-hvm.c                    | 10 ++--
 hw/i386/xen/xen-mapcache.c               | 14 ++---
 hw/input/lasips2.c                       |  2 +-
 hw/input/pckbd.c                         |  2 +-
 hw/input/ps2.c                           |  4 +-
 hw/input/pxa2xx_keypad.c                 |  2 +-
 hw/input/tsc2005.c                       |  3 +-
 hw/intc/riscv_aclint.c                   |  6 +-
 hw/intc/xics.c                           |  2 +-
 hw/m68k/virt.c                           |  2 +-
 hw/mips/mipssim.c                        |  2 +-
 hw/misc/applesmc.c                       |  2 +-
 hw/misc/imx6_src.c                       |  2 +-
 hw/misc/ivshmem.c                        |  4 +-
 hw/net/virtio-net.c                      |  4 +-
 hw/nvme/ns.c                             |  2 +-
 hw/pci-host/pnv_phb3.c                   |  2 +-
 hw/pci-host/pnv_phb4.c                   |  2 +-
 hw/pci/pcie_sriov.c                      |  2 +-
 hw/ppc/e500.c                            |  2 +-
 hw/ppc/ppc.c                             |  8 +--
 hw/ppc/ppc405_boards.c                   |  4 +-
 hw/ppc/ppc405_uc.c                       | 18 +++---
 hw/ppc/ppc4xx_devs.c                     |  2 +-
 hw/ppc/ppc_booke.c                       |  4 +-
 hw/ppc/spapr.c                           |  2 +-
 hw/ppc/spapr_events.c                    |  2 +-
 hw/ppc/spapr_hcall.c                     |  2 +-
 hw/ppc/spapr_numa.c                      |  3 +-
 hw/rdma/vmw/pvrdma_dev_ring.c            |  2 +-
 hw/rdma/vmw/pvrdma_qp_ops.c              |  6 +-
 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/slavio_timer.c                  |  2 +-
 hw/vfio/pci.c                            |  4 +-
 hw/vfio/platform.c                       |  4 +-
 hw/virtio/virtio-crypto.c                |  2 +-
 hw/virtio/virtio-iommu.c                 |  2 +-
 hw/virtio/virtio.c                       |  5 +-
 hw/xtensa/xtfpga.c                       |  2 +-
 linux-user/syscall.c                     |  2 +-
 migration/dirtyrate.c                    |  4 +-
 migration/multifd-zlib.c                 |  4 +-
 migration/ram.c                          |  2 +-
 monitor/misc.c                           |  2 +-
 monitor/qmp-cmds.c                       |  2 +-
 qga/commands-win32.c                     |  8 +--
 qga/commands.c                           |  2 +-
 qom/qom-qmp-cmds.c                       |  2 +-
 replay/replay-char.c                     |  4 +-
 replay/replay-events.c                   | 10 ++--
 scripts/coverity-scan/model.c            |  2 +-
 semihosting/config.c                     |  2 +-
 softmmu/bootdevice.c                     |  4 +-
 softmmu/dma-helpers.c                    |  4 +-
 softmmu/memory_mapping.c                 |  2 +-
 target/i386/cpu-sysemu.c                 |  2 +-
 target/i386/hax/hax-accel-ops.c          |  4 +-
 target/i386/nvmm/nvmm-accel-ops.c        |  4 +-
 target/i386/whpx/whpx-accel-ops.c        |  4 +-
 target/i386/whpx/whpx-all.c              |  2 +-
 target/s390x/cpu-sysemu.c                |  2 +-
 tests/qtest/virtio-9p-test.c             |  4 +-
 tests/unit/test-hbitmap.c                |  2 +-
 tests/unit/test-qmp-cmds.c               | 14 ++---
 tests/unit/test-qobject-output-visitor.c |  2 +-
 tests/unit/test-vmstate.c                | 42 ++++++-------
 ui/vnc-enc-tight.c                       |  2 +-
 util/envlist.c                           |  2 +-
 util/hbitmap.c                           |  2 +-
 util/main-loop.c                         |  2 +-
 util/qemu-timer.c                        |  2 +-
 util/vfio-helpers.c                      |  4 +-
 110 files changed, 284 insertions(+), 214 deletions(-)
 create mode 100644 scripts/coccinelle/use-g_new-etc.cocci

--
2.35.1



             reply	other threads:[~2022-03-14 16:03 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-14 16:01 Markus Armbruster [this message]
2022-03-14 16:01 ` [PATCH 1/3] scripts/coccinelle: New use-g_new-etc.cocci Markus Armbruster
2022-03-14 19:07   ` Richard Henderson
2022-03-14 19:22   ` Alex Bennée
2022-03-14 16:01 ` [PATCH 2/3] 9pfs: Use g_new() & friends where that makes obvious sense Markus Armbruster
2022-03-14 16:42   ` Christian Schoenebeck
2022-03-14 18:46     ` Philippe Mathieu-Daudé
2022-03-14 19:19       ` Christian Schoenebeck
2022-03-14 19:23   ` Alex Bennée
2022-03-15  7:53   ` Greg Kurz
2022-03-14 16:01 ` [PATCH 3/3] " Markus Armbruster
2022-03-14 16:08   ` Peter Maydell
2022-03-14 16:52     ` Markus Armbruster
2022-03-14 17:39       ` Daniel P. Berrangé
2022-03-14 17:06   ` Cédric Le Goater
2022-03-14 19:48   ` Alex Bennée
2022-03-14 20:37     ` Christian Schoenebeck
2022-03-15 13:49     ` Markus Armbruster
2022-03-14 22:52   ` Alex Bennée
2022-03-15 13:59     ` Markus Armbruster
2022-03-15 14:07       ` Philippe Mathieu-Daudé
2022-03-15 14:43         ` Markus Armbruster
2022-03-15 16:16           ` Alex Bennée
2022-03-15  9:07   ` Eric Blake
2022-03-15 14:03     ` Markus Armbruster
2022-03-15 10:58   ` Dr. David Alan Gilbert
2022-03-14 16:41 ` [PATCH 0/3] Use g_new() & friends where that makes obvious Philippe Mathieu-Daudé

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20220314160108.1440470-1-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=aleksandar.rikalo@syrmia.com \
    --cc=alex.bennee@linaro.org \
    --cc=alex.williamson@redhat.com \
    --cc=amit@kernel.org \
    --cc=ani@anisinha.ca \
    --cc=anthony.perard@citrix.com \
    --cc=arei.gonglei@huawei.com \
    --cc=atar4qemu@gmail.com \
    --cc=berrange@redhat.com \
    --cc=chouteau@adacore.com \
    --cc=clg@kaod.org \
    --cc=cminyard@mvista.com \
    --cc=cohuck@redhat.com \
    --cc=colin.xu@intel.com \
    --cc=danielhb413@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=eric.auger@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=frederic.konrad@adacore.com \
    --cc=groug@kaod.org \
    --cc=haxm-team@intel.com \
    --cc=hpoussin@reactos.org \
    --cc=imammedo@redhat.com \
    --cc=its@irrelevant.dk \
    --cc=jasowang@redhat.com \
    --cc=jcd@tribudubois.net \
    --cc=jcmvbkbc@gmail.com \
    --cc=jsnow@redhat.com \
    --cc=kamil@netbsd.org \
    --cc=kbusch@kernel.org \
    --cc=kkostiuk@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=magnus.damm@gmail.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=michael.roth@amd.com \
    --cc=mst@redhat.com \
    --cc=paul@xen.org \
    --cc=pavel.dovgaluk@ispras.ru \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=qemu_oss@crudebyte.com \
    --cc=quintela@redhat.com \
    --cc=reinoud@netbsd.org \
    --cc=richard.henderson@linaro.org \
    --cc=sstabellini@kernel.org \
    --cc=sunilmut@microsoft.com \
    --cc=thuth@redhat.com \
    --cc=venture@google.com \
    --cc=vsementsov@virtuozzo.com \
    --cc=wenchao.wang@intel.com \
    --cc=xen-devel@lists.xenproject.org \
    --cc=ysato@users.sourceforge.jp \
    --cc=yuval.shaia.ml@gmail.com \
    /path/to/YOUR_REPLY

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

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