qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Cody <jcody@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com,
	mreitz@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 1/4] block: Use g_new() & friends where that makes obvious sense
Date: Mon, 18 Aug 2014 15:43:35 -0400	[thread overview]
Message-ID: <20140818194335.GB2627@localhost.localdomain> (raw)
In-Reply-To: <1408378243-19713-2-git-send-email-armbru@redhat.com>

On Mon, Aug 18, 2014 at 06:10:40PM +0200, Markus Armbruster 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.
> 
> Patch created with Coccinelle, with two manual changes on top:
> 
> * Add const to bdrv_iterate_format() to keep the types straight
> 
> * Convert the allocation in bdrv_drop_intermediate(), which Coccinelle
>   inexplicably misses
> 
> Coccinelle semantic patch:
> 
>     @@
>     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)
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  block-migration.c      |  6 +++---
>  block.c                | 14 +++++++-------
>  block/archipelago.c    |  6 +++---
>  block/gluster.c        |  8 ++++----
>  block/iscsi.c          |  2 +-
>  block/nfs.c            |  2 +-
>  block/qcow.c           |  2 +-
>  block/qcow2-cluster.c  |  2 +-
>  block/qcow2-refcount.c |  8 ++++----
>  block/qcow2-snapshot.c |  8 ++++----
>  block/raw-posix.c      |  2 +-
>  block/rbd.c            |  4 ++--
>  block/sheepdog.c       |  4 ++--
>  block/vdi.c            |  2 +-
>  block/vhdx.c           |  4 ++--
>  block/vmdk.c           |  7 +++----
>  block/vvfat.c          |  2 +-
>  blockdev-nbd.c         |  2 +-
>  blockdev.c             |  2 +-
>  hw/ide/ahci.c          |  2 +-
>  qemu-io-cmds.c         |  2 +-
>  qemu-io.c              |  2 +-
>  22 files changed, 46 insertions(+), 47 deletions(-)

[...]

Reviewed-by: Jeff Cody <jcody@redhat.com>

  parent reply	other threads:[~2014-08-18 19:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-18 16:10 [Qemu-devel] [PATCH v2 0/4] block: Use g_new() & friends more Markus Armbruster
2014-08-18 16:10 ` [Qemu-devel] [PATCH v2 1/4] block: Use g_new() & friends where that makes obvious sense Markus Armbruster
2014-08-18 16:35   ` Max Reitz
2014-08-18 19:43   ` Jeff Cody [this message]
2014-08-18 16:10 ` [Qemu-devel] [PATCH v2 2/4] block: Use g_new() & friends to avoid multiplying sizes Markus Armbruster
2014-08-18 16:48   ` Max Reitz
2014-08-18 19:57   ` Jeff Cody
2014-08-18 16:10 ` [Qemu-devel] [PATCH v2 3/4] qemu-io-cmds: g_renew() can't fail, bury dead error handling Markus Armbruster
2014-08-18 16:50   ` Max Reitz
2014-08-18 19:59   ` Jeff Cody
2014-08-18 16:10 ` [Qemu-devel] [PATCH v2 4/4] block: Drop some superfluous casts from void * Markus Armbruster
2014-08-18 16:58   ` Max Reitz
2014-08-19  7:10     ` Markus Armbruster
2014-08-18 20:06   ` Jeff Cody
2014-08-19  7:10     ` Markus Armbruster
2014-08-19  8:33       ` Markus Armbruster

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=20140818194335.GB2627@localhost.localdomain \
    --to=jcody@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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).