From nobody Tue May 7 15:26:40 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=1635873070; cv=none; d=zohomail.com; s=zohoarc; b=NQ0cDFSM0Va58sSyz1nYmy6r227FlvxN1zbKYuf1l8HaC+2alzwhjRJ/5ujgX6cgd1fQzZMC6SKCnWS61fCeYoGD9obpOHupBZslYjMZGt0REa9pD4wXBQPsZufQqhiY8J8r8GyjbUcvbSl3R06qYtqt98x1bG/r1rDm3LreBA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635873070; 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=bhXlERxxTLcpdpDAbprSjSXleuPHdIxxV1fPBi1MU+o=; b=HMWazaut7dlUwUMjDmOAtCQ2FM0bVBy2eG9+T+j/3drQSAs6raxStufBqggmDcN/ql6OwlbbyffCHYyvL0wp53khGBu/VWNHQIPKCVl8beriATC97LAz3NJlB4bQmU5WQCp7kPhLDgvIT372P7x+2aE0RnTMV8vh0mW+MxvebyA= 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) 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 1635873070890606.2544873718568; Tue, 2 Nov 2021 10:11:10 -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-295-3zdDAC8HNuq7Q7Bo5a8rSg-1; Tue, 02 Nov 2021 13:11:06 -0400 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 0DDB610B7465; Tue, 2 Nov 2021 17:10:52 +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 02F0E5D6B1; Tue, 2 Nov 2021 17:10: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 96812180BAD1; Tue, 2 Nov 2021 17:10:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A2HAlhj009452 for ; Tue, 2 Nov 2021 13:10:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0934F7D492; Tue, 2 Nov 2021 17:10:47 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36F4B7E5C3 for ; Tue, 2 Nov 2021 17:10:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635873069; 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=bhXlERxxTLcpdpDAbprSjSXleuPHdIxxV1fPBi1MU+o=; b=ElMgLVBfFZflTXq68dvPwuDuDnLK9+yj4i0c+L2h6jXjdGUbHpM1bvQuRx4yzsnG4gE3p1 Cor6gJJdchRHK7nznDg9Jn56IEAO2yYPW2PvRRItOuSrP/sqAebXyZry76vpaFchHZe3Kg Wm7ZVB5U4A5J945aUwPUBmxaHBrGbnk= X-MC-Unique: 3zdDAC8HNuq7Q7Bo5a8rSg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/5] node_device_conf: Bring variables into loops Date: Tue, 2 Nov 2021 18:10:38 +0100 Message-Id: <1330d98604757e7de38d7a4626eb26345aed9656.1635872947.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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) X-ZM-MESSAGEID: 1635873073053100001 Content-Type: text/plain; charset="utf-8" I've noticed three functions inside node_device_conf.c, namely: - virNodeDeviceCapVPDParseCustomFields() - virNodeDeviceCapVPDParseReadOnlyFields() - virNodeDeviceCapVPDParseXML() that have strange attitude towards g_auto* variables. The first problem is that variables are declared at the top level despite being used inside a loop. The second problem is use of g_free() in combination with g_steal_pointer() even though we have VIR_FREE() which does exactly that. Bringing variable declarations into their respective loops allows us to make the code nicer. Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- src/conf/node_device_conf.c | 46 ++++++++++++++----------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index e958367572..ca534dfbed 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -940,19 +940,20 @@ static int virNodeDeviceCapVPDParseCustomFields(xmlXPathContextPtr ctxt, virPCIVPDRes= ource *res, bool readOnly) { int nfields =3D -1; - g_autofree char *index =3D NULL, *value =3D NULL, *keyword =3D NULL; g_autofree xmlNodePtr *nodes =3D NULL; - xmlNodePtr orignode =3D NULL; size_t i =3D 0; =20 - orignode =3D ctxt->node; if ((nfields =3D virXPathNodeSet("./vendor_field[@index]", ctxt, &node= s)) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("failed to evaluate elements")); - ctxt->node =3D orignode; return -1; } for (i =3D 0; i < nfields; i++) { + g_autofree char *value =3D NULL; + g_autofree char *index =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) + g_autofree char *keyword =3D NULL; + ctxt->node =3D nodes[i]; if (!(index =3D virXPathStringLimit("string(./@index[1])", 2, ctxt= ))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -966,21 +967,21 @@ virNodeDeviceCapVPDParseCustomFields(xmlXPathContextP= tr ctxt, virPCIVPDResource } keyword =3D g_strdup_printf("V%c", index[0]); virPCIVPDResourceUpdateKeyword(res, readOnly, keyword, value); - g_free(g_steal_pointer(&index)); - g_free(g_steal_pointer(&keyword)); - g_free(g_steal_pointer(&value)); } - g_free(g_steal_pointer(&nodes)); - ctxt->node =3D orignode; + VIR_FREE(nodes); =20 if (!readOnly) { if ((nfields =3D virXPathNodeSet("./system_field[@index]", ctxt, &= nodes)) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("failed to evaluate elements")); - ctxt->node =3D orignode; return -1; } for (i =3D 0; i < nfields; i++) { + g_autofree char *value =3D NULL; + g_autofree char *index =3D NULL; + g_autofree char *keyword =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt); + ctxt->node =3D nodes[i]; if (!(index =3D virXPathStringLimit("string(./@index[1])", 2, = ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -994,11 +995,7 @@ virNodeDeviceCapVPDParseCustomFields(xmlXPathContextPt= r ctxt, virPCIVPDResource } keyword =3D g_strdup_printf("Y%c", index[0]); virPCIVPDResourceUpdateKeyword(res, readOnly, keyword, value); - g_free(g_steal_pointer(&index)); - g_free(g_steal_pointer(&keyword)); - g_free(g_steal_pointer(&value)); } - ctxt->node =3D orignode; } =20 return 0; @@ -1009,8 +1006,6 @@ virNodeDeviceCapVPDParseReadOnlyFields(xmlXPathContex= tPtr ctxt, virPCIVPDResourc { const char *keywords[] =3D {"change_level", "manufacture_id", "serial_number", "part_number", NULL}; - g_autofree char *expression =3D NULL; - g_autofree char *result =3D NULL; size_t i =3D 0; =20 if (res =3D=3D NULL) @@ -1019,11 +1014,10 @@ virNodeDeviceCapVPDParseReadOnlyFields(xmlXPathCont= extPtr ctxt, virPCIVPDResourc res->ro =3D virPCIVPDResourceRONew(); =20 while (keywords[i]) { - expression =3D g_strdup_printf("string(./%s)", keywords[i]); - result =3D virXPathString(expression, ctxt); + g_autofree char *expression =3D g_strdup_printf("string(./%s)", ke= ywords[i]); + g_autofree char *result =3D virXPathString(expression, ctxt); + virPCIVPDResourceUpdateKeyword(res, true, keywords[i], result); - g_free(g_steal_pointer(&expression)); - g_free(g_steal_pointer(&result)); ++i; } if (virNodeDeviceCapVPDParseCustomFields(ctxt, res, true) < 0) @@ -1047,38 +1041,34 @@ virNodeDeviceCapVPDParseReadWriteFields(xmlXPathCon= textPtr ctxt, virPCIVPDResour static int virNodeDeviceCapVPDParseXML(xmlXPathContextPtr ctxt, virPCIVPDResource **r= es) { - xmlNodePtr orignode =3D NULL; g_autofree xmlNodePtr *nodes =3D NULL; int nfields =3D -1; - g_autofree char *access =3D NULL; size_t i =3D 0; g_autoptr(virPCIVPDResource) newres =3D g_new0(virPCIVPDResource, 1); =20 if (res =3D=3D NULL) return -1; =20 - orignode =3D ctxt->node; - if (!(newres->name =3D virXPathString("string(./name)", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Could not read a device name from the element")); - ctxt->node =3D orignode; return -1; } =20 if ((nfields =3D virXPathNodeSet("./fields[@access]", ctxt, &nodes)) <= 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("no VPD elements with an access type attribute = found")); - ctxt->node =3D orignode; return -1; } =20 for (i =3D 0; i < nfields; i++) { + g_autofree char *access =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt); + ctxt->node =3D nodes[i]; if (!(access =3D virXPathString("string(./@access[1])", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("VPD fields access type parsing has failed")); - ctxt->node =3D orignode; return -1; } =20 @@ -1099,9 +1089,7 @@ virNodeDeviceCapVPDParseXML(xmlXPathContextPtr ctxt, = virPCIVPDResource **res) access); return -1; } - g_free(g_steal_pointer(&access)); } - ctxt->node =3D orignode; =20 /* Replace the existing VPD representation if there is one already. */ if (*res !=3D NULL) --=20 2.32.0 From nobody Tue May 7 15:26:40 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=1635873075; cv=none; d=zohomail.com; s=zohoarc; b=kNZpDi9JrJ4CHaTltjk+xqlRIsOPry6xh/NwDMie5wHCzveibckI3WVsnEcAj2HmTSHgGZ/RvWpWh7dqjiiIc2BXiOsYfQC47y3bxSHeG8q70quIlsGh4D8KGcooMVn2edfU9HEcwKf/I8ZnGn4Sn3xQDhFODSGMyqs8M0hEF+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635873075; 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=AHZ7XXAWcS2E8TZobZBNux8yD4VtBIJC90QUVTP8M9w=; b=mGbepqCR4N8Nf7jH2YiWRZ7Q8/1KR0KK2Gx0Hk2dTp4lQ306JuqyriMPiaq6CWn7CvXYzDR1AHfsHN77pxfp8MMC+FUacvnedkdA2o44DxzozDW4OOosENwIoT1izJ6qQ3mG0/gtmkdN4Ytq5o7JdB7SZsAFe/A1Nfodj1tfbIs= 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) 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 1635873075101335.6606291364974; Tue, 2 Nov 2021 10:11:15 -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-443-CRjZ8FN-OkqNsetkOFRqUg-1; Tue, 02 Nov 2021 13:11:12 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 547721006AA2; Tue, 2 Nov 2021 17:11:00 +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 39FBB101E591; Tue, 2 Nov 2021 17:11:00 +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 0B2B7180BAD1; Tue, 2 Nov 2021 17:11:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A2HAlKO009459 for ; Tue, 2 Nov 2021 13:10:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id CFEF67D552; Tue, 2 Nov 2021 17:10:47 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 202AE7DDCE for ; Tue, 2 Nov 2021 17:10:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635873074; 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=AHZ7XXAWcS2E8TZobZBNux8yD4VtBIJC90QUVTP8M9w=; b=Jl6MuJBTgCQXU2pFaCu8dE91g7CEBthHrnpz0Fb3nZNv9vFfz86kMPz9tXAOAea/NPS7yv iywho/FLkd0bciGcvNMDpCt+rwtytBvESc6l+XefQQK+3uiOIwJecSish4wUjeIJX/bsGa nH4lsYgWnPBg/38G7rffJ5oc/t7IV/s= X-MC-Unique: CRjZ8FN-OkqNsetkOFRqUg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/5] virpcivpd: Bring variables into loops Date: Tue, 2 Nov 2021 18:10:39 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.84 on 10.5.11.22 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) X-ZM-MESSAGEID: 1635873978042100001 Content-Type: text/plain; charset="utf-8" I've noticed one function inside virpcivpd.c, namely virPCIVPDParseVPDLargeResourceFields() that declares some variables at the top level even though they are used only inside a loop in which they have to be freed explicitly. Bringing variable declarations into the loop allows us to make the code nicer. Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- src/util/virpcivpd.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index d8f2a43cde..9af0566d19 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -456,10 +456,6 @@ bool virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uint16_t resPos, uint1= 6_t resDataLen, bool readOnly, uint8_t *csum, virPCIV= PDResource *res) { - g_autofree char *fieldKeyword =3D NULL; - g_autofree char *fieldValue =3D NULL; - virPCIVPDResourceFieldValueFormat fieldFormat =3D VIR_PCI_VPD_RESOURCE= _FIELD_VALUE_FORMAT_LAST; - /* A buffer of up to one resource record field size (plus a zero byte)= is needed. */ g_autofree uint8_t *buf =3D g_malloc0(PCI_VPD_MAX_FIELD_SIZE + 1); uint16_t fieldDataLen =3D 0, bytesToRead =3D 0; @@ -473,6 +469,10 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, ui= nt16_t resPos, uint16_t re * just occupy 3 header bytes. In the in case of the RW field this may= mean that * no more space is left in the section. */ while (fieldPos + 3 <=3D resPos + resDataLen) { + virPCIVPDResourceFieldValueFormat fieldFormat =3D VIR_PCI_VPD_RESO= URCE_FIELD_VALUE_FORMAT_LAST; + g_autofree char *fieldKeyword =3D NULL; + g_autofree char *fieldValue =3D NULL; + /* Keyword resources consist of keywords (2 ASCII bytes per the sp= ec) and 1-byte length. */ if (virPCIVPDReadVPDBytes(vpdFileFd, buf, 3, fieldPos, csum) !=3D = 3) { /* Invalid field encountered which means the resource itself i= s invalid too. Report @@ -548,8 +548,6 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uin= t16_t resPos, uint16_t re /* Skip fields with invalid values - this is safe assuming= field length is * correctly specified. */ VIR_DEBUG("A value for field %s contains invalid character= s", fieldKeyword); - g_free(g_steal_pointer(&fieldKeyword)); - g_free(g_steal_pointer(&fieldValue)); continue; } } else if (fieldFormat =3D=3D VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FOR= MAT_RESVD) { @@ -559,19 +557,13 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, u= int16_t resPos, uint16_t re return false; } hasChecksum =3D true; - g_free(g_steal_pointer(&fieldKeyword)); - g_free(g_steal_pointer(&fieldValue)); break; } else if (fieldFormat =3D=3D VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FOR= MAT_RDWR) { /* Skip the read-write space since it is used for indication o= nly. */ hasRW =3D true; - g_free(g_steal_pointer(&fieldKeyword)); - g_free(g_steal_pointer(&fieldValue)); break; } else if (fieldFormat =3D=3D VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FOR= MAT_LAST) { /* Skip unknown fields */ - g_free(g_steal_pointer(&fieldKeyword)); - g_free(g_steal_pointer(&fieldValue)); continue; } else { fieldValue =3D g_malloc(fieldDataLen); @@ -591,9 +583,6 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uin= t16_t resPos, uint16_t re _("Could not update the VPD resource keyword: %= s"), fieldKeyword); return false; } - /* No longer need those since copies were made during the keyword = update. */ - g_free(g_steal_pointer(&fieldKeyword)); - g_free(g_steal_pointer(&fieldValue)); } =20 /* May have exited the loop prematurely in case RV or RW were encounte= red and --=20 2.32.0 From nobody Tue May 7 15:26:40 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=1635873069; cv=none; d=zohomail.com; s=zohoarc; b=NgP+//8p8UFlVYBTDfHbiHNYxYY+5gjM/pTv5Z2WWwP39qtdz6f5TKGl4shIxCV64wL3X0pVCXLWTVjR9ulm4NIEoKm7+ntqIHsa9oCCt71zKpZUbtXtVWpBzq7kyThCmyoltt1kg6W0xPmoQtAul50BQd03xmRdizHgtLAEXWA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635873069; 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=KvTWPAT+s5pWADU0KSCaodIQywCz59OYM2tptx0sbBY=; b=BeSCUUzv9qSWGDeKRc4w8er8CdJz06iGDqWT7Px8O772o7l6++0pnjF1dHc0ifUubC/yD4+FctsJ2w8tvHKuBIcss2bV0frtcdQNCJY0NCRK11fWxVFjVs9MUG+MtmJMiVf5fVpTWQJKKPRTLvuHUuS9uyxRPeAdjRpUTq3m7mc= 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) 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 1635873069149997.1557105831073; Tue, 2 Nov 2021 10:11:09 -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-403-g87iDCO6MwGDPlc4RBSh3A-1; Tue, 02 Nov 2021 13:11:06 -0400 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 CF1891922049; Tue, 2 Nov 2021 17:10: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 9728960BE5; Tue, 2 Nov 2021 17:10: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 04A194A703; Tue, 2 Nov 2021 17:10:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A2HAmPv009470 for ; Tue, 2 Nov 2021 13:10:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 741761969D; Tue, 2 Nov 2021 17:10:48 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7BFC19219 for ; Tue, 2 Nov 2021 17:10:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635873068; 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=KvTWPAT+s5pWADU0KSCaodIQywCz59OYM2tptx0sbBY=; b=Yolh5oaf5k4TMOMwWLmZQJAV6ZhdR6UYSE0TxCa/3MjUTuCYfmowcOZIRq5wiYAZJvFRuI xCtozm8l76lxaiCpigUopRq+nVMlvW9xPBtHjv4nL4uJRR0yGrj3oO/52E9uASIm5PfxiK grcuduImcjoWCnjvKX6gWStsUzkTks4= X-MC-Unique: g87iDCO6MwGDPlc4RBSh3A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/5] virpcivpdtest: Declare variables at multiple lines Date: Tue, 2 Nov 2021 18:10:40 +0100 Message-Id: <3c418f9acaa012e9894a815b5fa813d937a427a7.1635872947.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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) X-ZM-MESSAGEID: 1635873070719100001 Content-Type: text/plain; charset="utf-8" In testPCIVPDResourceCustomCompareIndex() there are two variables declared at one line. They are both g_autoptr() decorated which makes it worse, because coccinelle fails to parse that. Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- tests/virpcivpdtest.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index a9405f9427..add1c74c04 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -178,7 +178,8 @@ testPCIVPDResourceBasic(const void *data G_GNUC_UNUSED) static int testPCIVPDResourceCustomCompareIndex(const void *data G_GNUC_UNUSED) { - g_autoptr(virPCIVPDResourceCustom) a =3D NULL, b =3D NULL; + g_autoptr(virPCIVPDResourceCustom) a =3D NULL; + g_autoptr(virPCIVPDResourceCustom) b =3D NULL; =20 /* Both are NULL */ if (!virPCIVPDResourceCustomCompareIndex(a, b)) --=20 2.32.0 From nobody Tue May 7 15:26:40 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=1635873074; cv=none; d=zohomail.com; s=zohoarc; b=asL4AYPdbgbTSl0m+97hL1xRt1DB5EBJ+egXhK5aLLDYW0kPgvxj+KuorUqocevckJ11JYWPrOERgCC6IU7+Svqost22JeILPg04g6D6FA8iZch5RJiO5a+BTNQAKFPmBnC5cEY0u83LSPVd/6dUao2tdfssb/Xo457t21sumIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635873074; 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=YT7kRcVqpTEHRYxi7kJI0gbkdxMEHN86bl9BZ8jm2bQ=; b=Hwl30Vk++SK89qfE7NxKFb8bd17ocFXQK2sKCLVEB/K1+y4TPwEDAYp8BCxj7jJecSoF94EXpVI+Kg+YHJkMVusoJQjoRPajO9ktqKle3rfObmQQHviXFUbr9x/oTTtHYbZWX8yVZtuHXGS6OGJ8rzJdMWOunKnegg36q7/PgTA= 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) 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 1635873074660742.1643374396078; Tue, 2 Nov 2021 10:11:14 -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-367-QvM-kgE-O6GYt3beRPAklQ-1; Tue, 02 Nov 2021 13:11:11 -0400 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 8524ADF8CB; Tue, 2 Nov 2021 17:11:00 +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 64A4F60C17; Tue, 2 Nov 2021 17:11:00 +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 347504E58E; Tue, 2 Nov 2021 17:11:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A2HAnUc009475 for ; Tue, 2 Nov 2021 13:10:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4BBBF610A5; Tue, 2 Nov 2021 17:10:49 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3E1A19082 for ; Tue, 2 Nov 2021 17:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635873073; 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=YT7kRcVqpTEHRYxi7kJI0gbkdxMEHN86bl9BZ8jm2bQ=; b=L4B3GaVogrLMjfyHqsq1UchXCKAMZdD/wHnaBRC4+xhRy8obDrwIp5VbrwuleQ31JsBDHa uopWu4vAQg3eN9nRE8yZywoRC/wyttWwzfhr2iEyLCB/xlD83XOEDHWU0e0i32BpFdeKqr zNZmqwT+wYsIWe0IdQibStoqMQAoXKs= X-MC-Unique: QvM-kgE-O6GYt3beRPAklQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/5] lib: Use G_N_ELEMENTS instead of sizeof()/sizeof() Date: Tue, 2 Nov 2021 18:10:41 +0100 Message-Id: <867772e8eff290047fb97f2c89de57e9854680d5.1635872947.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635873075508100001 For statically declared arrays one can use G_N_ELEMENTS() instead of explicit sizeof(array) / sizeof(item). I've noticed couple of places where the latter was used. I am not fixing every occurrence because we have some places which do not use glib (examples and NSS module). Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- src/libxl/libxl_capabilities.c | 2 +- tests/virpcimock.c | 2 +- tests/virpcivpdtest.c | 26 +++++++++++++------------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index e03b6fd3c3..6263b5c8b5 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -380,7 +380,7 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCaps *caps) * we "own" the buffer. Parse out the features from each token. */ for (str =3D ver_info->capabilities, nr_guest_archs =3D 0; - nr_guest_archs < sizeof(guest_archs) / sizeof(guest_archs[0]) + nr_guest_archs < G_N_ELEMENTS(guest_archs) && (token =3D strtok_r(str, " ", &saveptr)) !=3D NULL; str =3D NULL) { if (g_regex_match(regex, token, 0, &info)) { diff --git a/tests/virpcimock.c b/tests/virpcimock.c index f65ae7c0c5..77d46f0952 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -965,7 +965,7 @@ init_env(void) }; struct pciVPD exampleVPD =3D { .data =3D fullVPDExampleData, - .vpd_len =3D sizeof(fullVPDExampleData) / sizeof(fullVPDExampleDat= a[0]), + .vpd_len =3D G_N_ELEMENTS(fullVPDExampleData), }; =20 if (!(fakerootdir =3D getenv("LIBVIRT_FAKE_ROOT_DIR"))) diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index add1c74c04..284350fe29 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -76,9 +76,9 @@ testPCIVPDResourceBasic(const void *data G_GNUC_UNUSED) {.keyword =3D "CP", .value =3D "42", .actual =3D NULL}, {.keyword =3D "EX", .value =3D "42", .actual =3D NULL}, }; - size_t numROCases =3D sizeof(readOnlyCases) / sizeof(TestPCIVPDKeyword= Value); - size_t numRWCases =3D sizeof(readWriteCases) / sizeof(TestPCIVPDKeywor= dValue); - size_t numUnsupportedCases =3D sizeof(unsupportedFieldCases) / sizeof(= TestPCIVPDKeywordValue); + size_t numROCases =3D G_N_ELEMENTS(readOnlyCases); + size_t numRWCases =3D G_N_ELEMENTS(readWriteCases); + size_t numUnsupportedCases =3D G_N_ELEMENTS(unsupportedFieldCases); g_autoptr(virPCIVPDResource) res =3D g_new0(virPCIVPDResource, 1); virPCIVPDResourceCustom *custom =3D NULL; =20 @@ -328,7 +328,7 @@ testPCIVPDIsValidTextValue(const void *data G_GNUC_UNUS= ED) /* The first and last code points are outside ASCII (multi-byte in= UTF-8). */ {"=D0=B3bl=F0=9F=90=A7", false}, }; - for (i =3D 0; i < sizeof(textValueCases) / sizeof(textValueCases[0]); = ++i) { + for (i =3D 0; i < G_N_ELEMENTS(textValueCases); ++i) { if (virPCIVPDResourceIsValidTextValue(textValueCases[i].keyword) != =3D textValueCases[i].expected) return -1; @@ -385,7 +385,7 @@ testPCIVPDGetFieldValueFormat(const void *data G_GNUC_U= NUSED) /* Many letters. */ {"EXAMPLE", VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_LAST}, }; - for (i =3D 0; i < sizeof(valueFormatCases) / sizeof(valueFormatCases[0= ]); ++i) { + for (i =3D 0; i < G_N_ELEMENTS(valueFormatCases); ++i) { if (virPCIVPDResourceGetFieldValueFormat(valueFormatCases[i].keywo= rd) !=3D valueFormatCases[i].expected) return -1; @@ -442,7 +442,7 @@ testVirPCIVPDReadVPDBytes(const void *opaque G_GNUC_UNU= SED) VPD_R_FIELDS_EXAMPLE_HEADER, VPD_R_FIELDS_EXAMPLE_DATA, PCI_VPD_RESOURCE_END_VAL }; - dataLen =3D sizeof(fullVPDExample) / sizeof(uint8_t) - 2; + dataLen =3D G_N_ELEMENTS(fullVPDExample) - 2; buf =3D g_malloc0(dataLen); =20 fd =3D virCreateAnonymousFile(fullVPDExample, dataLen); @@ -480,7 +480,7 @@ testVirPCIVPDParseVPDStringResource(const void *opaque = G_GNUC_UNUSED) VPD_STRING_RESOURCE_EXAMPLE_DATA }; =20 - dataLen =3D sizeof(stringResExample) / sizeof(uint8_t); + dataLen =3D G_N_ELEMENTS(stringResExample); fd =3D virCreateAnonymousFile(stringResExample, dataLen); result =3D virPCIVPDParseVPDLargeResourceString(fd, 0, dataLen, &csum,= res); VIR_FORCE_CLOSE(fd); @@ -550,7 +550,7 @@ testVirPCIVPDParseFullVPD(const void *opaque G_GNUC_UNU= SED) PCI_VPD_RESOURCE_END_VAL }; =20 - dataLen =3D sizeof(fullVPDExample) / sizeof(uint8_t); + dataLen =3D G_N_ELEMENTS(fullVPDExample); fd =3D virCreateAnonymousFile(fullVPDExample, dataLen); res =3D virPCIVPDParse(fd); VIR_FORCE_CLOSE(fd); @@ -618,7 +618,7 @@ testVirPCIVPDParseZeroLengthRW(const void *opaque G_GNU= C_UNUSED) PCI_VPD_RESOURCE_END_VAL }; =20 - dataLen =3D sizeof(fullVPDExample) / sizeof(uint8_t); + dataLen =3D G_N_ELEMENTS(fullVPDExample); fd =3D virCreateAnonymousFile(fullVPDExample, dataLen); res =3D virPCIVPDParse(fd); VIR_FORCE_CLOSE(fd); @@ -668,7 +668,7 @@ testVirPCIVPDParseNoRW(const void *opaque G_GNUC_UNUSED) PCI_VPD_RESOURCE_END_VAL }; =20 - dataLen =3D sizeof(fullVPDExample) / sizeof(uint8_t); + dataLen =3D G_N_ELEMENTS(fullVPDExample); fd =3D virCreateAnonymousFile(fullVPDExample, dataLen); res =3D virPCIVPDParse(fd); VIR_FORCE_CLOSE(fd); @@ -721,7 +721,7 @@ testVirPCIVPDParseFullVPDSkipInvalidKeywords(const void= *opaque G_GNUC_UNUSED) PCI_VPD_RESOURCE_END_VAL }; =20 - dataLen =3D sizeof(fullVPDExample) / sizeof(uint8_t); + dataLen =3D G_N_ELEMENTS(fullVPDExample); fd =3D virCreateAnonymousFile(fullVPDExample, dataLen); res =3D virPCIVPDParse(fd); VIR_FORCE_CLOSE(fd); @@ -774,7 +774,7 @@ testVirPCIVPDParseFullVPDSkipInvalidValues(const void *= opaque G_GNUC_UNUSED) 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 'R', '= W', 0x00, 0x78, }; =20 - dataLen =3D sizeof(fullVPDExample) / sizeof(uint8_t); + dataLen =3D G_N_ELEMENTS(fullVPDExample); fd =3D virCreateAnonymousFile(fullVPDExample, dataLen); res =3D virPCIVPDParse(fd); VIR_FORCE_CLOSE(fd); @@ -950,7 +950,7 @@ testVirPCIVPDParseFullVPDInvalid(const void *opaque G_G= NUC_UNUSED) do { \ g_autoptr(virPCIVPDResource) res =3D NULL; \ const uint8_t testCase[] =3D { invalidVPD }; \ - dataLen =3D sizeof(testCase) / sizeof(uint8_t); \ + dataLen =3D G_N_ELEMENTS(testCase); \ fd =3D virCreateAnonymousFile(testCase, dataLen); \ if ((res =3D virPCIVPDParse(fd))) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \ --=20 2.32.0 From nobody Tue May 7 15:26:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1635873080; cv=none; d=zohomail.com; s=zohoarc; b=D/An9vyccRIlp8ZZvBuM1UCvTxQFgoqyOGtrDSguABfXRerLYeJ/SVaFyUuSwJnnhlNc6wq8PE19VxPk7B8pO64UJhWPJKbOQIb7IETpBXllERHreHmVIg/yks7TgSPsgimmMzza5ZStsJDx0jshxZ58blfyVcqAP2BYPTdSITw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635873080; 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=O5FNXFAKHso0lZqZdnsB7P1djNiFJ4fYszMJXToolTk=; b=WGfX/I0p/KI9OPeWm2AmCPIUL+t8ZSKaGmRr7kctPJVVp6LgI0MSdnodOROisj6+4pG2tNYGxuYliwFhaVMFnM1J+34XOgEzjcLTmIQ4CneN43bM75irLqZAhDlvdKzY8tRgjgdW0kHQexmeupx76OdFI3T2TaUEFOac9PoSUyk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1635873080854506.5158480147195; Tue, 2 Nov 2021 10:11:20 -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-192-tGju4jktPmyi6qOzgzKybQ-1; Tue, 02 Nov 2021 13:11:17 -0400 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 8B161814267; Tue, 2 Nov 2021 17:11:03 +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 3830A60C05; Tue, 2 Nov 2021 17:11:03 +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 E084D4E590; Tue, 2 Nov 2021 17:11:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A2HAoSs009480 for ; Tue, 2 Nov 2021 13:10:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1AEDB60C05; Tue, 2 Nov 2021 17:10:50 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9888C61077 for ; Tue, 2 Nov 2021 17:10:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635873079; 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=O5FNXFAKHso0lZqZdnsB7P1djNiFJ4fYszMJXToolTk=; b=W25WBe+U4hFGp7G5CGJiQuR15jNhf3/+veqNHi/WH0/b5ebXJhPEyV1wHalhEFqtcrEl9S 5/DJe3pi3+mYSQo+2NpL0oE/7B11M1DnShz5IRdwx6Nfl7nWx3gGY3xhb8HzMbRyBM8XXo e/CUXwhMR4jRtqK6ZRfBP7BIV1XUGZ0= X-MC-Unique: tGju4jktPmyi6qOzgzKybQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/5] scripts: Properly declare g_auto() stub for cocci Date: Tue, 2 Nov 2021 18:10:42 +0100 Message-Id: <7b10a217ec882731cf5439035f8366de66908b80.1635872947.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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) X-ZM-MESSAGEID: 1635873082241100001 Content-Type: text/plain; charset="utf-8" While being great semantic patching tool, coccinelle fails to understand some of macros we use (including those provided by glib). What they have in common is use of __attribute__ under the hood. We store a list of such macros in a file. But in there, g_auto() macro is not defined properly. Indeed, g_auto(type) declares a local variable of given type, for instance from cocci's POV: g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; virBuffer buf =3D VIR_BUFFER_INITIALIZER; are both the same declaration. Fix declaration of g_auto() stub. Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- scripts/cocci-macro-file.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cocci-macro-file.h b/scripts/cocci-macro-file.h index a76ba533b4..4e6d218a97 100644 --- a/scripts/cocci-macro-file.h +++ b/scripts/cocci-macro-file.h @@ -34,6 +34,6 @@ =20 #define g_autoptr(x) x##_autoptr #define g_autofree -#define g_auto +#define g_auto(x) x =20 #define BAD_CAST --=20 2.32.0