From: Igor Mammedov <imammedo@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
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>,
qemu-devel@nongnu.org, "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>,
"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>,
"Yuval Shaia" <yuval.shaia.ml@gmail.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>,
xen-devel@lists.xenproject.org, "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>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [PATCH v2 3/3] Use g_new() & friends where that makes obvious sense
Date: Tue, 22 Mar 2022 12:21:24 +0100 [thread overview]
Message-ID: <20220322122124.4f1d76e9@redhat.com> (raw)
In-Reply-To: <20220315144156.1595462-4-armbru@redhat.com>
On Tue, 15 Mar 2022 15:41:56 +0100
Markus Armbruster <armbru@redhat.com> wrote:
> g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer,
> for two reasons. One, it catches multiplication overflowing size_t.
> Two, it returns T * rather than void *, which lets the compiler catch
> more type errors.
>
> This commit only touches allocations with size arguments of the form
> sizeof(T).
>
> Patch created mechanically with:
>
> $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci \
> --macro-file scripts/cocci-macro-file.h FILES...
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Reviewed-by: Cédric Le Goater <clg@kaod.org>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
for */i386/*
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
nit:
possible miss, see below
[...]
> diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
> index cf8e500514..0731f70410 100644
> --- a/hw/i386/xen/xen-hvm.c
> +++ b/hw/i386/xen/xen-hvm.c
missed:
pfn_list = g_malloc(sizeof (*pfn_list) * nr_pfn);
> @@ -396,7 +396,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;
> @@ -1281,7 +1281,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",
> @@ -1410,7 +1410,7 @@ void xen_hvm_init_pc(PCMachineState *pcms, MemoryRegion **ram_memory)
> xen_pfn_t ioreq_pfn;
> XenIOState *state;
>
> - state = g_malloc0(sizeof (XenIOState));
> + state = g_new0(XenIOState, 1);
>
> state->xce_handle = xenevtchn_open(NULL, 0);
> if (state->xce_handle == NULL) {
> @@ -1463,7 +1463,7 @@ void xen_hvm_init_pc(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) {
> @@ -1472,7 +1472,7 @@ void xen_hvm_init_pc(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);
[...]
next prev parent reply other threads:[~2022-03-22 11:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-15 14:41 [PATCH v2 0/3] Use g_new() & friends where that makes obvious sense Markus Armbruster
2022-03-15 14:41 ` [PATCH v2 1/3] scripts/coccinelle: New use-g_new-etc.cocci Markus Armbruster
2022-03-15 14:41 ` [PATCH v2 2/3] 9pfs: Use g_new() & friends where that makes obvious sense Markus Armbruster
2022-03-15 14:41 ` [PATCH v2 3/3] " Markus Armbruster
2022-03-17 5:01 ` Pavel Dovgalyuk
2022-03-22 11:21 ` Igor Mammedov [this message]
2022-03-22 17:21 ` Klaus Jensen
2022-03-22 13:25 ` [PATCH v2 0/3] " Michael S. Tsirkin
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=20220322122124.4f1d76e9@redhat.com \
--to=imammedo@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=armbru@redhat.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=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=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).