qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Greg Kurz <groug@kaod.org>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: Re: [Qemu-devel] [PATCH v2 1/2] spapr_pci: convert g_malloc() to g_new()
Date: Mon, 15 Oct 2018 12:04:38 +1100	[thread overview]
Message-ID: <20181015010438.GI16167@umbus.fritz.box> (raw)
In-Reply-To: <153933510947.3834759.3504000962964977142.stgit@bahia.lan>

[-- Attachment #1: Type: text/plain, Size: 1323 bytes --]

On Fri, Oct 12, 2018 at 11:05:09AM +0200, Greg Kurz wrote:
> When allocating an array, it is a recommended coding practice to call
> g_new(FooType, n) instead of g_malloc(n * sizeof(FooType)) because
> it takes care to avoid overflow when calculating the size of the
> allocated block and it returns FooType *, which allows the compiler
> to perform type checking.
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>

Applied to ppc-for-3.1, thanks.

> ---
>  hw/ppc/spapr_pci.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index c2271e6ed462..0537ce018f51 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -1883,7 +1883,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) {
> 

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2018-10-15  2:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-12  9:04 [Qemu-devel] [PATCH v2 0/2] spapr_pci: coding style fixes Greg Kurz
2018-10-12  9:05 ` [Qemu-devel] [PATCH v2 1/2] spapr_pci: convert g_malloc() to g_new() Greg Kurz
2018-10-12  9:43   ` Philippe Mathieu-Daudé
2018-10-15  1:04   ` David Gibson [this message]
2018-10-12  9:05 ` [Qemu-devel] [PATCH v2 2/2] spapr_pci: rename some structured types Greg Kurz
2018-10-15  1:49   ` Alexey Kardashevskiy
2018-11-07  4:46     ` David Gibson
2018-11-08 11:48       ` Greg Kurz

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=20181015010438.GI16167@umbus.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=f4bug@amsat.org \
    --cc=groug@kaod.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /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).