From: "Daniel P. Berrange" <berrange@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: Olaf Hering <olaf@aepfle.de>,
Stefano Stabellini <sstabellini@kernel.org>,
Anthony Perard <anthony.perard@citrix.com>,
Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
"open list:X86" <xen-devel@lists.xenproject.org>,
"open list:Block layer core" <qemu-block@nongnu.org>,
"open list:All patches CC here" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] xen-disk: use g_malloc0 to fix build
Date: Fri, 28 Jul 2017 13:52:07 +0100 [thread overview]
Message-ID: <20170728125207.GN31495@redhat.com> (raw)
In-Reply-To: <d8aca223-4007-6524-9876-fe32fd81e893@redhat.com>
On Fri, Jul 28, 2017 at 07:43:59AM -0500, Eric Blake wrote:
> On 07/28/2017 07:31 AM, Olaf Hering wrote:
> > g_malloc0_n is available since glib-2.24. To allow build with older glib
> > versions use the generic g_malloc0, which is already used in many other
> > places in the code.
> >
> > Fixes commit 3284fad728 ("xen-disk: add support for multi-page shared rings")
> >
> > Signed-off-by: Olaf Hering <olaf@aepfle.de>
> > ---
> > hw/block/xen_disk.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
> > index d42ed7070d..71deec17b0 100644
> > --- a/hw/block/xen_disk.c
> > +++ b/hw/block/xen_disk.c
> > @@ -1232,7 +1232,7 @@ static int blk_connect(struct XenDevice *xendev)
> > return -1;
> > }
> >
> > - domids = g_malloc0_n(blkdev->nr_ring_ref, sizeof(uint32_t));
> > + domids = g_malloc0(blkdev->nr_ring_ref * sizeof(uint32_t));
>
> This version is prone to multiplication overflow (well, maybe not, but
> you have to audit for that). Wouldn't it be better to use:
>
> domids = g_new0(blkdev->nr_ring_ref, uint32_t)
You mean g_new0(uint32_t, blkdev->nr_ring_ref) but yeah, g_new0 is
better than g_malloc0 pretty much every time.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
prev parent reply other threads:[~2017-07-28 12:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-28 12:31 [Qemu-devel] [PATCH] xen-disk: use g_malloc0 to fix build Olaf Hering
2017-07-28 12:31 ` Olaf Hering
2017-07-28 12:43 ` [Qemu-devel] " Eric Blake
2017-07-28 12:43 ` Eric Blake
2017-07-28 12:48 ` Olaf Hering
2017-07-28 12:48 ` Olaf Hering
2017-07-28 13:00 ` Eric Blake
2017-07-28 13:00 ` Eric Blake
2017-07-28 16:35 ` Markus Armbruster
2017-07-28 16:35 ` Markus Armbruster
2017-07-28 12:52 ` Daniel P. Berrange
2017-07-28 12:52 ` Daniel P. Berrange [this message]
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=20170728125207.GN31495@redhat.com \
--to=berrange@redhat.com \
--cc=anthony.perard@citrix.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=olaf@aepfle.de \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.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 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.