From nobody Sun Feb 8 09:41:08 2026 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=1601920143; cv=none; d=zohomail.com; s=zohoarc; b=SRxbAH2zEXQkKzMQ/t9V7xAjebp/GO7Ay8bzhR8hmQKA5+QOEtyly9fcDyaDRrC0GGAnfj24vPBz4dvSBAjDI/4KjCjpotnp1pBC2JQkeNRBi0jwo7X0PyaOr8SqzUq2AmP+XVT9UrXYtYugFezOh4kggcr0M9BxdZ72vBYJfeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601920143; 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=7Dc4OdVBt3RZU+smYP25PqHKOfU22IbMwsRChfggwqI=; b=j6r5FPbblYrV5u2SndE4eyfssp9q2MNFtksR9uGoMMxEOLJHvu2fJAPsiTrXmsQ55uRcozeBiJbWXsBn2NklWSIcpiik9SyGLX6RWCizZ8xkS1y2AiYOghmeEhHrsWaG6/w0s7GOtGMgLVEawuxM+CHVVOrrYoHXRkXknzfvES8= 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 1601920143014278.9443691636719; Mon, 5 Oct 2020 10:49:03 -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-543-YUVrly0_MfuW1t78-oFk9A-1; Mon, 05 Oct 2020 13:48:59 -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 DBC5781C478; Mon, 5 Oct 2020 17:48:52 +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 BB00A7368A; Mon, 5 Oct 2020 17:48:52 +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 8856244A73; Mon, 5 Oct 2020 17:48:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 095HmdAn015635 for ; Mon, 5 Oct 2020 13:48:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 73ACA5C1C4; Mon, 5 Oct 2020 17:48:39 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE7E55C225 for ; Mon, 5 Oct 2020 17:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601920141; 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=7Dc4OdVBt3RZU+smYP25PqHKOfU22IbMwsRChfggwqI=; b=cglNZNDKQei8P5KZbLQpCe2VSYGRrLubHeDLK0h5vSBE5AAK+gv1Tw97cV+53tKn1iI/uk v63BPs+PVIWEkzFCSkPwpXzVJ+OrpB0PiTwzQmJQ3xxydz9I1AU0Yn21iWc0pZEIfLd+7U lzSaMecv1wjU0/1B0n3V482icTU2W6s= X-MC-Unique: YUVrly0_MfuW1t78-oFk9A-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 07/12] util: netdev: use g_new0 Date: Mon, 5 Oct 2020 19:48:22 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 --- src/util/virnetdev.c | 25 +++++++++---------------- src/util/virnetdevbandwidth.c | 22 ++++------------------ src/util/virnetdevip.c | 3 +-- src/util/virnetdevmacvlan.c | 6 ++---- src/util/virnetdevtap.c | 3 +-- src/util/virnetdevvlan.c | 4 +--- src/util/virnetdevvportprofile.c | 7 ++----- 7 files changed, 20 insertions(+), 50 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 76aeeba22a..e711a6dc8a 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1209,8 +1209,7 @@ virNetDevGetVirtualFunctions(const char *pfname, n_vfname, max_vfs) < 0) goto cleanup; =20 - if (VIR_ALLOC_N(*vfname, *n_vfname) < 0) - goto cleanup; + *vfname =3D g_new0(char *, *n_vfname); =20 for (i =3D 0; i < *n_vfname; i++) { g_autofree char *pciConfigAddr =3D NULL; @@ -2039,8 +2038,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, } =20 if (MACStr) { - if (VIR_ALLOC(*MAC) < 0) - goto cleanup; + *MAC =3D g_new0(virMacAddr, 1); =20 if (virMacAddrParse(MACStr, *MAC) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2051,8 +2049,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf, } =20 if (adminMACStr) { - if (VIR_ALLOC(*adminMAC) < 0) - goto cleanup; + *adminMAC =3D g_new0(virMacAddr, 1); =20 if (virMacAddrParse(adminMACStr, *adminMAC) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2064,10 +2061,8 @@ virNetDevReadNetConfig(const char *linkdev, int vf, =20 if (vlanTag !=3D -1) { /* construct a simple virNetDevVlan object with a single tag */ - if (VIR_ALLOC(*vlan) < 0) - goto cleanup; - if (VIR_ALLOC((*vlan)->tag) < 0) - goto cleanup; + *vlan =3D g_new0(virNetDevVlan, 1); + (*vlan)->tag =3D g_new0(unsigned int, 1); (*vlan)->nTags =3D 1; (*vlan)->tag[0] =3D vlanTag; } @@ -2664,8 +2659,8 @@ static int virNetDevGetMcastList(const char *ifname, =20 cur =3D buf; while (cur) { - if (!entry && VIR_ALLOC(entry) < 0) - return -1; + if (!entry) + entry =3D g_new0(virNetDevMcastEntry, 1); =20 next =3D strchr(cur, '\n'); if (next) @@ -2709,8 +2704,7 @@ static int virNetDevGetMulticastTable(const char *ifn= ame, goto cleanup; =20 if (mcast.nentries > 0) { - if (VIR_ALLOC_N(filter->multicast.table, mcast.nentries) < 0) - goto cleanup; + filter->multicast.table =3D g_new0(virMacAddr, mcast.nentries); =20 for (i =3D 0; i < mcast.nentries; i++) { virMacAddrSet(&filter->multicast.table[i], @@ -2733,8 +2727,7 @@ virNetDevRxFilterNew(void) { virNetDevRxFilterPtr filter; =20 - if (VIR_ALLOC(filter) < 0) - return NULL; + filter =3D g_new0(virNetDevRxFilter, 1); return filter; } =20 diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c index 5fd7186760..c8eb5cfc79 100644 --- a/src/util/virnetdevbandwidth.c +++ b/src/util/virnetdevbandwidth.c @@ -442,39 +442,25 @@ int virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest, const virNetDevBandwidth *src) { - int ret =3D -1; - *dest =3D NULL; if (!src) { /* nothing to be copied */ return 0; } =20 - if (VIR_ALLOC(*dest) < 0) - goto cleanup; + *dest =3D g_new0(virNetDevBandwidth, 1); =20 if (src->in) { - if (VIR_ALLOC((*dest)->in) < 0) - goto cleanup; + (*dest)->in =3D g_new0(virNetDevBandwidthRate, 1); memcpy((*dest)->in, src->in, sizeof(*src->in)); } =20 if (src->out) { - if (VIR_ALLOC((*dest)->out) < 0) { - VIR_FREE((*dest)->in); - goto cleanup; - } + (*dest)->out =3D g_new0(virNetDevBandwidthRate, 1); memcpy((*dest)->out, src->out, sizeof(*src->out)); } =20 - ret =3D 0; - - cleanup: - if (ret < 0) { - virNetDevBandwidthFree(*dest); - *dest =3D NULL; - } - return ret; + return 0; } =20 bool diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c index a69567da6f..fc7808cbaa 100644 --- a/src/util/virnetdevip.c +++ b/src/util/virnetdevip.c @@ -180,8 +180,7 @@ virNetDevIPAddrAdd(const char *ifname, if (VIR_SOCKET_ADDR_FAMILY(addr) =3D=3D AF_INET && !(peer && VIR_SOCKET_ADDR_VALID(peer))) { /* compute a broadcast address if this is IPv4 */ - if (VIR_ALLOC(broadcast) < 0) - return -1; + broadcast =3D g_new0(virSocketAddr, 1); =20 if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index f301a9e96c..72f0d67086 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -726,11 +726,9 @@ virNetDevMacVLanVPortProfileRegisterCallback(const cha= r *ifname, virNetlinkCallbackDataPtr calld =3D NULL; =20 if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE))= { - if (VIR_ALLOC(calld) < 0) - goto error; + calld =3D g_new0(struct virNetlinkCallbackData, 1); calld->cr_ifname =3D g_strdup(ifname); - if (VIR_ALLOC(calld->virtPortProfile) < 0) - goto error; + calld->virtPortProfile =3D g_new0(virNetDevVPortProfile, 1); memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortPr= ofile)); virMacAddrSet(&calld->macaddress, macaddress); calld->linkdev =3D g_strdup(linkdev); diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 1738f48a5f..198607b5bb 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -165,8 +165,7 @@ virNetDevTapGetRealDeviceName(char *ifname G_GNUC_UNUSE= D) return NULL; } =20 - if (VIR_ALLOC_N(ret, len) < 0) - return NULL; + ret =3D g_new0(char, len); =20 if (sysctl(name, 6, ret, &len, 0, 0) < 0) { virReportSystemError(errno, diff --git a/src/util/virnetdevvlan.c b/src/util/virnetdevvlan.c index 2076cc48dc..154d92497c 100644 --- a/src/util/virnetdevvlan.c +++ b/src/util/virnetdevvlan.c @@ -83,9 +83,7 @@ virNetDevVlanCopy(virNetDevVlanPtr dst, const virNetDevVl= an *src) if (!src || src->nTags =3D=3D 0) return 0; =20 - if (VIR_ALLOC_N(dst->tag, src->nTags) < 0) - return -1; - + dst->tag =3D g_new0(unsigned int, src->nTags); dst->trunk =3D src->trunk; dst->nTags =3D src->nTags; dst->nativeMode =3D src->nativeMode; diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprof= ile.c index 5dae8aa57d..5d6c055b32 100644 --- a/src/util/virnetdevvportprofile.c +++ b/src/util/virnetdevvportprofile.c @@ -129,9 +129,7 @@ int virNetDevVPortProfileCopy(virNetDevVPortProfilePtr = *dst, const virNetDevVPor return 0; } =20 - if (VIR_ALLOC(*dst) < 0) - return -1; - + *dst =3D g_new0(virNetDevVPortProfile, 1); memcpy(*dst, src, sizeof(*src)); return 0; } @@ -431,8 +429,7 @@ int virNetDevVPortProfileMerge3(virNetDevVPortProfilePt= r *result, } =20 /* at least one of the source profiles is non-empty */ - if (VIR_ALLOC(*result) < 0) - return ret; + *result =3D g_new0(virNetDevVPortProfile, 1); =20 /* start with the interface's profile. There are no pointers in a * virtualPortProfile, so a shallow copy is sufficient. --=20 2.26.2