From nobody Tue May 7 07:28:55 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=1612359289; cv=none; d=zohomail.com; s=zohoarc; b=IQOL+/xdRDrf+z7lipUmuHq4qt54Mp2Gy0iSGeBRt2dGroIUbddjvdXKNXW2Fgm67oBEGFz9XAtKxfT1eU3lGP6UGCwaYVHYZQKjWGHJZgjSMs2sA5DPyaPbvYcq9Ciqu9GeDReZ7WQaM9OAj9yhdyLMKAbjmbpSK00vIPX6UaA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612359289; 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=njKO7GAC77CfYm698/EEZWv+6hOqDNinnNcp1ukqwyw=; b=mSc033yKjbw0ddGaG+qls1DRt3M1bdbfEAPTSV6P1eqWFYtoHpZv72731KTnPsBx54yrLxnKZeRt5uBroDHs73q/8CZMY3kOzRPsOzKrh8spHRPQOqQd8aK/3Oi3H6dNR7hwtXizu5A8sl8p0O//N7awREWOAOH2NiKsyDJV/88= 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 1612359289229314.6023612383384; Wed, 3 Feb 2021 05:34:49 -0800 (PST) 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-374-bvZct4Q8MMOj1LL7P4KIeQ-1; Wed, 03 Feb 2021 08:34:46 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B5C6C107ACE8; Wed, 3 Feb 2021 13:34:40 +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 8E7995D9E3; Wed, 3 Feb 2021 13:34:40 +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 969B14EE76; Wed, 3 Feb 2021 13:34:36 +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 113DYXhf014042 for ; Wed, 3 Feb 2021 08:34:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1206F2CFCE; Wed, 3 Feb 2021 13:34:33 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D23E5C6B8 for ; Wed, 3 Feb 2021 13:34:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612359288; 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=njKO7GAC77CfYm698/EEZWv+6hOqDNinnNcp1ukqwyw=; b=QAuUSe9FLCglKI3jNp+Q+Ey2Iu+S5HjZYN3JTIxuNhxz3zW0Z+CfHEVaY91f9+cU2kyEgw 45r1BeMk8+/3ot54zIe6+PLd9QD5NBB1I5XEncPCtBlm9EWbb/cWhFtZ+aAOVEhwb8BzHk lUnmrzg7Dbu4k+QyLp5nfH6JOvfafsM= X-MC-Unique: bvZct4Q8MMOj1LL7P4KIeQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/6] virNWFilterVarCombIter: Allocate 'iter' member separately Date: Wed, 3 Feb 2021 14:34:21 +0100 Message-Id: <14b2747d77f15f5ae7e625882b514cdaebc9acfc.1612358891.git.pkrempa@redhat.com> 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.14 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Switch to the more common approach of having arrays allocated separately rather than trailing the struct. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrang=C3=A9 --- src/conf/nwfilter_params.c | 6 ++++-- src/conf/nwfilter_params.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c index 18b64e373b..1be492759a 100644 --- a/src/conf/nwfilter_params.c +++ b/src/conf/nwfilter_params.c @@ -304,6 +304,8 @@ virNWFilterVarCombIterFree(virNWFilterVarCombIterPtr ci) for (i =3D 0; i < ci->nIter; i++) g_free(ci->iter[i].varNames); + g_free(ci->iter); + g_free(ci); } @@ -465,8 +467,8 @@ virNWFilterVarCombIterCreate(GHashTable *hash, int iterIndex =3D -1; unsigned int nextIntIterId =3D VIR_NWFILTER_MAX_ITERID + 1; - if (VIR_ALLOC_VAR(res, virNWFilterVarCombIterEntry, 1 + nVarAccess) < = 0) - return NULL; + res =3D g_new0(virNWFilterVarCombIter, 1); + res->iter =3D g_new0(virNWFilterVarCombIterEntry, nVarAccess + 1); res->hashTable =3D hash; diff --git a/src/conf/nwfilter_params.h b/src/conf/nwfilter_params.h index 05a6a43399..59068b8ae9 100644 --- a/src/conf/nwfilter_params.h +++ b/src/conf/nwfilter_params.h @@ -137,7 +137,7 @@ typedef virNWFilterVarCombIter *virNWFilterVarCombIterP= tr; struct _virNWFilterVarCombIter { GHashTable *hashTable; size_t nIter; - virNWFilterVarCombIterEntry iter[0]; + virNWFilterVarCombIterEntryPtr iter; }; virNWFilterVarCombIterPtr virNWFilterVarCombIterCreate( GHashTable *hash, --=20 2.29.2 From nobody Tue May 7 07:28:55 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=1612359288; cv=none; d=zohomail.com; s=zohoarc; b=Y2EdHqMbXaL2Eu3yYdAHeZED/GAevx287ZRh5QavMjBlE7JZWyp+MCszEGxriLhti32fhJSUgb+GIOeDD7ps+RCywozlNcD3s73ISuZfgEAKpfdGe7E7/M70hL5+Hje0eGJ+/QWGF1siasc/wyq+6maMHjM70m3tW142FVKpU74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612359288; 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=nUHF4+bozopR7nWFt89tXTeEhKPJPAJX2d76afGJrP0=; b=T8YMsftqwWHV4sjGDRPBTWvBrcRk3FC0NK3uAQGQJrqsZaGi5L3UJP7hUakq9nn9MAT6rcnxbYXJcSWMMbFszmf6cG5Wbk1xbpoDLGoHpd9pyMMCSjQHJMeB5FOYryr/tfLVA5gGDYwXYVXMiY2NHjdh1DBX+TYu3snUbrng2FU= 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 1612359288286899.4299505344375; Wed, 3 Feb 2021 05:34:48 -0800 (PST) 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-358-9P3eWbgbNtSGECHTPXQSaQ-1; Wed, 03 Feb 2021 08:34:45 -0500 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 AB97BDF8A7; Wed, 3 Feb 2021 13:34:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7958750EDE; Wed, 3 Feb 2021 13:34:39 +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 3BAAE18095C9; Wed, 3 Feb 2021 13:34:36 +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 113DYYhv014054 for ; Wed, 3 Feb 2021 08:34:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 36BE62CFCE; Wed, 3 Feb 2021 13:34:34 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A40C5884C for ; Wed, 3 Feb 2021 13:34:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612359287; 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=nUHF4+bozopR7nWFt89tXTeEhKPJPAJX2d76afGJrP0=; b=c5Wq7kMDIwy/VIczA8FQk+9CSk77niY0OsZh58dxTIOBnXe3I1yf+ZeqEOuKP4QHhC3pyN A9CWjvnOWrXNoaDCunxzyGAHNb2G8i64T4vm8jGfrj96nAxAB+Yrv+sHoujmCqlBdF+j2c Cg/3kGLG8/t7013q2E9D4jw8lXsVt0A= X-MC-Unique: 9P3eWbgbNtSGECHTPXQSaQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/6] virLockManagerSanlockAddLease: Refactor cleanup Date: Wed, 3 Feb 2021 14:34:22 +0100 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.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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use g_autofree and remove the 'cleanup' section and 'ret' variable. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrang=C3=A9 --- src/locking/lock_driver_sanlock.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sa= nlock.c index 9c38a1d2f6..77c8d9542b 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -528,12 +528,11 @@ static int virLockManagerSanlockAddLease(virLockManag= erPtr lock, bool shared) { virLockManagerSanlockPrivatePtr priv =3D lock->privateData; - int ret =3D -1; - struct sanlk_resource *res =3D NULL; + g_autofree struct sanlk_resource *res =3D NULL; size_t i; if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0) - goto cleanup; + return -1; res->flags =3D shared ? SANLK_RES_SHARED : 0; res->num_disks =3D 1; @@ -541,7 +540,7 @@ static int virLockManagerSanlockAddLease(virLockManager= Ptr lock, virReportError(VIR_ERR_INTERNAL_ERROR, _("Resource name '%s' exceeds %d characters"), name, SANLK_NAME_LEN); - goto cleanup; + return -1; } for (i =3D 0; i < nparams; i++) { @@ -550,7 +549,7 @@ static int virLockManagerSanlockAddLease(virLockManager= Ptr lock, virReportError(VIR_ERR_INTERNAL_ERROR, _("Lease path '%s' exceeds %d characters"), params[i].value.str, SANLK_PATH_LEN); - goto cleanup; + return -1; } } else if (STREQ(params[i].key, "offset")) { res->disks[0].offset =3D params[i].value.ul; @@ -559,20 +558,15 @@ static int virLockManagerSanlockAddLease(virLockManag= erPtr lock, virReportError(VIR_ERR_INTERNAL_ERROR, _("Resource lockspace '%s' exceeds %d chara= cters"), params[i].value.str, SANLK_NAME_LEN); - goto cleanup; + return -1; } } } - priv->res_args[priv->res_count] =3D res; + priv->res_args[priv->res_count] =3D g_steal_pointer(&res); priv->res_count++; - ret =3D 0; - - cleanup: - if (ret =3D=3D -1) - VIR_FREE(res); - return ret; + return 0; } --=20 2.29.2 From nobody Tue May 7 07:28:55 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=1612359364; cv=none; d=zohomail.com; s=zohoarc; b=as8PSPEfFg8gmpOBGM/udFiE+XLE6tSxuKtq9ACa/FuSHtkzAsfWpVXTz1cBC3zS5mXsIZb9rzICjJA7TMdydxsCAe3os2+VYKoWlHfoRId9YdvhJZB2dfO64zTTt7ubSI5kBOuIpDPHXqiAbEQILkRFJOJcwRhg5+4dni+7Qi8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612359364; 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=geLMwHyYC2RvhPdbkNbBhX663CWG4gFZVh0ovHwRbQo=; b=QTY5VoJsTrjD5EVGmzFPrfO1TX257dAgeZpUPxCaPewO9RYttgOsVMsKwYkfGDeqdJlDvaDVUReKF31A3+h1SKyzRdAWZUa09A099GAQbxEpPlcLVXMmepaCphIhoNFNCzxsGiMOLfRQNk0yiyy6DsD+8BvRzxywjWQGEkblh1E= 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 1612359364741425.31082385472234; Wed, 3 Feb 2021 05:36:04 -0800 (PST) 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-491-c_2Xxrr9NayaPlQOJ2CS8Q-1; Wed, 03 Feb 2021 08:35:07 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4B001DF8B5; Wed, 3 Feb 2021 13:35:01 +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 2634A60C6C; Wed, 3 Feb 2021 13:35:01 +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 DC98C85F2; Wed, 3 Feb 2021 13:35:00 +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 113DYZp2014064 for ; Wed, 3 Feb 2021 08:34:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3F2292CFCE; Wed, 3 Feb 2021 13:34:35 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AFEF5884C for ; Wed, 3 Feb 2021 13:34:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612359363; 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=geLMwHyYC2RvhPdbkNbBhX663CWG4gFZVh0ovHwRbQo=; b=ccm0oiNuOLvFwCjHBKjDpULfTQB0IsRnc/fNyR542XGd4tqsPdnqbHhZA4M9809lF7L7l4 t2+bvhF7iKV8Qmz9vBU1AXeeXxkyS75s2ZWwJMwclW89LjmNZovQ2ohWVEYcwsTz/SRjnv dmfiTVtzTssx20NwD5HIn9MaeDNtZ60= X-MC-Unique: c_2Xxrr9NayaPlQOJ2CS8Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/6] virLockManagerSanlockAddDisk: Refactor cleanup Date: Wed, 3 Feb 2021 14:34:23 +0100 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.12 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use g_autofree to allow removal of 'cleanup:' and the 'ret' variable. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrang=C3=A9 --- src/locking/lock_driver_sanlock.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sa= nlock.c index 77c8d9542b..f35a0c065c 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -581,10 +581,9 @@ virLockManagerSanlockAddDisk(virLockManagerSanlockDriv= erPtr driver, bool shared) { virLockManagerSanlockPrivatePtr priv =3D lock->privateData; - int ret =3D -1; - struct sanlk_resource *res =3D NULL; - char *path =3D NULL; - char *hash =3D NULL; + g_autofree struct sanlk_resource *res =3D NULL; + g_autofree char *path =3D NULL; + g_autofree char *hash =3D NULL; if (nparams) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -593,17 +592,17 @@ virLockManagerSanlockAddDisk(virLockManagerSanlockDri= verPtr driver, } if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0) - goto cleanup; + return -1; res->flags =3D shared ? SANLK_RES_SHARED : 0; res->num_disks =3D 1; if (virCryptoHashString(VIR_CRYPTO_HASH_MD5, name, &hash) < 0) - goto cleanup; + return -1; if (virStrcpy(res->name, hash, SANLK_NAME_LEN) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("MD5 hash '%s' unexpectedly larger than %d charac= ters"), hash, (SANLK_NAME_LEN - 1)); - goto cleanup; + return -1; } path =3D g_strdup_printf("%s/%s", driver->autoDiskLeasePath, res->name= ); @@ -611,7 +610,7 @@ virLockManagerSanlockAddDisk(virLockManagerSanlockDrive= rPtr driver, virReportError(VIR_ERR_INTERNAL_ERROR, _("Lease path '%s' exceeds %d characters"), path, SANLK_PATH_LEN); - goto cleanup; + return -1; } if (virStrcpy(res->lockspace_name, @@ -620,20 +619,13 @@ virLockManagerSanlockAddDisk(virLockManagerSanlockDri= verPtr driver, virReportError(VIR_ERR_INTERNAL_ERROR, _("Resource lockspace '%s' exceeds %d characters"), VIR_LOCK_MANAGER_SANLOCK_AUTO_DISK_LOCKSPACE, SANLK= _NAME_LEN); - goto cleanup; + return -1; } - priv->res_args[priv->res_count] =3D res; + priv->res_args[priv->res_count] =3D g_steal_pointer(&res); priv->res_count++; - ret =3D 0; - - cleanup: - if (ret =3D=3D -1) - VIR_FREE(res); - VIR_FREE(path); - VIR_FREE(hash); - return ret; + return 0; } --=20 2.29.2 From nobody Tue May 7 07:28:55 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=1612359307; cv=none; d=zohomail.com; s=zohoarc; b=MmcekLBYza2PiaBGEM5QeYAzt/KtqJJFpx9axTdFT5prv/Bz307FkpZF4HMLh6qPW2Cwpn6kGyG12hAQqYBWv0PBM/K0ySqTQDr00ilScS9NRxi7hHXMrY2xWH8BvuHFEsGKWFXSR+XkB5hIUV+C7eQI2KxlASTHBiTgSon6rHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612359307; 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=wTIN2ylvbzvOF7hoUyD71Qwrz6hVXFTksgBQUizvH4g=; b=g20GOaYjGs4TzBZNfaIEl15PWdFSae5rA2CYI5N/dXVarYVONhpGxTI3eo2KUCAUi+ep8QeIM50O00SdsxoUnq/9Ag5TrMgTKV+ySyMZfIdHXs07wN00kI3dicwbwvkoChWMSzUEOcvUsa3nlm4LlA/6uZDADwxS8nEgnAovem0= 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 161235930790546.09816141203828; Wed, 3 Feb 2021 05:35:07 -0800 (PST) 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-352-X3hAaePzO6S0Vhh6vYwQVw-1; Wed, 03 Feb 2021 08:35:04 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 213A3100F344; Wed, 3 Feb 2021 13:34:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F27075D9E8; Wed, 3 Feb 2021 13:34:58 +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 B929F1809C91; Wed, 3 Feb 2021 13:34:58 +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 113DYaZa014073 for ; Wed, 3 Feb 2021 08:34:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id 425CF2CFF6; Wed, 3 Feb 2021 13:34:36 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id A52CB2CFCE for ; Wed, 3 Feb 2021 13:34:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612359306; 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=wTIN2ylvbzvOF7hoUyD71Qwrz6hVXFTksgBQUizvH4g=; b=QQxluJVIDJAtzRcJKwcRJfKVTVY0nLBlfe7PG/R9JVQG3H9UwIwdugOum7FE/D3ErR0GsX pPw2CmnryGRdl8DCfKSItmVMXaBQVMCf9UD2PBdPZ3FbnZu+Hqx0wd4HIE60FPP6EAGTMA 5+gTsx2rkmpEuh5I59K1NQgKaEA9QgU= X-MC-Unique: X3hAaePzO6S0Vhh6vYwQVw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/6] locking: sanlock: Avoid use of VIR_ALLOC_VAR for 'struct sanlk_resource' Date: Wed, 3 Feb 2021 14:34:24 +0100 Message-Id: <44b84eb74c6135280b03104a159e46c1bb5af57a.1612358891.git.pkrempa@redhat.com> 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.14 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In both cases we need memory for a 'struct sanlk_resource' followed by one 'struct sanlk_disk', thus there's no risk of overflow. Use g_malloc0 and sizeof() to allocate the memory instead of VIR_ALLOC_VAR. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrang=C3=A9 --- src/locking/lock_driver_sanlock.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sa= nlock.c index f35a0c065c..7319f56819 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -531,8 +531,7 @@ static int virLockManagerSanlockAddLease(virLockManager= Ptr lock, g_autofree struct sanlk_resource *res =3D NULL; size_t i; - if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0) - return -1; + res =3D g_malloc0(sizeof(struct sanlk_resource) + sizeof(struct sanlk_= disk)); res->flags =3D shared ? SANLK_RES_SHARED : 0; res->num_disks =3D 1; @@ -591,8 +590,7 @@ virLockManagerSanlockAddDisk(virLockManagerSanlockDrive= rPtr driver, return -1; } - if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0) - return -1; + res =3D g_malloc0(sizeof(struct sanlk_resource) + sizeof(struct sanlk_= disk)); res->flags =3D shared ? SANLK_RES_SHARED : 0; res->num_disks =3D 1; --=20 2.29.2 From nobody Tue May 7 07:28:55 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=1612359363; cv=none; d=zohomail.com; s=zohoarc; b=b82Yh/B4qgTU/AcOD+MIk2m9XbWwesVqunlARQtxJFD8hDwvQAEP/6vZjI1ju81Qiz+bRR72/T914OO2lHFPNANUtNY+0JyVw4SNME0Wa3uq9ntVUd/Q5RmTgL1WalMzl0o60/C5xVSYxGZ385Z8tjQLQP1yGVh+3ky8lx9mJFU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612359363; 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=f9nbjpEXs/iaNlvm1W9+m74L86ihk6k85xonA7rQ0AI=; b=maG6WfDl2Gm9C+6cYXNR3dfQ3rSAR3Ca8Qlh877z8iTUfYX23KWSGrA9nvtQKMCGq8dOXiYKfA42yYzHStyEbfud+N6i34kBPr8a2WBMsUy91jHXV9nW21CBAAFhAPqrTvNAQSMV+ybUt5nwT/T3SracZ81ri9WDFVJI5WPE+9g= 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 1612359363620721.1465712341769; Wed, 3 Feb 2021 05:36:03 -0800 (PST) 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-482-ucZG3T3-NoCHlZ-VONQsBQ-1; Wed, 03 Feb 2021 08:35:06 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47933814318; Wed, 3 Feb 2021 13:35:01 +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 209C162680; Wed, 3 Feb 2021 13:35:01 +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 D4F3485CD; Wed, 3 Feb 2021 13:35:00 +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 113DYbhw014096 for ; Wed, 3 Feb 2021 08:34:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4F10D2CFCE; Wed, 3 Feb 2021 13:34:37 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6FC55C6B8 for ; Wed, 3 Feb 2021 13:34:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612359362; 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=f9nbjpEXs/iaNlvm1W9+m74L86ihk6k85xonA7rQ0AI=; b=BjTbUedZov3jfiuXoYBfHioX6UZlIMQgmqAMoNp1MLgDc47hfKUOppviYbSodb4cj2b0Lj nYiEu+ByAO8xIwo2frxj0BDiSvutdQPRVtZ2L0+DQtuAl9QDbaegPV3unI8lRbruj5itw6 5bYgkFWfbRUxm8a32fd51D43Adr1VNI= X-MC-Unique: ucZG3T3-NoCHlZ-VONQsBQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/6] virNetDevGetEthtoolGFeatures: Avoid use of VIR_ALLOC_VAR Date: Wed, 3 Feb 2021 14:34:25 +0100 Message-Id: <50aed380de268b8134a2479948342b3c9f95bb05.1612358891.git.pkrempa@redhat.com> 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.15 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In this case we need a 'struct ethtool_gfeatures' followed by two 'struct ethtool_get_features_block' so there's no risk of overflow. Use g_malloc0 and sizeof() to allocate the memory instead of VIR_ALLOC_VAR. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrang=C3=A9 --- src/util/virnetdev.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 1ef7cea20a..6ee59989ed 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -3300,9 +3300,8 @@ virNetDevGetEthtoolGFeatures(const char *ifname, { g_autofree struct ethtool_gfeatures *g_cmd =3D NULL; - if (VIR_ALLOC_VAR(g_cmd, - struct ethtool_get_features_block, GFEATURES_SIZE) <= 0) - return -1; + g_cmd =3D g_malloc0(sizeof(struct ethtool_gfeatures) + + sizeof(struct ethtool_get_features_block) * GFEATURE= S_SIZE); g_cmd->cmd =3D ETHTOOL_GFEATURES; g_cmd->size =3D GFEATURES_SIZE; --=20 2.29.2 From nobody Tue May 7 07:28:55 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=1612359364; cv=none; d=zohomail.com; s=zohoarc; b=MtotMAWMykDNV5InHBZfMoyKKPyqdERqLSSVYTugI/hqilsPdXlH801ZEgj/NptJaxYX8FZuIZPQ8WQu2efQb7Qkt6FuusoaXbf8mNiR7mhswzHW95hnuj0jAOdjRS/5bXZ9e5CMgWlqMB2R2yX2QFpJ4aovq6mNZujo9iNOUbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612359364; 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=amtt66U17rvp0b1li/9fv1BI9MCiGPvrUDLcLL+d6sk=; b=JuQ9DBEuowun/0NJrbyTpnX3RlTMq8FfeC4nq8OElF+z2mRcJI9DoPsu+FZcHcdiKomDoiDg7/qLIguevVVv26C+xlfYsNtRqrvf+n35F8VTi5YcgA/wvgCHKhHWGpPAFq+K8OGEg/vRKeGVibQGMTviR2Plu0KhDU5Zgx3A/Gs= 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 1612359364315789.9443821818878; Wed, 3 Feb 2021 05:36:04 -0800 (PST) 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-559-vXPAietCNEa7oKa39HtvUQ-1; Wed, 03 Feb 2021 08:35:10 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A468107ACF7; Wed, 3 Feb 2021 13:35:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 142D45D723; Wed, 3 Feb 2021 13:35:04 +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 CC43F18095CE; Wed, 3 Feb 2021 13:35:03 +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 113DYccf014101 for ; Wed, 3 Feb 2021 08:34:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6175B2CFCE; Wed, 3 Feb 2021 13:34:38 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2C205C6B8 for ; Wed, 3 Feb 2021 13:34:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612359363; 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=amtt66U17rvp0b1li/9fv1BI9MCiGPvrUDLcLL+d6sk=; b=FA+M+ETE6kzoeCOl9xLCFBgjwaj/k2dM2HTfJ9JKFGd8K4g9NY6YoFeIjXYId8fCARCrOi Ap6kKwXXyRzKeRt4XQlCKnYpZ9Xj8Hv8U0yX46DUYYGhLtUUeovd9Zs68Xk3/oCjOHzJa5 TIJmE3Vdk3/P+MWLYdE4RwnunHRNFeU= X-MC-Unique: vXPAietCNEa7oKa39HtvUQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 6/6] viralloc: Remove VIR_ALLOC_VAR Date: Wed, 3 Feb 2021 14:34:26 +0100 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.15 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The use case VIR_ALLOC_VAR deals with is very unlikely. We had just 2 legitimate uses, which were reimplemented locally using g_malloc0 and sizeof instead as they used a static number of members of the trailing array. Remove VIR_ALLOC_VAR since in most cases the direct implementation is shorter and clearer and there are no users of it currently. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrang=C3=A9 --- src/libvirt_private.syms | 1 - src/util/viralloc.c | 33 --------------------------------- src/util/viralloc.h | 35 ----------------------------------- 3 files changed, 69 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 30589c08ac..0636b0d8c9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1724,7 +1724,6 @@ vir_g_strdup_vprintf; # util/viralloc.h -virAllocVar; virDeleteElementsN; virExpandN; virInsertElementsN; diff --git a/src/util/viralloc.c b/src/util/viralloc.c index e4dc13b776..1317537c8a 100644 --- a/src/util/viralloc.c +++ b/src/util/viralloc.c @@ -260,36 +260,3 @@ virDeleteElementsN(void *ptrptr, size_t size, size_t a= t, virShrinkN(ptrptr, size, countptr, toremove); return 0; } - -/** - * virAllocVar: - * @ptrptr: pointer to hold address of allocated memory - * @struct_size: size of initial struct - * @element_size: size of array elements - * @count: number of array elements to allocate - * - * Allocate struct_size bytes plus an array of 'count' elements, each - * of size element_size. This sort of allocation is useful for - * receiving the data of certain ioctls and other APIs which return a - * struct in which the last element is an array of undefined length. - * The caller of this type of API is expected to know the length of - * the array that will be returned and allocate a suitable buffer to - * contain the returned data. C99 refers to these variable length - * objects as structs containing flexible array members. - * - * Returns -1 on failure, 0 on success - */ -int virAllocVar(void *ptrptr, - size_t struct_size, - size_t element_size, - size_t count) -{ - size_t alloc_size =3D 0; - - if (VIR_ALLOC_VAR_OVERSIZED(struct_size, count, element_size)) - abort(); - - alloc_size =3D struct_size + (element_size * count); - *(void **)ptrptr =3D g_malloc0(alloc_size); - return 0; -} diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 29e3224818..e3027622c4 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -49,8 +49,6 @@ int virInsertElementsN(void *ptrptr, size_t size, size_t = at, size_t *countptr, int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *count= ptr, size_t toremove, bool inPlace) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); -int virAllocVar(void *ptrptr, size_t struct_size, size_t element_size, siz= e_t count) - G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1); /** * VIR_REALLOC_N: @@ -292,39 +290,6 @@ int virAllocVar(void *ptrptr, size_t struct_size, size= _t element_size, size_t co #define VIR_DELETE_ELEMENT_INPLACE(ptr, at, count) \ virDeleteElementsN(&(ptr), sizeof(*(ptr)), at, &(count), 1, true) -/** - * VIR_ALLOC_VAR_OVERSIZED: - * @M: size of base structure - * @N: number of array elements in trailing array - * @S: size of trailing array elements - * - * Check to make sure that the requested allocation will not cause - * arithmetic overflow in the allocation size. - */ -#define VIR_ALLOC_VAR_OVERSIZED(M, N, S) ((((size_t)-1) - (M)) / (S) < (N)) - -/** - * VIR_ALLOC_VAR: - * @ptr: pointer to hold address of allocated memory - * @type: element type of trailing array - * @count: number of array elements to allocate - * - * Allocate sizeof(*ptr) bytes plus an array of 'count' elements, each - * sizeof('type'). This sort of allocation is useful for receiving - * the data of certain ioctls and other APIs which return a struct in - * which the last element is an array of undefined length. The caller - * of this type of API is expected to know the length of the array - * that will be returned and allocate a suitable buffer to contain the - * returned data. C99 refers to these variable length objects as - * structs containing flexible array members. - * - * This macro is safe to use on arguments with side effects. - * - * Returns 0 on success, aborts on OOM - */ -#define VIR_ALLOC_VAR(ptr, type, count) \ - virAllocVar(&(ptr), sizeof(*(ptr)), sizeof(type), (count)) - /** * VIR_FREE: * @ptr: pointer holding address to be freed --=20 2.29.2