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

* 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>

Just a small patch then...

> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> index d65e744af9..aace12a787 100644
> --- a/migration/dirtyrate.c
> +++ b/migration/dirtyrate.c
> @@ -91,7 +91,7 @@ static struct DirtyRateInfo *query_dirty_rate_info(void)
>  {
>      int i;
>      int64_t dirty_rate = DirtyStat.dirty_rate;
> -    struct DirtyRateInfo *info = g_malloc0(sizeof(DirtyRateInfo));
> +    struct DirtyRateInfo *info = g_new0(DirtyRateInfo, 1);
>      DirtyRateVcpuList *head = NULL, **tail = &head;
>  
>      info->status = CalculatingState;
> @@ -112,7 +112,7 @@ static struct DirtyRateInfo *query_dirty_rate_info(void)
>              info->sample_pages = 0;
>              info->has_vcpu_dirty_rate = true;
>              for (i = 0; i < DirtyStat.dirty_ring.nvcpu; i++) {
> -                DirtyRateVcpu *rate = g_malloc0(sizeof(DirtyRateVcpu));
> +                DirtyRateVcpu *rate = g_new0(DirtyRateVcpu, 1);
>                  rate->id = DirtyStat.dirty_ring.rates[i].id;
>                  rate->dirty_rate = DirtyStat.dirty_ring.rates[i].dirty_rate;
>                  QAPI_LIST_APPEND(tail, rate);
> diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c
> index aba1c88a0c..3a7ae44485 100644
> --- a/migration/multifd-zlib.c
> +++ b/migration/multifd-zlib.c
> @@ -43,7 +43,7 @@ struct zlib_data {
>   */
>  static int zlib_send_setup(MultiFDSendParams *p, Error **errp)
>  {
> -    struct zlib_data *z = g_malloc0(sizeof(struct zlib_data));
> +    struct zlib_data *z = g_new0(struct zlib_data, 1);
>      z_stream *zs = &z->zs;
>  
>      zs->zalloc = Z_NULL;
> @@ -164,7 +164,7 @@ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp)
>   */
>  static int zlib_recv_setup(MultiFDRecvParams *p, Error **errp)
>  {
> -    struct zlib_data *z = g_malloc0(sizeof(struct zlib_data));
> +    struct zlib_data *z = g_new0(struct zlib_data, 1);
>      z_stream *zs = &z->zs;
>  
>      p->data = z;
> diff --git a/migration/ram.c b/migration/ram.c
> index 170e522a1f..3532f64ecb 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -2059,7 +2059,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len)
>      }
>  
>      struct RAMSrcPageRequest *new_entry =
> -        g_malloc0(sizeof(struct RAMSrcPageRequest));
> +        g_new0(struct RAMSrcPageRequest, 1);
>      new_entry->rb = ramblock;
>      new_entry->offset = start;
>      new_entry->len = len;

For migration:
Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK


WARNING: multiple messages have this Message-ID (diff)
From: "Dr. David Alan Gilbert" <dgilbert@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>,
	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>,
	"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>,
	"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: Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense
Date: Tue, 15 Mar 2022 10:58:28 +0000	[thread overview]
Message-ID: <YjBxVFUw2DtBniYS@work-vm> (raw)
In-Reply-To: <20220314160108.1440470-4-armbru@redhat.com>

* 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>

Just a small patch then...

> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> index d65e744af9..aace12a787 100644
> --- a/migration/dirtyrate.c
> +++ b/migration/dirtyrate.c
> @@ -91,7 +91,7 @@ static struct DirtyRateInfo *query_dirty_rate_info(void)
>  {
>      int i;
>      int64_t dirty_rate = DirtyStat.dirty_rate;
> -    struct DirtyRateInfo *info = g_malloc0(sizeof(DirtyRateInfo));
> +    struct DirtyRateInfo *info = g_new0(DirtyRateInfo, 1);
>      DirtyRateVcpuList *head = NULL, **tail = &head;
>  
>      info->status = CalculatingState;
> @@ -112,7 +112,7 @@ static struct DirtyRateInfo *query_dirty_rate_info(void)
>              info->sample_pages = 0;
>              info->has_vcpu_dirty_rate = true;
>              for (i = 0; i < DirtyStat.dirty_ring.nvcpu; i++) {
> -                DirtyRateVcpu *rate = g_malloc0(sizeof(DirtyRateVcpu));
> +                DirtyRateVcpu *rate = g_new0(DirtyRateVcpu, 1);
>                  rate->id = DirtyStat.dirty_ring.rates[i].id;
>                  rate->dirty_rate = DirtyStat.dirty_ring.rates[i].dirty_rate;
>                  QAPI_LIST_APPEND(tail, rate);
> diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c
> index aba1c88a0c..3a7ae44485 100644
> --- a/migration/multifd-zlib.c
> +++ b/migration/multifd-zlib.c
> @@ -43,7 +43,7 @@ struct zlib_data {
>   */
>  static int zlib_send_setup(MultiFDSendParams *p, Error **errp)
>  {
> -    struct zlib_data *z = g_malloc0(sizeof(struct zlib_data));
> +    struct zlib_data *z = g_new0(struct zlib_data, 1);
>      z_stream *zs = &z->zs;
>  
>      zs->zalloc = Z_NULL;
> @@ -164,7 +164,7 @@ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp)
>   */
>  static int zlib_recv_setup(MultiFDRecvParams *p, Error **errp)
>  {
> -    struct zlib_data *z = g_malloc0(sizeof(struct zlib_data));
> +    struct zlib_data *z = g_new0(struct zlib_data, 1);
>      z_stream *zs = &z->zs;
>  
>      p->data = z;
> diff --git a/migration/ram.c b/migration/ram.c
> index 170e522a1f..3532f64ecb 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -2059,7 +2059,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len)
>      }
>  
>      struct RAMSrcPageRequest *new_entry =
> -        g_malloc0(sizeof(struct RAMSrcPageRequest));
> +        g_new0(struct RAMSrcPageRequest, 1);
>      new_entry->rb = ramblock;
>      new_entry->offset = start;
>      new_entry->len = len;

For migration:
Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



  parent reply	other threads:[~2022-03-15 10:58 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-14 16:01 [PATCH 0/3] Use g_new() & friends where that makes obvious Markus Armbruster
2022-03-14 16:01 ` Markus Armbruster
2022-03-14 16:01 ` [PATCH 1/3] scripts/coccinelle: New use-g_new-etc.cocci Markus Armbruster
2022-03-14 16:01   ` Markus Armbruster
2022-03-14 19:07   ` Richard Henderson
2022-03-14 19:22   ` Alex Bennée
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:01   ` Markus Armbruster
2022-03-14 16:42   ` Christian Schoenebeck
2022-03-14 18:46     ` Philippe Mathieu-Daudé
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-14 19:23     ` Alex Bennée
2022-03-15  7:53   ` Greg Kurz
2022-03-15  7:53     ` Greg Kurz
2022-03-14 16:01 ` [PATCH 3/3] " Markus Armbruster
2022-03-14 16:01   ` Markus Armbruster
2022-03-14 16:08   ` Peter Maydell
2022-03-14 16:08     ` Peter Maydell
2022-03-14 16:52     ` Markus Armbruster
2022-03-14 16:52       ` Markus Armbruster
2022-03-14 17:39       ` Daniel P. Berrangé
2022-03-14 17:39         ` Daniel P. Berrangé
2022-03-14 17:06   ` Cédric Le Goater
2022-03-14 17:06     ` Cédric Le Goater
2022-03-14 19:48   ` Alex Bennée
2022-03-14 19:48     ` Alex Bennée
2022-03-14 20:37     ` Christian Schoenebeck
2022-03-15 13:49     ` Markus Armbruster
2022-03-15 13:49       ` Markus Armbruster
2022-03-14 22:52   ` Alex Bennée
2022-03-14 22:52     ` Alex Bennée
2022-03-15 13:59     ` Markus Armbruster
2022-03-15 13:59       ` Markus Armbruster
2022-03-15 14:07       ` Philippe Mathieu-Daudé
2022-03-15 14:07         ` Philippe Mathieu-Daudé
2022-03-15 14:43         ` Markus Armbruster
2022-03-15 14:43           ` Markus Armbruster
2022-03-15 16:16           ` Alex Bennée
2022-03-15 16:16             ` Alex Bennée
2022-03-15  9:07   ` Eric Blake
2022-03-15  9:07     ` Eric Blake
2022-03-15 14:03     ` Markus Armbruster
2022-03-15 14:03       ` Markus Armbruster
2022-03-15 10:58   ` Dr. David Alan Gilbert [this message]
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é
2022-03-14 16:41   ` 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=YjBxVFUw2DtBniYS@work-vm \
    --to=dgilbert@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=colin.xu@intel.com \
    --cc=danielhb413@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@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=marcel.apfelbaum@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.