From patchwork Thu Jun 11 13:07:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 49767 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 818712460E for ; Thu, 11 Jun 2015 13:08:17 +0000 (UTC) Received: by wibut5 with SMTP id ut5sf2747362wib.0 for ; Thu, 11 Jun 2015 06:08:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=SMuUWMlUU/yFS1viUun1M+DQ5lY2x37rwJgISXX2few=; b=bxlVTnvvJaD1iGlipUNvTaU2Whdthiuj1v+wmEAWbAfUlICQC5lVK0ezzusTDIky5x iBTpZC4PunRM0gz2vM1vfM+po9CAgE83cv2ALd0EMn5XX3k7YKcs9ZYRoOJxyNVFiqy+ /j2Vy9XYWq87UQKi2SnWg76Yjh+/gy+YJJSyTC7+0FFFkUfzrCvREsMRKavaaryYTScP PyOOTGHsiWRY6QPSDdcAqU3SvyuXOiQvHqqVxb56BbhP3jwl7nTV2Pb6b9NGSRlZbKbw fTcHrISNwb4AHV5AZBNSQOldr63whakNT2v/iYNhCxeKL/uS5GsRITQq72qAWSfJG+LB zwBA== X-Gm-Message-State: ALoCoQnv/WNsRLFZXuntE/jC+h/MWMALBfeotIiP+qZj5kox3NFLIINRcyp5lkGRiqMVNF7MZwnS X-Received: by 10.112.122.13 with SMTP id lo13mr8303168lbb.5.1434028096711; Thu, 11 Jun 2015 06:08:16 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.10 with SMTP id p10ls408375lag.29.gmail; Thu, 11 Jun 2015 06:08:16 -0700 (PDT) X-Received: by 10.152.121.42 with SMTP id lh10mr10066692lab.0.1434028096473; Thu, 11 Jun 2015 06:08:16 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id eu8si547352lbc.171.2015.06.11.06.08.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jun 2015 06:08:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbbqq2 with SMTP id qq2so3716055lbb.3 for ; Thu, 11 Jun 2015 06:08:16 -0700 (PDT) X-Received: by 10.112.198.74 with SMTP id ja10mr9876780lbc.19.1434028096177; Thu, 11 Jun 2015 06:08:16 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp4032294lbb; Thu, 11 Jun 2015 06:08:15 -0700 (PDT) X-Received: by 10.180.83.6 with SMTP id m6mr29970741wiy.72.1434028095384; Thu, 11 Jun 2015 06:08:15 -0700 (PDT) Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com. [74.125.82.45]) by mx.google.com with ESMTPS id t9si1834118wib.66.2015.06.11.06.08.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jun 2015 06:08:15 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.45 as permitted sender) client-ip=74.125.82.45; Received: by wgme6 with SMTP id e6so4972860wgm.2 for ; Thu, 11 Jun 2015 06:08:15 -0700 (PDT) X-Received: by 10.180.7.169 with SMTP id k9mr19502038wia.84.1434028095098; Thu, 11 Jun 2015 06:08:15 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id di9sm12778034wib.16.2015.06.11.06.08.13 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 11 Jun 2015 06:08:14 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, alex.williamson@redhat.com Cc: patches@linaro.org Subject: [PATCH] hw/vfio: Use g_new0() where that makes obvious sense Date: Thu, 11 Jun 2015 14:07:54 +0100 Message-Id: <1434028074-4472-1-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Replace g_malloc0 occurences by g_new0 where that makes obvious sense. This looks to be the best practice bringing extra compile-time checking and integer overflow protection. Signed-off-by: Eric Auger --- hw/vfio/common.c | 8 ++++---- hw/vfio/pci.c | 24 ++++++++++++------------ hw/vfio/platform.c | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index b1045da..7f09700 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -376,7 +376,7 @@ static void vfio_listener_region_add(MemoryListener *listener, * they must make sure there are no existing mappings or * loop through existing mappings to map them into VFIO. */ - giommu = g_malloc0(sizeof(*giommu)); + giommu = g_new0(VFIOGuestIOMMU, 1); giommu->iommu = section->mr; giommu->container = container; giommu->n.notify = vfio_iommu_map_notify; @@ -614,7 +614,7 @@ static VFIOAddressSpace *vfio_get_address_space(AddressSpace *as) } /* No suitable VFIOAddressSpace, create a new one */ - space = g_malloc0(sizeof(*space)); + space = g_new0(VFIOAddressSpace, 1); space->as = as; QLIST_INIT(&space->containers); @@ -662,7 +662,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as) goto close_fd_exit; } - container = g_malloc0(sizeof(*container)); + container = g_new0(VFIOContainer, 1); container->space = space; container->fd = fd; if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) || @@ -804,7 +804,7 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *as) } } - group = g_malloc0(sizeof(*group)); + group = g_new0(VFIOGroup, 1); snprintf(path, sizeof(path), "/dev/vfio/%d", groupid); group->fd = qemu_open(path, O_RDWR); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index e0e339a..7e2e1ea 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -752,7 +752,7 @@ static void vfio_enable_msix(VFIOPCIDevice *vdev) { vfio_disable_interrupts(vdev); - vdev->msi_vectors = g_malloc0(vdev->msix->entries * sizeof(VFIOMSIVector)); + vdev->msi_vectors = g_new0(VFIOMSIVector, vdev->msix->entries); vdev->interrupt = VFIO_INT_MSIX; @@ -788,7 +788,7 @@ static void vfio_enable_msi(VFIOPCIDevice *vdev) vdev->nr_vectors = msi_nr_vectors_allocated(&vdev->pdev); retry: - vdev->msi_vectors = g_malloc0(vdev->nr_vectors * sizeof(VFIOMSIVector)); + vdev->msi_vectors = g_new0(VFIOMSIVector, vdev->nr_vectors); for (i = 0; i < vdev->nr_vectors; i++) { VFIOMSIVector *vector = &vdev->msi_vectors[i]; @@ -1424,7 +1424,7 @@ static void vfio_vga_probe_ati_3c3_quirk(VFIOPCIDevice *vdev) return; } - quirk = g_malloc0(sizeof(*quirk)); + quirk = g_new0(VFIOQuirk, 1); quirk->vdev = vdev; memory_region_init_io(&quirk->mem, OBJECT(vdev), &vfio_ati_3c3_quirk, quirk, @@ -1458,7 +1458,7 @@ static void vfio_probe_ati_bar4_window_quirk(VFIOPCIDevice *vdev, int nr) return; } - quirk = g_malloc0(sizeof(*quirk)); + quirk = g_new0(VFIOQuirk, 1); quirk->vdev = vdev; quirk->data.address_size = 4; quirk->data.data_offset = 4; @@ -1614,7 +1614,7 @@ static void vfio_probe_rtl8168_bar2_window_quirk(VFIOPCIDevice *vdev, int nr) return; } - quirk = g_malloc0(sizeof(*quirk)); + quirk = g_new0(VFIOQuirk, 1); quirk->vdev = vdev; quirk->data.bar = nr; @@ -1641,7 +1641,7 @@ static void vfio_probe_ati_bar2_4000_quirk(VFIOPCIDevice *vdev, int nr) return; } - quirk = g_malloc0(sizeof(*quirk)); + quirk = g_new0(VFIOQuirk, 1); quirk->vdev = vdev; quirk->data.flags = quirk->data.read_flags = quirk->data.write_flags = 1; quirk->data.address_match = 0x4000; @@ -1772,7 +1772,7 @@ static void vfio_vga_probe_nvidia_3d0_quirk(VFIOPCIDevice *vdev) return; } - quirk = g_malloc0(sizeof(*quirk)); + quirk = g_new0(VFIOQuirk, 1); quirk->vdev = vdev; quirk->data.base_offset = 0x10; quirk->data.address_offset = 4; @@ -1862,7 +1862,7 @@ static void vfio_probe_nvidia_bar5_window_quirk(VFIOPCIDevice *vdev, int nr) return; } - quirk = g_malloc0(sizeof(*quirk)); + quirk = g_new0(VFIOQuirk, 1); quirk->vdev = vdev; quirk->data.read_flags = quirk->data.write_flags = NV_BAR5_VALID; quirk->data.address_offset = 0x8; @@ -1934,7 +1934,7 @@ static void vfio_probe_nvidia_bar0_88000_quirk(VFIOPCIDevice *vdev, int nr) return; } - quirk = g_malloc0(sizeof(*quirk)); + quirk = g_new0(VFIOQuirk, 1); quirk->vdev = vdev; quirk->data.flags = quirk->data.read_flags = quirk->data.write_flags = 1; quirk->data.address_match = 0x88000; @@ -1971,7 +1971,7 @@ static void vfio_probe_nvidia_bar0_1800_quirk(VFIOPCIDevice *vdev, int nr) (unsigned int)(vfio_region_read(&vdev->bars[0].region, 0, 4) >> 20) & 0xff); - quirk = g_malloc0(sizeof(*quirk)); + quirk = g_new0(VFIOQuirk, 1); quirk->vdev = vdev; quirk->data.flags = quirk->data.read_flags = quirk->data.write_flags = 1; quirk->data.address_match = 0x1800; @@ -2245,7 +2245,7 @@ static int vfio_early_setup_msix(VFIOPCIDevice *vdev) table = le32_to_cpu(table); pba = le32_to_cpu(pba); - vdev->msix = g_malloc0(sizeof(*(vdev->msix))); + vdev->msix = g_new0(VFIOMSIXInfo, 1); vdev->msix->table_bar = table & PCI_MSIX_FLAGS_BIRMASK; vdev->msix->table_offset = table & ~PCI_MSIX_FLAGS_BIRMASK; vdev->msix->pba_bar = pba & PCI_MSIX_FLAGS_BIRMASK; @@ -2792,7 +2792,7 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single) vfio_pci_pre_reset(vdev); vdev->vbasedev.needs_reset = false; - info = g_malloc0(sizeof(*info)); + info = g_new0(struct vfio_pci_hot_reset_info, 1); info->argsz = sizeof(*info); ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info); diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 9382bb7..c19a0ee 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -46,7 +46,7 @@ static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev, SysBusDevice *sbdev = SYS_BUS_DEVICE(vdev); VFIOINTp *intp; - intp = g_malloc0(sizeof(*intp)); + intp = g_new0(VFIOINTp, 1); intp->vdev = vdev; intp->pin = info.index; intp->flags = info.flags; @@ -352,7 +352,7 @@ static int vfio_populate_device(VFIODevice *vbasedev) struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) }; VFIORegion *ptr; - vdev->regions[i] = g_malloc0(sizeof(VFIORegion)); + vdev->regions[i] = g_new0(VFIORegion, 1); ptr = vdev->regions[i]; reg_info.index = i; ret = ioctl(vbasedev->fd, VFIO_DEVICE_GET_REGION_INFO, ®_info);