From nobody Mon Apr 29 04:51:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601402592; cv=none; d=zohomail.com; s=zohoarc; b=Yu43H5jDf8wOxSf+YJQuBajVPVpKtzhCgI5qdSatKOcx0tx1FtjhTcLEV6PfTmHOuvVRmxyvb9D3UUYJV51KyJ0oF7+snnrfRG22U2l6hWcYe4Od4wO36whtO5LaB1RqZcC67UJdWG7W+zRc4BOqhV9ePuA07ZmC8P3koRMRnrs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601402592; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zUAdFq9G53o2rrSHA9ylR/b4WHnCQ9Dfhv7z0eoarPo=; b=XmxKdc1bAsVcYZhPSp1xMyCQJ/pNXr2L8eYH2X8DHthVvKzI4N6q0H+8iCvLOapdRviOm3rykAV2SrkwnZHXt5jrl1wOrxegQpfhJXAsTuMV1e5/goZvZpep34gXV5i60Bkv/R/ZFHI0b4KuR6WwdbW+9tM1nrfu7fVB4J6K744= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1601402592732473.3454404383634; Tue, 29 Sep 2020 11:03:12 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-399-e3PhTzEANgCudveQuEHqBg-1; Tue, 29 Sep 2020 14:01:44 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B123881C464; Tue, 29 Sep 2020 18:01:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC41A78822; Tue, 29 Sep 2020 18:01:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6A72744A45; Tue, 29 Sep 2020 18:01:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08TI1WOG017069 for ; Tue, 29 Sep 2020 14:01:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 410691002C07; Tue, 29 Sep 2020 18:01:32 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 475F81002C04 for ; Tue, 29 Sep 2020 18:01:31 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601402591; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=zUAdFq9G53o2rrSHA9ylR/b4WHnCQ9Dfhv7z0eoarPo=; b=cSoVNXdzk84tbpU9VXbhwkkhRE0KnhV/fxDEOpqUb07Q7HLTdL58wOI/HDBgzHpmQxvFr6 1+rBxIYDTp6K2JGfmZ1cTejYoSFos9iWeqMRFfdKP1muOKuzxXDU4TOElSR80IdEPRampF ET+4BRjvF251ADO7keXSHXUC39Exi6Q= X-MC-Unique: e3PhTzEANgCudveQuEHqBg-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/2] libxl: prefer g_new0 to VIR_ALLOC Date: Tue, 29 Sep 2020 20:01:25 +0200 Message-Id: <0da2e5e143e9f71c81e0485abd6f010977b66279.1601402455.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- src/libxl/libxl_capabilities.c | 13 ++-- src/libxl/libxl_conf.c | 48 ++++--------- src/libxl/libxl_domain.c | 19 ++--- src/libxl/libxl_driver.c | 20 +++--- src/libxl/libxl_migration.c | 21 ++---- src/libxl/xen_common.c | 122 +++++++++------------------------ src/libxl/xen_xl.c | 85 +++++++---------------- src/libxl/xen_xm.c | 9 +-- 8 files changed, 104 insertions(+), 233 deletions(-) diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index e5b144ea1d..e3472acb4b 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -269,11 +269,9 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCapsPtr caps) } } =20 - if (VIR_ALLOC_N(cpus, nr_nodes) < 0) - goto cleanup; + cpus =3D g_new0(virCapsHostNUMACellCPUPtr, nr_nodes); =20 - if (VIR_ALLOC_N(nr_cpus_node, nr_nodes) < 0) - goto cleanup; + nr_cpus_node =3D g_new0(int, nr_nodes); =20 /* For each node, prepare a list of CPUs belonging to that node */ for (i =3D 0; i < nr_cpus; i++) { @@ -285,7 +283,7 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCapsPtr caps) nr_cpus_node[node]++; =20 if (nr_cpus_node[node] =3D=3D 1) { - if (VIR_ALLOC(cpus[node]) < 0) + cpus[node] =3D g_new0(virCapsHostNUMACellCPU, 1); goto cleanup; } else { if (VIR_REALLOC_N(cpus[node], nr_cpus_node[node]) < 0) @@ -328,7 +326,7 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCapsPtr caps) if (nr_siblings) { size_t j; =20 - if (VIR_ALLOC_N(siblings, nr_siblings) < 0) + siblings =3D g_new0(virCapsHostNUMACellSiblingInfo, nr_sibling= s); goto cleanup; =20 for (j =3D 0; j < nr_siblings; j++) { @@ -590,8 +588,7 @@ libxlMakeDomainOSCaps(const char *machine, return 0; =20 capsLoader->supported =3D VIR_TRISTATE_BOOL_YES; - if (VIR_ALLOC_N(capsLoader->values.values, nfirmwares) < 0) - return -1; + capsLoader->values.values =3D g_new0(char *, nfirmwares); =20 for (i =3D 0; i < nfirmwares; i++) { capsLoader->values.values[capsLoader->values.nvalues] =3D g_strdup= (firmwares[i]->name); diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 5b729a019a..03ec37d6c5 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -613,9 +613,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, return -1; } else { #ifdef LIBXL_HAVE_BUILDINFO_SERIAL_LIST - if (VIR_ALLOC_N(b_info->u.hvm.serial_list, def->nserials += 1) < - 0) - return -1; + b_info->u.hvm.serial_list =3D *g_new0(libxl_string_list, d= ef->nserials + 1); for (i =3D 0; i < def->nserials; i++) { if (libxlMakeChrdevStr(def->serials[i], &b_info->u.hvm.serial_list[i]) = < 0) @@ -826,8 +824,7 @@ libxlMakeVnumaList(virDomainDefPtr def, /* * allocate the vnuma_nodes for assignment under b_info. */ - if (VIR_ALLOC_N(vnuma_nodes, num_vnuma) < 0) - return -1; + vnuma_nodes =3D g_new0(libxl_vnode_info, num_vnuma); =20 /* * parse the vnuma vnodes data. @@ -870,8 +867,7 @@ libxlMakeVnumaList(virDomainDefPtr def, libxl_bitmap_dispose(&vcpu_bitmap); =20 /* vdistances */ - if (VIR_ALLOC_N(p->distances, num_vnuma) < 0) - goto cleanup; + p->distances =3D g_new0(uint32_t, num_vnuma); p->num_distances =3D num_vnuma; =20 for (j =3D 0; j < num_vnuma; j++) @@ -1193,8 +1189,7 @@ libxlMakeDiskList(virDomainDefPtr def, libxl_domain_c= onfig *d_config) libxl_device_disk *x_disks; size_t i; =20 - if (VIR_ALLOC_N(x_disks, ndisks) < 0) - return -1; + x_disks =3D g_new0(libxl_device_disk, ndisks); =20 for (i =3D 0; i < ndisks; i++) { if (libxlMakeDisk(l_disks[i], &x_disks[i]) < 0) @@ -1464,8 +1459,7 @@ libxlMakeNicList(virDomainDefPtr def, libxl_domain_c= onfig *d_config) libxl_device_nic *x_nics; size_t i, nvnics =3D 0; =20 - if (VIR_ALLOC_N(x_nics, nnics) < 0) - return -1; + x_nics =3D g_new0(libxl_device_nic, nnics); =20 for (i =3D 0; i < nnics; i++) { if (virDomainNetGetActualType(l_nics[i]) =3D=3D VIR_DOMAIN_NET_TYP= E_HOSTDEV) @@ -1567,12 +1561,8 @@ libxlMakeVfbList(virPortAllocatorRangePtr graphicspo= rts, if (nvfbs =3D=3D 0) return 0; =20 - if (VIR_ALLOC_N(x_vfbs, nvfbs) < 0) - return -1; - if (VIR_ALLOC_N(x_vkbs, nvfbs) < 0) { - VIR_FREE(x_vfbs); - return -1; - } + x_vfbs =3D g_new0(libxl_device_vfb, nvfbs); + x_vkbs =3D g_new0(libxl_device_vkb, nvfbs); =20 for (i =3D 0; i < nvfbs; i++) { libxl_device_vkb_init(&x_vkbs[i]); @@ -1764,11 +1754,9 @@ libxlDriverConfigNew(void) goto error; =20 #else - if (VIR_ALLOC_N(cfg->firmwares, 1) < 0) - goto error; + cfg->firmwares =3D g_new0(virFirmwarePtr, 1); cfg->nfirmwares =3D 1; - if (VIR_ALLOC(cfg->firmwares[0]) < 0) - goto error; + cfg->firmwares[0] =3D g_new0(virFirmware, 1); cfg->firmwares[0]->name =3D g_strdup(LIBXL_FIRMWARE_DIR "/ovmf.bin"); #endif =20 @@ -1776,8 +1764,7 @@ libxlDriverConfigNew(void) if (VIR_REALLOC_N(cfg->firmwares, cfg->nfirmwares + 1) < 0) goto error; cfg->nfirmwares++; - if (VIR_ALLOC(cfg->firmwares[cfg->nfirmwares - 1]) < 0) - goto error; + cfg->firmwares[cfg->nfirmwares - 1] =3D g_new0(virFirmware, 1); cfg->firmwares[cfg->nfirmwares - 1]->name =3D g_strdup(LIBXL_FIRMWARE_= DIR "/hvmloader"); =20 /* defaults for keepalive messages */ @@ -2033,8 +2020,7 @@ libxlMakeChannelList(const char *channelDir, libxl_device_channel *x_channels; size_t i, nvchannels =3D 0; =20 - if (VIR_ALLOC_N(x_channels, nchannels) < 0) - return -1; + x_channels =3D g_new0(libxl_device_channel, nchannels); =20 for (i =3D 0; i < nchannels; i++) { if (l_channels[i]->deviceType !=3D VIR_DOMAIN_CHR_DEVICE_TYPE_CHAN= NEL) @@ -2125,8 +2111,7 @@ libxlMakeDefaultUSBControllers(virDomainDefPtr def, =20 /* Create USB controllers with 8 ports */ ncontrollers =3D VIR_DIV_UP(nusbdevs, 8); - if (VIR_ALLOC_N(x_controllers, ncontrollers) < 0) - return -1; + x_controllers =3D g_new0(libxl_device_usbctrl, ncontrollers); =20 for (i =3D 0; i < ncontrollers; i++) { if (!(l_controller =3D virDomainControllerDefNew(VIR_DOMAIN_CONTRO= LLER_TYPE_USB))) @@ -2176,8 +2161,7 @@ libxlMakeUSBControllerList(virDomainDefPtr def, libxl= _domain_config *d_config) if (nusbctrls =3D=3D 0) return libxlMakeDefaultUSBControllers(def, d_config); =20 - if (VIR_ALLOC_N(x_usbctrls, nusbctrls) < 0) - return -1; + x_usbctrls =3D g_new0(libxl_device_usbctrl, nusbctrls); =20 for (i =3D 0, j =3D 0; i < ncontrollers && j < nusbctrls; i++) { if (l_controllers[i]->type !=3D VIR_DOMAIN_CONTROLLER_TYPE_USB) @@ -2253,8 +2237,7 @@ libxlMakeUSBList(virDomainDefPtr def, libxl_domain_co= nfig *d_config) if (nhostdevs =3D=3D 0) return 0; =20 - if (VIR_ALLOC_N(x_usbdevs, nhostdevs) < 0) - return -1; + x_usbdevs =3D g_new0(libxl_device_usbdev, nhostdevs); =20 for (i =3D 0, j =3D 0; i < nhostdevs; i++) { if (l_hostdevs[i]->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) @@ -2316,8 +2299,7 @@ libxlMakePCIList(virDomainDefPtr def, libxl_domain_co= nfig *d_config) if (nhostdevs =3D=3D 0) return 0; =20 - if (VIR_ALLOC_N(x_pcidevs, nhostdevs) < 0) - return -1; + x_pcidevs =3D g_new0(libxl_device_pci, nhostdevs); =20 for (i =3D 0, j =3D 0; i < nhostdevs; i++) { if (l_hostdevs[i]->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index de2059fa24..a3f362a0c8 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -72,8 +72,7 @@ libxlDomainObjInitJob(libxlDomainObjPrivatePtr priv) if (virCondInit(&priv->job.cond) < 0) return -1; =20 - if (VIR_ALLOC(priv->job.current) < 0) - return -1; + priv->job.current =3D g_new0(virDomainJobInfo, 1); =20 return 0; } @@ -402,11 +401,7 @@ libxlDomainDefPostParse(virDomainDefPtr def, chrdef->target.port =3D 0; chrdef->targetType =3D VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN; =20 - if (VIR_ALLOC_N(def->consoles, 1) < 0) { - virDomainChrDefFree(chrdef); - return -1; - } - + def->consoles =3D g_new0(virDomainChrDefPtr, 1); def->nconsoles =3D 1; def->consoles[0] =3D chrdef; } @@ -429,8 +424,8 @@ libxlDomainDefPostParse(virDomainDefPtr def, /* add implicit balloon device */ if (def->memballoon =3D=3D NULL) { virDomainMemballoonDefPtr memballoon; - if (VIR_ALLOC(memballoon) < 0) - return -1; + memballoon =3D g_new0(virDomainMemballoonDef, + 1); =20 memballoon->model =3D VIR_DOMAIN_MEMBALLOON_MODEL_XEN; def->memballoon =3D memballoon; @@ -695,8 +690,7 @@ libxlDomainEventHandler(void *data, VIR_LIBXL_EVENT_CON= ST libxl_event *event) * Start a thread to handle shutdown. We don't want to be tying up * libxl's event machinery by doing a potentially lengthy shutdown. */ - if (VIR_ALLOC(shutdown_info) < 0) - goto error; + shutdown_info =3D g_new0(struct libxlShutdownThreadInfo, 1); =20 shutdown_info->driver =3D driver; shutdown_info->event =3D (libxl_event *)event; @@ -785,8 +779,7 @@ libxlDomainSaveImageOpen(libxlDriverPrivatePtr driver, goto error; } =20 - if (VIR_ALLOC_N(xml, hdr.xmlLen) < 0) - goto error; + xml =3D g_new0(char, hdr.xmlLen); =20 if (saferead(fd, xml, hdr.xmlLen) !=3D hdr.xmlLen) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to read X= ML")); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 571b70f982..eece0f8118 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -159,8 +159,7 @@ libxlFDRegisterEventHook(void *priv, int vir_events =3D VIR_EVENT_HANDLE_ERROR; libxlOSEventHookInfoPtr info; =20 - if (VIR_ALLOC(info) < 0) - return -1; + info =3D g_new0(libxlOSEventHookInfo, 1); =20 info->ctx =3D priv; info->xl_priv =3D xl_priv; @@ -239,8 +238,7 @@ libxlTimeoutRegisterEventHook(void *priv, gint64 res_ms; int timeout; =20 - if (VIR_ALLOC(info) < 0) - return -1; + info =3D g_new0(libxlOSEventHookInfo, 1); =20 info->ctx =3D priv; info->xl_priv =3D xl_priv; @@ -671,8 +669,7 @@ libxlStateInitialize(bool privileged, if (!libxlDriverShouldLoad(privileged)) return VIR_DRV_STATE_INIT_SKIPPED; =20 - if (VIR_ALLOC(libxl_driver) < 0) - return VIR_DRV_STATE_INIT_ERROR; + libxl_driver =3D g_new0(libxlDriverPrivate, 1); =20 libxl_driver->lockFD =3D -1; if (virMutexInit(&libxl_driver->lock) < 0) { @@ -2316,8 +2313,7 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned i= nt nvcpus, goto endjob; =20 maplen =3D VIR_CPU_MAPLEN(nvcpus); - if (VIR_ALLOC_N(bitmask, maplen) < 0) - goto endjob; + bitmask =3D g_new0(uint8_t, maplen); =20 for (i =3D 0; i < nvcpus; ++i) { pos =3D i / 8; @@ -2766,7 +2762,7 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, con= st char * nativeFormat, goto cleanup; } =20 - if (VIR_ALLOC_N(ret, len) < 0) + ret =3D g_new0(char, len); goto cleanup; =20 if (virConfWriteMem(ret, &len, conf) < 0) { @@ -6373,15 +6369,15 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm, goto error; =20 if (n_leases) { - ifaces_ret =3D g_renew(typeof(*ifaces_ret), ifaces_ret, ifaces= _count + 1); - ifaces_ret[ifaces_count] =3D g_new0(typeof(**ifaces_ret), 1); + ifaces_ret =3D g_renew(virDomainInterfacePtr, ifaces_ret, ifac= es_count + 1); + ifaces_ret[ifaces_count] =3D g_new0(virDomainInterface, 1); iface =3D ifaces_ret[ifaces_count]; ifaces_count++; =20 /* Assuming each lease corresponds to a separate IP */ iface->naddrs =3D n_leases; =20 - iface->addrs =3D g_new0(typeof(*iface->addrs), iface->naddrs); + iface->addrs =3D g_new0(virDomainIPAddress, iface->naddrs); iface->name =3D g_strdup(vm->def->nets[i]->ifname); iface->hwaddr =3D g_strdup(macaddr); } diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index 87cd5337ba..6dc6812ee7 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -92,8 +92,7 @@ libxlMigrationCookieNew(virDomainObjPtr dom) { libxlMigrationCookiePtr mig =3D NULL; =20 - if (VIR_ALLOC(mig) < 0) - goto error; + mig =3D g_new0(libxlMigrationCookie, 1); =20 mig->name =3D g_strdup(dom->def->name); =20 @@ -160,8 +159,7 @@ libxlMigrationEatCookie(const char *cookiein, * specify a stream version. */ if (!cookiein || !cookieinlen) { - if (VIR_ALLOC(mig) < 0) - return -1; + mig =3D g_new0(libxlMigrationCookie, 1); =20 mig->xenMigStreamVer =3D 1; *migout =3D mig; @@ -176,8 +174,7 @@ libxlMigrationEatCookie(const char *cookiein, =20 VIR_DEBUG("cookielen=3D%d cookie=3D'%s'", cookieinlen, NULLSTR(cookiei= n)); =20 - if (VIR_ALLOC(mig) < 0) - return -1; + mig =3D g_new0(libxlMigrationCookie, 1); =20 if (!(doc =3D virXMLParseStringCtxt(cookiein, _("(libxl_migration_cookie)"), @@ -313,8 +310,7 @@ libxlMigrateDstReceive(virNetSocketPtr sock, */ args->recvfd =3D recvfd; VIR_FREE(priv->migrationDstReceiveThr); - if (VIR_ALLOC(priv->migrationDstReceiveThr) < 0) - goto fail; + priv->migrationDstReceiveThr =3D g_new0(virThread, 1); =20 name =3D g_strdup_printf("mig-%s", args->vm->def->name); if (virThreadCreateFull(priv->migrationDstReceiveThr, true, @@ -614,8 +610,7 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr dco= nn, mig =3D NULL; =20 VIR_FREE(priv->migrationDstReceiveThr); - if (VIR_ALLOC(priv->migrationDstReceiveThr) < 0) - goto error; + priv->migrationDstReceiveThr =3D g_new0(virThread, 1); name =3D g_strdup_printf("mig-%s", args->vm->def->name); if (virThreadCreateFull(priv->migrationDstReceiveThr, true, libxlDoMigrateDstReceive, @@ -849,8 +844,7 @@ static void libxlTunnel3MigrationSrcFunc(void *arg) struct pollfd fds[1]; int timeout =3D -1; =20 - if (VIR_ALLOC_N(buffer, TUNNEL_SEND_BUF_SIZE) < 0) - return; + buffer =3D g_new0(char, TUNNEL_SEND_BUF_SIZE); =20 fds[0].fd =3D data->srcFD; for (;;) { @@ -920,8 +914,7 @@ libxlMigrationSrcStartTunnel(libxlDriverPrivatePtr driv= er, int ret =3D -1; g_autofree char *name =3D NULL; =20 - if (VIR_ALLOC(tc) < 0) - goto out; + tc =3D g_new0(struct libxlTunnelControl, 1); *tnl =3D tc; =20 tc->dataFD[0] =3D -1; diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 56702a2a76..7b6a7b6e9f 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -253,8 +253,7 @@ xenConfigSetInt(virConfPtr conf, const char *setting, l= ong long l) l, setting); return -1; } - if (VIR_ALLOC(value) < 0) - return -1; + value =3D g_new0(virConfValue, 1); =20 value->type =3D VIR_CONF_LLONG; value->next =3D NULL; @@ -269,8 +268,7 @@ xenConfigSetString(virConfPtr conf, const char *setting= , const char *str) { virConfValuePtr value =3D NULL; =20 - if (VIR_ALLOC(value) < 0) - return -1; + value =3D g_new0(virConfValue, 1); =20 value->type =3D VIR_CONF_STRING; value->next =3D NULL; @@ -554,10 +552,10 @@ xenParseHypervisorFeatures(virConfPtr conf, virDomain= DefPtr def) return -1; =20 if (strval) { - if (VIR_EXPAND_N(def->clock.timers, def->clock.ntimers, 1) < 0 || - VIR_ALLOC(timer) < 0) + if (VIR_EXPAND_N(def->clock.timers, def->clock.ntimers, 1) < 0) return -1; =20 + timer =3D g_new0(virDomainTimerDef, 1); timer->name =3D VIR_DOMAIN_TIMER_NAME_TSC; timer->present =3D 1; timer->tickpolicy =3D -1; @@ -627,10 +625,10 @@ xenParseHypervisorFeatures(virConfPtr conf, virDomain= DefPtr def) return -1; =20 if (val !=3D -1) { - if (VIR_EXPAND_N(def->clock.timers, def->clock.ntimers, 1) < 0= || - VIR_ALLOC(timer) < 0) + if (VIR_EXPAND_N(def->clock.timers, def->clock.ntimers, 1) < 0) return -1; =20 + timer =3D g_new0(virDomainTimerDef, 1); timer->name =3D VIR_DOMAIN_TIMER_NAME_HPET; timer->present =3D val; timer->tickpolicy =3D -1; @@ -666,8 +664,7 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) if (xenConfigGetBool(conf, "vnc", &val, 0) < 0) goto cleanup; if (val) { - if (VIR_ALLOC(graphics) < 0) - goto cleanup; + graphics =3D g_new0(virDomainGraphicsDef, 1); graphics->type =3D VIR_DOMAIN_GRAPHICS_TYPE_VNC; if (xenConfigGetBool(conf, "vncunused", &val, 1) < 0) goto cleanup; @@ -689,8 +686,7 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) goto cleanup; if (xenConfigCopyStringOpt(conf, "keymap", &graphics->data.vnc= .keymap) < 0) goto cleanup; - if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto cleanup; + def->graphics =3D g_new0(virDomainGraphicsDefPtr, 1); def->graphics[0] =3D graphics; def->ngraphics =3D 1; graphics =3D NULL; @@ -698,15 +694,13 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) if (xenConfigGetBool(conf, "sdl", &val, 0) < 0) goto cleanup; if (val) { - if (VIR_ALLOC(graphics) < 0) - goto cleanup; + graphics =3D g_new0(virDomainGraphicsDef, 1); graphics->type =3D VIR_DOMAIN_GRAPHICS_TYPE_SDL; if (xenConfigCopyStringOpt(conf, "display", &graphics->dat= a.sdl.display) < 0) goto cleanup; if (xenConfigCopyStringOpt(conf, "xauthority", &graphics->= data.sdl.xauth) < 0) goto cleanup; - if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto cleanup; + def->graphics =3D g_new0(virDomainGraphicsDefPtr, 1); def->graphics[0] =3D graphics; def->ngraphics =3D 1; graphics =3D NULL; @@ -729,8 +723,7 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) goto cleanup; } =20 - if (VIR_ALLOC(graphics) < 0) - goto cleanup; + graphics =3D g_new0(virDomainGraphicsDef, 1); if (strstr(key, "type=3Dsdl")) graphics->type =3D VIR_DOMAIN_GRAPHICS_TYPE_SDL; else @@ -785,8 +778,7 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) goto cleanup; VIR_FREE(listenAddr); } - if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto cleanup; + def->graphics =3D g_new0(virDomainGraphicsDefPtr, 1); def->graphics[0] =3D graphics; def->ngraphics =3D 1; graphics =3D NULL; @@ -962,8 +954,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, c= onst char *nativeFormat) !(chr =3D xenParseSxprChar(parallel, NULL))) goto cleanup; if (chr) { - if (VIR_ALLOC_N(def->parallels, 1) < 0) - goto cleanup; + def->parallels =3D g_new0(virDomainChrDefPtr, 1); =20 chr->deviceType =3D VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; chr->target.port =3D 0; @@ -1010,8 +1001,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def,= const char *nativeFormat) !(chr =3D xenParseSxprChar(serial, NULL))) goto cleanup; if (chr) { - if (VIR_ALLOC_N(def->serials, 1) < 0) - goto cleanup; + def->serials =3D g_new0(virDomainChrDefPtr, 1); chr->deviceType =3D VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->target.port =3D 0; def->serials[0] =3D chr; @@ -1019,8 +1009,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def,= const char *nativeFormat) } } } else { - if (VIR_ALLOC_N(def->consoles, 1) < 0) - goto cleanup; + def->consoles =3D g_new0(virDomainChrDefPtr, 1); def->nconsoles =3D 1; if (!(def->consoles[0] =3D xenParseSxprChar("pty", NULL))) goto cleanup; @@ -1051,15 +1040,11 @@ xenParseVifBridge(virDomainNetDefPtr net, char *bri= dge) if (virStrToLong_ui(vlanstr, NULL, 10, &tag) < 0) return -1; =20 - if (VIR_ALLOC_N(net->vlan.tag, 1) < 0) - return -1; - + net->vlan.tag =3D g_new0(unsigned int, 1); net->vlan.tag[0] =3D tag; net->vlan.nTags =3D 1; =20 - if (VIR_ALLOC(net->virtPortProfile) < 0) - return -1; - + net->virtPortProfile =3D g_new0(virNetDevVPortProfile, 1); net->virtPortProfile->virtPortType =3D VIR_NETDEV_VPORT_PROFILE_OP= ENVSWITCH; return 0; } else if ((vlanstr =3D strchr(bridge, ':'))) { @@ -1076,10 +1061,7 @@ xenParseVifBridge(virDomainNetDefPtr net, char *brid= ge) for (i =3D 1; vlanstr_list[i]; i++) nvlans++; =20 - if (VIR_ALLOC_N(net->vlan.tag, nvlans) < 0) { - g_strfreev(vlanstr_list); - return -1; - } + net->vlan.tag =3D g_new0(unsigned int, nvlans); =20 for (i =3D 1; i <=3D nvlans; i++) { if (virStrToLong_ui(vlanstr_list[i], NULL, 10, &tag) < 0) { @@ -1092,9 +1074,7 @@ xenParseVifBridge(virDomainNetDefPtr net, char *bridg= e) net->vlan.trunk =3D true; g_strfreev(vlanstr_list); =20 - if (VIR_ALLOC(net->virtPortProfile) < 0) - return -1; - + net->virtPortProfile =3D g_new0(virNetDevVPortProfile, 1); net->virtPortProfile->virtPortType =3D VIR_NETDEV_VPORT_PROFILE_OP= ENVSWITCH; return 0; } else { @@ -1314,14 +1294,8 @@ xenParseVif(char *entry, const char *vif_typename) if (xenParseSxprVifRate(rate, &kbytes_per_sec) < 0) goto cleanup; =20 - if (VIR_ALLOC(bandwidth) < 0) - goto cleanup; - - if (VIR_ALLOC(bandwidth->out) < 0) { - VIR_FREE(bandwidth); - goto cleanup; - } - + bandwidth =3D g_new0(virNetDevBandwidth, 1); + bandwidth->out =3D g_new0(virNetDevBandwidthRate, 1); bandwidth->out->average =3D kbytes_per_sec; net->bandwidth =3D bandwidth; } @@ -1393,15 +1367,11 @@ xenParseSxprSound(virDomainDefPtr def, * Hence use of MODEL_ES1370 + 1, instead of MODEL_LAST */ =20 - if (VIR_ALLOC_N(def->sounds, - VIR_DOMAIN_SOUND_MODEL_ES1370 + 1) < 0) - return -1; - + def->sounds =3D g_new0(virDomainSoundDefPtr, + VIR_DOMAIN_SOUND_MODEL_ES1370 + 1); =20 for (i =3D 0; i < (VIR_DOMAIN_SOUND_MODEL_ES1370 + 1); i++) { - virDomainSoundDefPtr sound; - if (VIR_ALLOC(sound) < 0) - return -1; + virDomainSoundDefPtr sound =3D g_new0(virDomainSoundDef, 1); sound->model =3D i; def->sounds[def->nsounds++] =3D sound; } @@ -1424,8 +1394,7 @@ xenParseSxprSound(virDomainDefPtr def, return -1; } =20 - if (VIR_ALLOC(sound) < 0) - return -1; + sound =3D g_new0(virDomainSoundDef, 1); =20 if ((sound->model =3D virDomainSoundModelTypeFromString(model)= ) < 0) { VIR_FREE(sound); @@ -1661,8 +1630,7 @@ xenFormatSerial(virConfValuePtr list, virDomainChrDef= Ptr serial) virBufferAddLit(&buf, "none"); } =20 - if (VIR_ALLOC(val) < 0) - return -1; + val =3D g_new0(virConfValue, 1); =20 val->type =3D VIR_CONF_STRING; val->str =3D virBufferContentAndReset(&buf); @@ -1684,8 +1652,7 @@ xenMakeIPList(virNetDevIPInfoPtr guestIP) char **address_array; char *ret =3D NULL; =20 - if (VIR_ALLOC_N(address_array, guestIP->nips + 1) < 0) - return NULL; + address_array =3D g_new0(char *, guestIP->nips + 1); =20 for (i =3D 0; i < guestIP->nips; i++) { address_array[i] =3D virSocketAddrFormat(&guestIP->ips[i]->address= ); @@ -1822,9 +1789,7 @@ xenFormatNet(virConnectPtr conn, if (net->bandwidth && net->bandwidth->out && net->bandwidth->out->aver= age) virBufferAsprintf(&buf, ",rate=3D%lluKB/s", net->bandwidth->out->a= verage); =20 - if (VIR_ALLOC(val) < 0) - return -1; - + val =3D g_new0(virConfValue, 1); val->type =3D VIR_CONF_STRING; val->str =3D virBufferContentAndReset(&buf); tmp =3D list->list; @@ -1854,8 +1819,7 @@ xenFormatPCI(virConfPtr conf, virDomainDefPtr def) if (!hasPCI) return 0; =20 - if (VIR_ALLOC(pciVal) < 0) - return -1; + pciVal =3D g_new0(virConfValue, 1); =20 pciVal->type =3D VIR_CONF_LIST; pciVal->list =3D NULL; @@ -1888,10 +1852,7 @@ xenFormatPCI(virConfPtr conf, virDomainDefPtr def) permissive_str); =20 =20 - if (VIR_ALLOC(val) < 0) { - VIR_FREE(buf); - goto error; - } + val =3D g_new0(virConfValue, 1); val->type =3D VIR_CONF_STRING; val->str =3D buf; tmp =3D pciVal->list; @@ -1913,10 +1874,6 @@ xenFormatPCI(virConfPtr conf, virDomainDefPtr def) VIR_FREE(pciVal); =20 return 0; - - error: - virConfFreeValue(pciVal); - return -1; } =20 =20 @@ -2098,9 +2055,7 @@ xenFormatCharDev(virConfPtr conf, virDomainDefPtr def, return -1; } =20 - if (VIR_ALLOC(serialVal) < 0) - return -1; - + serialVal =3D g_new0(virConfValue, 1); serialVal->type =3D VIR_CONF_LIST; serialVal->list =3D NULL; =20 @@ -2385,16 +2340,8 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def) =20 vfbstr =3D virBufferContentAndReset(&buf); =20 - if (VIR_ALLOC(vfb) < 0) { - VIR_FREE(vfbstr); - return -1; - } - - if (VIR_ALLOC(disp) < 0) { - VIR_FREE(vfb); - VIR_FREE(vfbstr); - return -1; - } + vfb =3D g_new0(virConfValue, 1); + disp =3D g_new0(virConfValue, 1); =20 vfb->type =3D VIR_CONF_LIST; vfb->list =3D disp; @@ -2450,8 +2397,7 @@ xenFormatVif(virConfPtr conf, size_t i; int hvm =3D def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM; =20 - if (VIR_ALLOC(netVal) < 0) - goto cleanup; + netVal =3D g_new0(virConfValue, 1); netVal->type =3D VIR_CONF_LIST; netVal->list =3D NULL; =20 diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 30a8125f5f..74f48e4117 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -110,9 +110,7 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virC= apsPtr caps) return -1; =20 if (bios && STREQ(bios, "ovmf")) { - if (VIR_ALLOC(def->os.loader) < 0) - return -1; - + def->os.loader =3D g_new0(virDomainLoaderDef, 1); def->os.loader->type =3D VIR_DOMAIN_LOADER_TYPE_PFLASH; def->os.loader->readonly =3D VIR_TRISTATE_BOOL_YES; =20 @@ -121,8 +119,7 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virC= apsPtr caps) for (i =3D 0; i < caps->nguests; i++) { if (caps->guests[i]->ostype =3D=3D VIR_DOMAIN_OSTYPE_HVM && caps->guests[i]->arch.id =3D=3D def->os.arch) { - if (VIR_ALLOC(def->os.loader) < 0) - return -1; + def->os.loader =3D g_new0(virDomainLoaderDef, 1); def->os.loader->path =3D g_strdup(caps->guests[i]->arc= h.defaultInfo.loader); } } @@ -345,9 +342,7 @@ xenParseXLSpice(virConfPtr conf, virDomainDefPtr def) return -1; =20 if (val) { - if (VIR_ALLOC(graphics) < 0) - return -1; - + graphics =3D g_new0(virDomainGraphicsDef, 1); graphics->type =3D VIR_DOMAIN_GRAPHICS_TYPE_SPICE; if (xenConfigCopyStringOpt(conf, "spicehost", &listenAddr) < 0) goto cleanup; @@ -394,8 +389,7 @@ xenParseXLSpice(virConfPtr conf, virDomainDefPtr def) else graphics->data.spice.copypaste =3D VIR_TRISTATE_BOOL_NO; =20 - if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto cleanup; + def->graphics =3D g_new0(virDomainGraphicsDefPtr, 1); def->graphics[0] =3D graphics; def->ngraphics =3D 1; } @@ -702,8 +696,7 @@ xenParseXLDisk(virConfPtr conf, virDomainDefPtr def) libxl_device_disk *libxldisk; virDomainDiskDefPtr disk =3D NULL; =20 - if (VIR_ALLOC(libxldisk) < 0) - return -1; + libxldisk =3D g_new0(libxl_device_disk, 1); =20 if (!(xluconf =3D xlu_cfg_init(stderr, "command line"))) goto cleanup; @@ -868,8 +861,8 @@ xenParseXLInputDevs(virConfPtr conf, virDomainDefPtr de= f) STREQ(str, "mouse") || STREQ(str, "keyboard"))) { virDomainInputDefPtr input; - if (VIR_ALLOC(input) < 0) - return -1; + input =3D g_new0(virDomainInputDef, + 1); =20 input->bus =3D VIR_DOMAIN_INPUT_BUS_USB; if (STREQ(str, "mouse")) @@ -1397,8 +1390,7 @@ xenFormatXLCPUID(virConfPtr conf, virDomainDefPtr def) } =20 /* "host" + all features + NULL */ - if (VIR_ALLOC_N(cpuid_pairs, def->cpu->nfeatures + 2) < 0) - return -1; + cpuid_pairs =3D g_new0(char *, def->cpu->nfeatures + 2); =20 cpuid_pairs[0] =3D g_strdup("host"); =20 @@ -1455,8 +1447,7 @@ xenFormatXLVnode(virConfValuePtr list, { virConfValuePtr numaPnode, tmp; =20 - if (VIR_ALLOC(numaPnode) < 0) - return -1; + numaPnode =3D g_new0(virConfValue, 1); =20 /* Place VNODE directive */ numaPnode->type =3D VIR_CONF_STRING; @@ -1487,10 +1478,10 @@ xenFormatXLVnuma(virConfValuePtr list, size_t nodeSize =3D virDomainNumaGetNodeMemorySize(numa, node) / 1024; g_autofree char *nodeVcpus =3D NULL; =20 - if (!cpumask || - VIR_ALLOC(numaVnode) < 0) - goto cleanup; + if (!cpumask) + return -1; =20 + numaVnode =3D g_new0(virConfValue, 1); numaVnode->type =3D VIR_CONF_LIST; numaVnode->list =3D NULL; =20 @@ -1527,7 +1518,6 @@ xenFormatXLVnuma(virConfValuePtr list, list->list =3D numaVnode; ret =3D 0; =20 - cleanup: VIR_FREE(nodeVcpus); return ret; } @@ -1544,8 +1534,7 @@ xenFormatXLDomainVnuma(virConfPtr conf, if (numa =3D=3D NULL) return -1; =20 - if (VIR_ALLOC(vnumaVal) < 0) - return -1; + vnumaVal =3D g_new0(virConfValue, 1); =20 vnumaVal->type =3D VIR_CONF_LIST; vnumaVal->list =3D NULL; @@ -1772,8 +1761,7 @@ xenFormatXLDisk(virConfValuePtr list, virDomainDiskDe= fPtr disk) if (target) virBufferAsprintf(&buf, ",target=3D%s", target); =20 - if (VIR_ALLOC(val) < 0) - goto cleanup; + val =3D g_new0(virConfValue, 1); =20 val->type =3D VIR_CONF_STRING; val->str =3D virBufferContentAndReset(&buf); @@ -1798,8 +1786,7 @@ xenFormatXLDomainDisks(virConfPtr conf, virDomainDefP= tr def) virConfValuePtr diskVal; size_t i; =20 - if (VIR_ALLOC(diskVal) < 0) - return -1; + diskVal =3D g_new0(virConfValue, 1); =20 diskVal->type =3D VIR_CONF_LIST; diskVal->list =3D NULL; @@ -1923,9 +1910,7 @@ xenFormatXLInputDevs(virConfPtr conf, virDomainDefPtr= def) virConfValuePtr usbdevices =3D NULL, lastdev; =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { - if (VIR_ALLOC(usbdevices) < 0) - goto error; - + usbdevices =3D g_new0(virConfValue, 1); usbdevices->type =3D VIR_CONF_LIST; usbdevices->list =3D NULL; lastdev =3D NULL; @@ -1949,12 +1934,10 @@ xenFormatXLInputDevs(virConfPtr conf, virDomainDefP= tr def) } =20 if (lastdev =3D=3D NULL) { - if (VIR_ALLOC(lastdev) < 0) - goto error; + lastdev =3D g_new0(virConfValue, 1); usbdevices->list =3D lastdev; } else { - if (VIR_ALLOC(lastdev->next) < 0) - goto error; + lastdev->next =3D g_new0(virConfValue, 1); lastdev =3D lastdev->next; } lastdev->type =3D VIR_CONF_STRING; @@ -2000,8 +1983,7 @@ xenFormatXLUSBController(virConfPtr conf, if (!hasUSBCtrl) return 0; =20 - if (VIR_ALLOC(usbctrlVal) < 0) - return -1; + usbctrlVal =3D g_new0(virConfValue, 1); =20 usbctrlVal->type =3D VIR_CONF_LIST; usbctrlVal->list =3D NULL; @@ -2030,9 +2012,7 @@ xenFormatXLUSBController(virConfPtr conf, virBufferAsprintf(&buf, "ports=3D%x", def->controllers[i]->opts.usbopts.ports); =20 - if (VIR_ALLOC(val) < 0) - goto error; - + val =3D g_new0(virConfValue, 1); val->type =3D VIR_CONF_STRING; val->str =3D virBufferContentAndReset(&buf); tmp =3D usbctrlVal->list; @@ -2080,8 +2060,7 @@ xenFormatXLUSB(virConfPtr conf, if (!hasUSB) return 0; =20 - if (VIR_ALLOC(usbVal) < 0) - return -1; + usbVal =3D g_new0(virConfValue, 1); =20 usbVal->type =3D VIR_CONF_LIST; usbVal->list =3D NULL; @@ -2096,10 +2075,7 @@ xenFormatXLUSB(virConfPtr conf, def->hostdevs[i]->source.subsys.u.usb.bu= s, def->hostdevs[i]->source.subsys.u.usb.de= vice); =20 - if (VIR_ALLOC(val) < 0) { - VIR_FREE(buf); - goto error; - } + val =3D g_new0(virConfValue, 1); val->type =3D VIR_CONF_STRING; val->str =3D buf; tmp =3D usbVal->list; @@ -2121,10 +2097,6 @@ xenFormatXLUSB(virConfPtr conf, VIR_FREE(usbVal); =20 return 0; - - error: - virConfFreeValue(usbVal); - return -1; } =20 static int @@ -2154,9 +2126,7 @@ xenFormatXLChannel(virConfValuePtr list, virDomainChr= DefPtr channel) /* name */ virBufferAsprintf(&buf, "name=3D%s", channel->target.name); =20 - if (VIR_ALLOC(val) < 0) - return -1; - + val =3D g_new0(virConfValue, 1); val->type =3D VIR_CONF_STRING; val->str =3D virBufferContentAndReset(&buf); tmp =3D list->list; @@ -2175,8 +2145,7 @@ xenFormatXLDomainChannels(virConfPtr conf, virDomainD= efPtr def) virConfValuePtr channelVal =3D NULL; size_t i; =20 - if (VIR_ALLOC(channelVal) < 0) - goto cleanup; + channelVal =3D g_new0(virConfValue, 1); =20 channelVal->type =3D VIR_CONF_LIST; channelVal->list =3D NULL; @@ -2219,8 +2188,7 @@ xenFormatXLDomainNamespaceData(virConfPtr conf, virDo= mainDefPtr def) if (nsdata->num_args =3D=3D 0) return 0; =20 - if (VIR_ALLOC(args) < 0) - return -1; + args =3D g_new0(virConfValue, 1); =20 args->type =3D VIR_CONF_LIST; args->list =3D NULL; @@ -2228,8 +2196,7 @@ xenFormatXLDomainNamespaceData(virConfPtr conf, virDo= mainDefPtr def) for (i =3D 0; i < nsdata->num_args; i++) { virConfValuePtr val, tmp; =20 - if (VIR_ALLOC(val) < 0) - goto error; + val =3D g_new0(virConfValue, 1); =20 val->type =3D VIR_CONF_STRING; val->str =3D g_strdup(nsdata->args[i]); diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index edf86abc64..8ade5aec1c 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -148,8 +148,7 @@ xenParseXMDisk(char *entry, int hvm) if (!(offset =3D strchr(head, ','))) goto error; =20 - if (VIR_ALLOC_N(disk->dst, (offset - head) + 1) < 0) - goto error; + disk->dst =3D g_new0(char, (offset - head) + 1); =20 if (virStrncpy(disk->dst, head, offset - head, (offset - head) + 1) < 0) { @@ -368,8 +367,7 @@ xenFormatXMDisks(virConfPtr conf, virDomainDefPtr def) virConfValuePtr diskVal =3D NULL; size_t i =3D 0; =20 - if (VIR_ALLOC(diskVal) < 0) - goto cleanup; + diskVal =3D g_new0(virConfValue, 1); =20 diskVal->type =3D VIR_CONF_LIST; diskVal->list =3D NULL; @@ -411,8 +409,7 @@ xenParseXMInputDevs(virConfPtr conf, virDomainDefPtr de= f) STREQ(str, "mouse") || STREQ(str, "keyboard"))) { virDomainInputDefPtr input; - if (VIR_ALLOC(input) < 0) - return -1; + input =3D g_new0(virDomainInputDef, 1); =20 input->bus =3D VIR_DOMAIN_INPUT_BUS_USB; if (STREQ(str, "mouse")) --=20 2.26.2 From nobody Mon Apr 29 04:51:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601402520; cv=none; d=zohomail.com; s=zohoarc; b=Ltviq/z0Z5P8j49lFmqfaBOZSMpgAjm6KUdVHEVZ+hfNYVVwzlSbE9Ebi7FnDtAhlYAFLBcw/fsnuQzL62tpvAfJ6nQRXPdcslmBpXL6SjGmD+KHszfR2XQWb8c8FOAfbu6dcQifeteER60zH6P3E4MmdrDbQgVrGbGwQn+zhiU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601402520; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VpgAe7RKcPSUns3JyODytVaMHKyIzE6bGUZU93WpK74=; b=E+dUn+jCxuyfH0GGSUSFFZ6YTDcZFAZ9/o+A3E4m4NbyKgetEJwr9LrSWwhWpOKZNVcARW+LHa7+Y8EjaJeYTR5R6UWgJ10uRLmCrZlVwLaf6jMOu7bITusyq4WczCAvQoFDctsSZOTwX3y+lknmkkVEArX/e18cVaPSDODrbHQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1601402520302869.621883983979; Tue, 29 Sep 2020 11:02:00 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-524-W7Ecg6HLMmOBYqyC7gtu-A-1; Tue, 29 Sep 2020 14:01:56 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EAA571074646; Tue, 29 Sep 2020 18:01:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C63F37EB77; Tue, 29 Sep 2020 18:01:50 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8FCAA44A5F; Tue, 29 Sep 2020 18:01:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08TI1X9f017077 for ; Tue, 29 Sep 2020 14:01:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 157421002C04; Tue, 29 Sep 2020 18:01:33 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F7881002C0E for ; Tue, 29 Sep 2020 18:01:32 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601402519; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=VpgAe7RKcPSUns3JyODytVaMHKyIzE6bGUZU93WpK74=; b=hwrOcBIi2JK6yeKn/w2Jb3A5MSvmU9ry67yamwKEx9CsSYHovZ4h4a7ZGbe+z7UwPxHzWS 8t92oVjPtfZ7muoF7dim7NJoztmepTLcoPyGgt0LfJIt25Nc4AVgjvfVVY+cyWE+xwYe/X pBcHbY/enZ78gvdEm90aN8j0/T4zgvU= X-MC-Unique: W7Ecg6HLMmOBYqyC7gtu-A-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/2] locking: prefer g_new0 to VIR_ALLOC Date: Tue, 29 Sep 2020 20:01:26 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- src/locking/lock_daemon.c | 9 +++------ src/locking/lock_daemon_config.c | 3 +-- src/locking/lock_driver_lockd.c | 7 +++---- src/locking/lock_driver_sanlock.c | 10 ++++------ src/locking/lock_manager.c | 6 ++---- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index e1b495e8ba..88fa7b7957 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -120,8 +120,7 @@ virLockDaemonNew(virLockDaemonConfigPtr config, bool pr= ivileged) virLockDaemonPtr lockd; virNetServerPtr srv =3D NULL; =20 - if (VIR_ALLOC(lockd) < 0) - return NULL; + lockd =3D g_new0(virLockDaemon, 1); =20 g_mutex_init(&lockd->lock); =20 @@ -212,8 +211,7 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object,= bool privileged) size_t i; const char *serverNames[] =3D { "virtlockd" }; =20 - if (VIR_ALLOC(lockd) < 0) - return NULL; + lockd =3D g_new0(virLockDaemon, 1); =20 g_mutex_init(&lockd->lock); =20 @@ -456,8 +454,7 @@ virLockDaemonClientNew(virNetServerClientPtr client, unsigned long long timestamp; bool privileged =3D opaque !=3D NULL; =20 - if (VIR_ALLOC(priv) < 0) - return NULL; + priv =3D g_new0(virLockDaemonClient, 1); =20 g_mutex_init(&priv->lock); =20 diff --git a/src/locking/lock_daemon_config.c b/src/locking/lock_daemon_con= fig.c index c67b0a75e1..6346703715 100644 --- a/src/locking/lock_daemon_config.c +++ b/src/locking/lock_daemon_config.c @@ -57,8 +57,7 @@ virLockDaemonConfigNew(bool privileged G_GNUC_UNUSED) { virLockDaemonConfigPtr data; =20 - if (VIR_ALLOC(data) < 0) - return NULL; + data =3D g_new0(virLockDaemonConfig, 1); =20 data->max_clients =3D 1024; data->admin_max_clients =3D 5000; diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lock= d.c index bec98dd05f..15d9e5f076 100644 --- a/src/locking/lock_driver_lockd.c +++ b/src/locking/lock_driver_lockd.c @@ -316,8 +316,7 @@ static int virLockManagerLockDaemonInit(unsigned int ve= rsion, if (driver) return 0; =20 - if (VIR_ALLOC(driver) < 0) - return -1; + driver =3D g_new0(virLockManagerLockDaemonDriver, 1); =20 driver->requireLeaseForDisks =3D true; driver->autoDiskLease =3D true; @@ -399,8 +398,8 @@ static int virLockManagerLockDaemonNew(virLockManagerPt= r lock, =20 virCheckFlags(VIR_LOCK_MANAGER_NEW_STARTED, -1); =20 - if (VIR_ALLOC(priv) < 0) - return -1; + priv =3D g_new0(virLockManagerLockDaemonPrivate, + 1); =20 switch (type) { case VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN: diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sa= nlock.c index 640033eb97..9c38a1d2f6 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -397,8 +397,7 @@ static int virLockManagerSanlockInit(unsigned int versi= on, if (sanlockDriver) return 0; =20 - if (VIR_ALLOC(sanlockDriver) < 0) - return -1; + sanlockDriver =3D g_new0(virLockManagerSanlockDriver, 1); =20 driver =3D sanlockDriver; =20 @@ -468,8 +467,8 @@ static int virLockManagerSanlockNew(virLockManagerPtr l= ock, return -1; } =20 - if (VIR_ALLOC(priv) < 0) - return -1; + priv =3D g_new0(virLockManagerSanlockPrivate, + 1); =20 priv->flags =3D flags; =20 @@ -937,8 +936,7 @@ static int virLockManagerSanlockAcquire(virLockManagerP= tr lock, return 0; } =20 - if (VIR_ALLOC(opt) < 0) - goto error; + opt =3D g_new0(struct sanlk_options, 1); =20 /* sanlock doesn't use owner_name for anything, so it's safe to take j= ust * the first SANLK_NAME_LEN - 1 characters from vm_name */ diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c index 07034b1799..d83a192bf6 100644 --- a/src/locking/lock_manager.c +++ b/src/locking/lock_manager.c @@ -171,8 +171,7 @@ virLockManagerPluginPtr virLockManagerPluginNew(const c= har *name, if (driver->drvInit(VIR_LOCK_MANAGER_VERSION, configFile, flags) < 0) goto cleanup; =20 - if (VIR_ALLOC(plugin) < 0) - goto cleanup; + plugin =3D g_new0(virLockManagerPlugin, 1); =20 plugin->driver =3D driver; plugin->handle =3D handle; @@ -303,8 +302,7 @@ virLockManagerPtr virLockManagerNew(virLockDriverPtr dr= iver, =20 CHECK_DRIVER(drvNew, NULL); =20 - if (VIR_ALLOC(lock) < 0) - return NULL; + lock =3D g_new0(virLockManager, 1); =20 lock->driver =3D driver; =20 --=20 2.26.2