From nobody Tue Feb 10 23:00:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507335901135247.85284441867077; Fri, 6 Oct 2017 17:25:01 -0700 (PDT) Received: from localhost ([::1]:47710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0cvD-0002k9-8S for importer@patchew.org; Fri, 06 Oct 2017 20:24:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0cQ8-00007g-LD for qemu-devel@nongnu.org; Fri, 06 Oct 2017 19:52:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e0cQ7-00065m-Al for qemu-devel@nongnu.org; Fri, 06 Oct 2017 19:52:44 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:49209) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e0cQ7-00065T-5m; Fri, 06 Oct 2017 19:52:43 -0400 Received: by mail-qt0-x242.google.com with SMTP id o3so34347178qte.6; Fri, 06 Oct 2017 16:52:43 -0700 (PDT) Received: from yoga.lan ([181.93.89.178]) by smtp.gmail.com with ESMTPSA id g1sm1705226qta.95.2017.10.06.16.52.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Oct 2017 16:52:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R6xePZMLxKwxCP3mOIf6xlQLtUECVd5CGTbpHDOl3uw=; b=XKKYYne1OZGaYAp6QFkIJfejzMDWPnBWher4jYXGDuUKzmQiyx1knUnwSJjDPxoZhY OhR+/QCGR7zJFrf0pYhBC3kfluMBR1rAtGrV9en25STszj+1D7uNfD3lk4+KTVoaomad 1zUgwF8TDgEU4lUuIPoAjl6nMwFdTV3XFASM7xOdLXXZc582CdQNDgcKOM3KVNYxt/rY AyVZKkO6azmOc+FtgXUEs+KVl9oJqZAOYqYSfxFaB/FjneKC/tpS+JjsGUSSTeVWFEMz vAwvNtiNy2idPHvz9f81PppyHmnL7C0jEQMSDL0VXXSKUutMypJAfrWKPwlK42uq9+H8 mzqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=R6xePZMLxKwxCP3mOIf6xlQLtUECVd5CGTbpHDOl3uw=; b=HkKnHlJrc23MGE6hu71HU1Jzg5NNG+l0NyZvPpI/AG29NlDz4Ca+hLS65sgCSAmaSm djb98Q1VYlAwd1W8Z6XJO3fC4eecWcASGaj7jzysVq3817dPlyBRwTCMw8DAyneojTlb nKbBf466GF6WwcESkwqNWAaOK8TK9a3FiVThI2EkaYxJm9hGWYQPMzr3quPyaM1Ggu+J aDJuSQgMFoucb3FXhNdlR8NMjxz6VJSNxOmh8JGLGqTJlD7IG/LtadDbOJgseVNOd2TI 9B0+sBeUWi73kRkOBSdPxj4Nzl5jReOwVJhUDhhG6LTb3a/67qZK5N/sJZUhoxuDHFEl /EfA== X-Gm-Message-State: AMCzsaVFogQUqZuNviYMxHlyHN4gxFatRAFdLImrS5D7mkfwOghn8Scp YoCewFLriJtZBLEAl6tDu6U= X-Google-Smtp-Source: AOwi7QDfyMxPWMusyiyt1Eyqi3vIwEyHl9cD+VakzCIBbdfmkNzhRsTBz1vn5i48xY/3o5PWuRjuoQ== X-Received: by 10.237.46.98 with SMTP id j89mr5831642qtd.182.1507333962575; Fri, 06 Oct 2017 16:52:42 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Eric Blake , Alex Williamson Date: Fri, 6 Oct 2017 20:49:33 -0300 Message-Id: <20171006235023.11952-39-f4bug@amsat.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171006235023.11952-1-f4bug@amsat.org> References: <20171006235023.11952-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::242 Subject: [Qemu-devel] [PATCH 38/88] VFIO: use g_new() family of functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu trival , qemu-devel@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Philippe Mathieu-Daud=C3=A9 [PMD: more changes in each file, added pci-quirks.c] --- hw/vfio/common.c | 12 ++++++------ hw/vfio/pci-quirks.c | 18 +++++++++--------- hw/vfio/pci.c | 7 +++---- hw/vfio/platform.c | 6 +++--- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 7b2924c0ef..bde4fdba66 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -272,7 +272,7 @@ static void vfio_host_win_add(VFIOContainer *container, } } =20 - hostwin =3D g_malloc0(sizeof(*hostwin)); + hostwin =3D g_new0(VFIOHostDMAWindow, 1); =20 hostwin->min_iova =3D min_iova; hostwin->max_iova =3D max_iova; @@ -488,7 +488,7 @@ static void vfio_listener_region_add(MemoryListener *li= stener, * would be the right place to wire that up (tell the KVM * device emulation the VFIO iommu handles to use). */ - giommu =3D g_malloc0(sizeof(*giommu)); + giommu =3D g_new0(VFIOGuestIOMMU, 1); giommu->iommu =3D iommu_mr; giommu->iommu_offset =3D section->offset_within_address_space - section->offset_within_region; @@ -688,7 +688,7 @@ static int vfio_setup_region_sparse_mmaps(VFIORegion *r= egion, } =20 region->nr_mmaps =3D j; - region->mmaps =3D g_realloc(region->mmaps, j * sizeof(VFIOMmap)); + region->mmaps =3D g_renew(VFIOMmap, region->mmaps, j); =20 return 0; } @@ -938,7 +938,7 @@ static VFIOAddressSpace *vfio_get_address_space(Address= Space *as) } =20 /* No suitable VFIOAddressSpace, create a new one */ - space =3D g_malloc0(sizeof(*space)); + space =3D g_new0(VFIOAddressSpace, 1); space->as =3D as; QLIST_INIT(&space->containers); =20 @@ -987,7 +987,7 @@ static int vfio_connect_container(VFIOGroup *group, Add= ressSpace *as, goto close_fd_exit; } =20 - container =3D g_malloc0(sizeof(*container)); + container =3D g_new0(VFIOContainer, 1); container->space =3D space; container->fd =3D fd; if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) || @@ -1202,7 +1202,7 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace *= as, Error **errp) } } =20 - group =3D g_malloc0(sizeof(*group)); + group =3D g_new0(VFIOGroup, 1); =20 snprintf(path, sizeof(path), "/dev/vfio/%d", groupid); group->fd =3D qemu_open(path, O_RDWR); diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index 14291c2a16..b51ee60368 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -288,7 +288,7 @@ static void vfio_vga_probe_ati_3c3_quirk(VFIOPCIDevice = *vdev) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); + quirk =3D g_new0(VFIOQuirk, 1); quirk->mem =3D g_new0(MemoryRegion, 1); quirk->nr_mem =3D 1; =20 @@ -323,7 +323,7 @@ static void vfio_probe_ati_bar4_quirk(VFIOPCIDevice *vd= ev, int nr) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); + quirk =3D g_new0(VFIOQuirk, 1); quirk->mem =3D g_new0(MemoryRegion, 2); quirk->nr_mem =3D 2; window =3D quirk->data =3D g_malloc0(sizeof(*window) + @@ -371,7 +371,7 @@ static void vfio_probe_ati_bar2_quirk(VFIOPCIDevice *vd= ev, int nr) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); + quirk =3D g_new0(VFIOQuirk, 1); mirror =3D quirk->data =3D g_malloc0(sizeof(*mirror)); mirror->mem =3D quirk->mem =3D g_new0(MemoryRegion, 1); quirk->nr_mem =3D 1; @@ -547,7 +547,7 @@ static void vfio_vga_probe_nvidia_3d0_quirk(VFIOPCIDevi= ce *vdev) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); + quirk =3D g_new0(VFIOQuirk, 1); quirk->data =3D data =3D g_malloc0(sizeof(*data)); quirk->mem =3D g_new0(MemoryRegion, 2); quirk->nr_mem =3D 2; @@ -665,7 +665,7 @@ static void vfio_probe_nvidia_bar5_quirk(VFIOPCIDevice = *vdev, int nr) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); + quirk =3D g_new0(VFIOQuirk, 1); quirk->mem =3D g_new0(MemoryRegion, 4); quirk->nr_mem =3D 4; bar5 =3D quirk->data =3D g_malloc0(sizeof(*bar5) + @@ -759,7 +759,7 @@ static void vfio_probe_nvidia_bar0_quirk(VFIOPCIDevice = *vdev, int nr) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); + quirk =3D g_new0(VFIOQuirk, 1); mirror =3D quirk->data =3D g_malloc0(sizeof(*mirror)); mirror->mem =3D quirk->mem =3D g_new0(MemoryRegion, 1); quirk->nr_mem =3D 1; @@ -942,7 +942,7 @@ static void vfio_probe_rtl8168_bar2_quirk(VFIOPCIDevice= *vdev, int nr) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); + quirk =3D g_new0(VFIOQuirk, 1); quirk->mem =3D g_new0(MemoryRegion, 2); quirk->nr_mem =3D 2; quirk->data =3D rtl =3D g_malloc0(sizeof(*rtl)); @@ -1500,7 +1500,7 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *= vdev, int nr) } =20 /* Setup our quirk to munge GTT addresses to the VM allocated buffer */ - quirk =3D g_malloc0(sizeof(*quirk)); + quirk =3D g_new0(VFIOQuirk, 1); quirk->mem =3D g_new0(MemoryRegion, 2); quirk->nr_mem =3D 2; igd =3D quirk->data =3D g_malloc0(sizeof(*igd)); @@ -1553,7 +1553,7 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *= vdev, int nr) * memory region must be written to the device BDSM regsiter at PCI * config offset 0x5C. */ - bdsm_size =3D g_malloc(sizeof(*bdsm_size)); + bdsm_size =3D g_new(uint64_t, 1); *bdsm_size =3D cpu_to_le64((ggms_mb + gms_mb) * 1024 * 1024); fw_cfg_add_file(fw_cfg_find(), "etc/igd-bdsm-size", bdsm_size, sizeof(*bdsm_size)); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 9e86db7c3b..15b82b2942 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -1395,7 +1395,7 @@ static void vfio_msix_early_setup(VFIOPCIDevice *vdev= , Error **errp) table =3D le32_to_cpu(table); pba =3D le32_to_cpu(pba); =20 - msix =3D g_malloc0(sizeof(*msix)); + msix =3D g_new0(VFIOMSIXInfo, 1); msix->table_bar =3D table & PCI_MSIX_FLAGS_BIRMASK; msix->table_offset =3D table & ~PCI_MSIX_FLAGS_BIRMASK; msix->pba_bar =3D pba & PCI_MSIX_FLAGS_BIRMASK; @@ -1437,8 +1437,7 @@ static int vfio_msix_setup(VFIOPCIDevice *vdev, int p= os, Error **errp) int ret; Error *err =3D NULL; =20 - vdev->msix->pending =3D g_malloc0(BITS_TO_LONGS(vdev->msix->entries) * - sizeof(unsigned long)); + vdev->msix->pending =3D g_new0(unsigned long, BITS_TO_LONGS(vdev->msix= ->entries)); ret =3D msix_init(&vdev->pdev, vdev->msix->entries, vdev->bars[vdev->msix->table_bar].region.mem, vdev->msix->table_bar, vdev->msix->table_offset, @@ -2076,7 +2075,7 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bo= ol single) } vdev->vbasedev.needs_reset =3D false; =20 - info =3D g_malloc0(sizeof(*info)); + info =3D g_new0(struct vfio_pci_hot_reset_info, 1); info->argsz =3D sizeof(*info); =20 ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, i= nfo); diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index da84abf4fc..547225037f 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -55,7 +55,7 @@ static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev, SysBusDevice *sbdev =3D SYS_BUS_DEVICE(vdev); VFIOINTp *intp; =20 - intp =3D g_malloc0(sizeof(*intp)); + intp =3D g_new0(VFIOINTp, 1); intp->vdev =3D vdev; intp->pin =3D info.index; intp->flags =3D info.flags; @@ -65,7 +65,7 @@ static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev, sysbus_init_irq(sbdev, &intp->qemuirq); =20 /* Get an eventfd for trigger */ - intp->interrupt =3D g_malloc0(sizeof(EventNotifier)); + intp->interrupt =3D g_new0(EventNotifier, 1); ret =3D event_notifier_init(intp->interrupt, 0); if (ret) { g_free(intp->interrupt); @@ -76,7 +76,7 @@ static VFIOINTp *vfio_init_intp(VFIODevice *vbasedev, } if (vfio_irq_is_automasked(intp)) { /* Get an eventfd for resample/unmask */ - intp->unmask =3D g_malloc0(sizeof(EventNotifier)); + intp->unmask =3D g_new0(EventNotifier, 1); ret =3D event_notifier_init(intp->unmask, 0); if (ret) { g_free(intp->interrupt); --=20 2.14.2