From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36232) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z30OH-0001Pm-Sv for qemu-devel@nongnu.org; Thu, 11 Jun 2015 07:11:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z30OD-0006if-Np for qemu-devel@nongnu.org; Thu, 11 Jun 2015 07:11:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41537) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z30OD-0006hx-JU for qemu-devel@nongnu.org; Thu, 11 Jun 2015 07:11:17 -0400 From: Markus Armbruster References: <1434006867-19701-1-git-send-email-eric.auger@linaro.org> Date: Thu, 11 Jun 2015 13:11:14 +0200 In-Reply-To: <1434006867-19701-1-git-send-email-eric.auger@linaro.org> (Eric Auger's message of "Thu, 11 Jun 2015 08:14:27 +0100") Message-ID: <87381ywld9.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] hw/vfio/platform: replace g_malloc0_n by g_malloc0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Auger Cc: peter.maydell@linaro.org, alex.williamson@redhat.com, arei.gonglei@huawei.com, eric.auger@st.com, qemu-devel@nongnu.org Eric Auger writes: > g_malloc0_n() is introduced since glib-2.24 while QEMU currently > requires glib-2.22. This may cause a link error on some distributions. > > Signed-off-by: Eric Auger > --- > hw/vfio/platform.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c > index 35266a8..c0acc8b 100644 > --- a/hw/vfio/platform.c > +++ b/hw/vfio/platform.c > @@ -346,8 +346,7 @@ static int vfio_populate_device(VFIODevice *vbasedev) > return ret; > } > > - vdev->regions = g_malloc0_n(vbasedev->num_regions, > - sizeof(VFIORegion *)); > + vdev->regions = g_malloc0(vbasedev->num_regions * sizeof(VFIORegion *)); > > for (i = 0; i < vbasedev->num_regions; i++) { > struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) }; Please use g_new0(VFIORegion, vbasedev->num_regions) for extra compile-time checking and integer overflow protection. See commits 58889fe net: Use g_new() & friends where that makes obvious sense 3c55fe2 scsi: Use g_new() & friends where that makes obvious sense ab3ad07 x86: Use g_new() & friends where that makes obvious sense 3ba235a block: Use g_new0() for a bit of extra type checking e1cf558 util: Use g_new() & friends where that makes obvious sense 02c4f26 block: Use g_new() & friends to avoid multiplying sizes 5839e53 block: Use g_new() & friends where that makes obvious sense