From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706634735351144.06023025599768; Tue, 30 Jan 2024 09:12:15 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 34B7D1DB2; Tue, 30 Jan 2024 12:12:14 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 0D1561CBF; Tue, 30 Jan 2024 12:08:23 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 810F61C15; Tue, 30 Jan 2024 12:08:15 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0CB721C07 for ; Tue, 30 Jan 2024 12:08:15 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-_sBA69CZN3aoShjvSAeqiQ-1; Tue, 30 Jan 2024 12:08:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8B4761C05157 for ; Tue, 30 Jan 2024 17:08:12 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0566B2166B31 for ; Tue, 30 Jan 2024 17:08:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: _sBA69CZN3aoShjvSAeqiQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 01/31] virPCIVPDResourceIsValidTextValue: Adjust comment to reflect actual code Date: Tue, 30 Jan 2024 18:07:39 +0100 Message-ID: <32b1198b7ff7ec659fedae74032f5cdc68444190.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: Z6LR4BHHLIGCUFTCS72T6U56NTNFXFWN X-Message-ID-Hash: Z6LR4BHHLIGCUFTCS72T6U56NTNFXFWN X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706634740826100001 The function does not reject '&', '<', '>' contrary to what it actually states. Move and adjust the comment. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 39557c7347..248a9b2790 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -167,19 +167,15 @@ virPCIVPDResourceGetFieldValueFormat(const char *keyw= ord) * value or text field value. The expectations are based on the keywords s= pecified * in relevant sections of PCI(e) specifications * ("I.3. VPD Definitions" in PCI specs, "6.28.1 VPD Format" PCIe 4.0). + * + * The PCI(e) specs mention alphanumeric characters when talking about tex= t fields + * and the string resource but also include spaces and dashes in the provi= ded example. + * Dots, commas, equal signs have also been observed in values used by maj= or device vendors. */ bool virPCIVPDResourceIsValidTextValue(const char *value) { size_t i =3D 0; - /* - * The PCI(e) specs mention alphanumeric characters when talking about= text fields - * and the string resource but also include spaces and dashes in the p= rovided example. - * Dots, commas, equal signs have also been observed in values used by= major device vendors. - * The specs do not specify a full set of allowed code points and for = Libvirt it is important - * to keep values in the ranges allowed within XML elements (mainly ex= cluding less-than, - * greater-than and ampersand). - */ if (value =3D=3D NULL) return false; --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706634833399882.9842485826842; Tue, 30 Jan 2024 09:13:53 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4894E1CD9; Tue, 30 Jan 2024 12:13:52 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BC6AF1D1E; Tue, 30 Jan 2024 12:08:32 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 940831C10; Tue, 30 Jan 2024 12:08:16 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id D10FD1C03 for ; Tue, 30 Jan 2024 12:08:15 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-611-0Znj9hqMMP6xjAVKh19zmA-1; Tue, 30 Jan 2024 12:08:13 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 74DF5800074 for ; Tue, 30 Jan 2024 17:08:13 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0E3A2166B31 for ; Tue, 30 Jan 2024 17:08:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: 0Znj9hqMMP6xjAVKh19zmA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 02/31] util: pcivpd: Refactor virPCIVPDResourceIsValidTextValue Date: Tue, 30 Jan 2024 18:07:40 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: RYOYT3HCSQOR4RZ76GWQHSE7LSKTCOHV X-Message-ID-Hash: RYOYT3HCSQOR4RZ76GWQHSE7LSKTCOHV X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706634835138100001 The function is never called with NULL argument. Remove the check and refactor the rest including the debug statement. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 248a9b2790..81c7c317b3 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -175,23 +175,18 @@ virPCIVPDResourceGetFieldValueFormat(const char *keyw= ord) bool virPCIVPDResourceIsValidTextValue(const char *value) { - size_t i =3D 0; + const char *v; + bool ret =3D true; - if (value =3D=3D NULL) - return false; - - /* An empty string is a valid value. */ - if (STREQ(value, "")) - return true; - - while (i < strlen(value)) { - if (!g_ascii_isprint(value[i])) { - VIR_DEBUG("The provided value contains non-ASCII printable cha= racters: %s", value); - return false; + for (v =3D value; *v; v++) { + if (!g_ascii_isprint(*v)) { + ret =3D false; + break; } - ++i; } - return true; + + VIR_DEBUG("val=3D'%s' ret=3D'%d'", value, ret); + return ret; } void --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706634925671477.3880914905659; Tue, 30 Jan 2024 09:15:25 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8973A1DB6; Tue, 30 Jan 2024 12:15:24 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id B59F91C6B; Tue, 30 Jan 2024 12:08:40 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0C9CD1C75; Tue, 30 Jan 2024 12:08:20 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A8E741C07 for ; Tue, 30 Jan 2024 12:08:17 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-176-aVVadNvuM2iKXHebqLAWGg-1; Tue, 30 Jan 2024 12:08:14 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5C06C835389 for ; Tue, 30 Jan 2024 17:08:14 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6EE32166B31 for ; Tue, 30 Jan 2024 17:08:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: aVVadNvuM2iKXHebqLAWGg-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 03/31] virNodeDeviceCapVPDFormatCustom*: Escape unsanitized strings Date: Tue, 30 Jan 2024 18:07:41 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: Z72PNRL2R6DTFUFZWOREHJ3KGII63HOC X-Message-ID-Hash: Z72PNRL2R6DTFUFZWOREHJ3KGII63HOC X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706634927635100001 The custom field data is taken from PCI device data which can contain any printable characters, and thus must be escaped when putting into XML. Originally, based on the comment and XML schema which was fixed in previous commits the idea seemed to be that the parser would validate that only characters which don't break the XML would be present but that didn't seem to materialize. Switch to proper escaping of the XML. Fixes: 3954378d06a Resolves: https://issues.redhat.com/browse/RHEL-22314 Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/node_device_conf.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 4826be6f42..87c046e571 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -242,23 +242,32 @@ virNodeDeviceCapMdevTypesFormat(virBuffer *buf, } static void -virNodeDeviceCapVPDFormatCustomVendorField(virPCIVPDResourceCustom *field,= virBuffer *buf) +virNodeDeviceCapVPDFormatCustomField(virBuffer *buf, + const char *fieldtype, + virPCIVPDResourceCustom *field) { + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) content =3D VIR_BUFFER_INITIALIZER; + if (field =3D=3D NULL || field->value =3D=3D NULL) return; - virBufferAsprintf(buf, "%s\n= ", field->idx, - field->value); + virBufferAsprintf(&attrBuf, " index=3D'%c'", field->idx); + virBufferEscapeString(&content, "%s", field->value); + + virXMLFormatElementInternal(buf, fieldtype, &attrBuf, &content, false,= false); } static void -virNodeDeviceCapVPDFormatCustomSystemField(virPCIVPDResourceCustom *field,= virBuffer *buf) +virNodeDeviceCapVPDFormatCustomVendorField(virPCIVPDResourceCustom *field,= virBuffer *buf) { - if (field =3D=3D NULL || field->value =3D=3D NULL) - return; + virNodeDeviceCapVPDFormatCustomField(buf, "vendor_field", field); +} - virBufferAsprintf(buf, "%s\n= ", field->idx, - field->value); +static void +virNodeDeviceCapVPDFormatCustomSystemField(virPCIVPDResourceCustom *field,= virBuffer *buf) +{ + virNodeDeviceCapVPDFormatCustomField(buf, "system_field", field); } static inline void --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706635024368442.2331650989196; Tue, 30 Jan 2024 09:17:04 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4C8A11E3E; Tue, 30 Jan 2024 12:17:03 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id CE8DE1D40; Tue, 30 Jan 2024 12:08:49 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 970161C8B; Tue, 30 Jan 2024 12:08:20 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id E0B2C1C15 for ; Tue, 30 Jan 2024 12:08:17 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-602-e35GcvaWOQmEMrEXr92kBg-1; Tue, 30 Jan 2024 12:08:15 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4593D83538D for ; Tue, 30 Jan 2024 17:08:15 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id B12DD2166B31 for ; Tue, 30 Jan 2024 17:08:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: e35GcvaWOQmEMrEXr92kBg-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 04/31] virNodeDeviceCapVPDFormat: Properly escape system-originated strings Date: Tue, 30 Jan 2024 18:07:42 +0100 Message-ID: <4959274c5abcc0c955b14505e46bbc7ceeb71ff5.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: HYIGOADWII2CCIS5I2Z2DWBT4764GH7Q X-Message-ID-Hash: HYIGOADWII2CCIS5I2Z2DWBT4764GH7Q X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706635025964100001 Similarly to previous commit other specific fields which come from the system data and aren't sanitized enough to be safe for XML were also formatted via virBufferAsprintf. Other static and safe strings used virBufferEscapeString instead of virBufferAddLit. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/node_device_conf.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 87c046e571..95de77abe9 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -270,14 +270,6 @@ virNodeDeviceCapVPDFormatCustomSystemField(virPCIVPDRe= sourceCustom *field, virBu virNodeDeviceCapVPDFormatCustomField(buf, "system_field", field); } -static inline void -virNodeDeviceCapVPDFormatRegularField(virBuffer *buf, const char *keyword,= const char *value) -{ - if (keyword =3D=3D NULL || value =3D=3D NULL) - return; - - virBufferAsprintf(buf, "<%s>%s\n", keyword, value, keyword); -} static void virNodeDeviceCapVPDFormat(virBuffer *buf, virPCIVPDResource *res) @@ -290,31 +282,33 @@ virNodeDeviceCapVPDFormat(virBuffer *buf, virPCIVPDRe= source *res) virBufferEscapeString(buf, "%s\n", res->name); if (res->ro !=3D NULL) { - virBufferEscapeString(buf, "\n", "readonly"); - + virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); - virNodeDeviceCapVPDFormatRegularField(buf, "change_level", res->ro= ->change_level); - virNodeDeviceCapVPDFormatRegularField(buf, "manufacture_id", res->= ro->manufacture_id); - virNodeDeviceCapVPDFormatRegularField(buf, "part_number", res->ro-= >part_number); - virNodeDeviceCapVPDFormatRegularField(buf, "serial_number", res->r= o->serial_number); + + virBufferEscapeString(buf, "%s\n", re= s->ro->change_level); + virBufferEscapeString(buf, "%s\n"= , res->ro->manufacture_id); + virBufferEscapeString(buf, "%s\n", res-= >ro->part_number); + virBufferEscapeString(buf, "%s\n", = res->ro->serial_number); + g_ptr_array_foreach(res->ro->vendor_specific, (GFunc)virNodeDeviceCapVPDFormatCustomVendorFi= eld, buf); - virBufferAdjustIndent(buf, -2); + virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); } if (res->rw !=3D NULL) { - virBufferEscapeString(buf, "\n", "readwrite"= ); - + virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); - virNodeDeviceCapVPDFormatRegularField(buf, "asset_tag", res->rw->a= sset_tag); + + virBufferEscapeString(buf, "%s\n", res->rw-= >asset_tag); + g_ptr_array_foreach(res->rw->vendor_specific, (GFunc)virNodeDeviceCapVPDFormatCustomVendorFi= eld, buf); g_ptr_array_foreach(res->rw->system_specific, (GFunc)virNodeDeviceCapVPDFormatCustomSystemFi= eld, buf); - virBufferAdjustIndent(buf, -2); + virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); } --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 170663510689991.4994637079999; Tue, 30 Jan 2024 09:18:26 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id D137A1D2B; Tue, 30 Jan 2024 12:18:25 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1B4DB1CB6; Tue, 30 Jan 2024 12:08:58 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9448B1CDB; Tue, 30 Jan 2024 12:08:24 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 76FE11C33 for ; Tue, 30 Jan 2024 12:08:18 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-358-8_8VkUMROTev8MWZR-078A-1; Tue, 30 Jan 2024 12:08:16 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2C8FD85A59A for ; Tue, 30 Jan 2024 17:08:16 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 998B92166B31 for ; Tue, 30 Jan 2024 17:08:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: 8_8VkUMROTev8MWZR-078A-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 05/31] schema: nodedev: Adjust allowed characters in 'vpdFieldValueFormat' Date: Tue, 30 Jan 2024 18:07:43 +0100 Message-ID: <354238f40df3ffae9852b79bd449a10519afe7e4.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: WKM3BBHEBEC6BOQKCKWPUIX6SG4VGF2K X-Message-ID-Hash: WKM3BBHEBEC6BOQKCKWPUIX6SG4VGF2K X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706635108215100001 The check in 'virPCIVPDResourceIsValidTextValue' allows any printable characters, thus the XML schema should do the same. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/schemas/nodedev.rng | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/schemas/nodedev.rng b/src/conf/schemas/nodedev.rng index fba4021754..ff07313968 100644 --- a/src/conf/schemas/nodedev.rng +++ b/src/conf/schemas/nodedev.rng @@ -869,7 +869,7 @@ - [0-9a-zA-F -_,.:;=3D]{0,255} + .{0,255} --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706635198096700.4000048136354; Tue, 30 Jan 2024 09:19:58 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 108981E3A; Tue, 30 Jan 2024 12:19:57 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id DF0EA1CD3; Tue, 30 Jan 2024 12:09:07 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 147D21C9A; Tue, 30 Jan 2024 12:08:50 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 374431C5D for ; Tue, 30 Jan 2024 12:08:19 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-TvB9V7XJMHGvTRqfy1fM3A-1; Tue, 30 Jan 2024 12:08:17 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1BC4485A58F for ; Tue, 30 Jan 2024 17:08:17 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8AEC52166B31 for ; Tue, 30 Jan 2024 17:08:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: TvB9V7XJMHGvTRqfy1fM3A-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 06/31] tests: Test the previously mishandled PCI VPD characters Date: Tue, 30 Jan 2024 18:07:44 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: L3X3IZ6YH553BQEODGKRIV6MAA7ZUT44 X-Message-ID-Hash: L3X3IZ6YH553BQEODGKRIV6MAA7ZUT44 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706635198570100001 Modify the test data to validate '<>' and other characters. Unfortunately the test suite doesn't have a proper end-to-end test, thus we just add a XML->XML variant and also add data to the binary parser. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/nodedevschemadata/pci_0000_42_00_0_vpd.xml | 4 ++-- tests/virpcimock.c | 4 ++-- tests/virpcivpdtest.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/nodedevschemadata/pci_0000_42_00_0_vpd.xml b/tests/noded= evschemadata/pci_0000_42_00_0_vpd.xml index 8b56e4f6b4..c9a2901381 100644 --- a/tests/nodedevschemadata/pci_0000_42_00_0_vpd.xml +++ b/tests/nodedevschemadata/pci_0000_42_00_0_vpd.xml @@ -15,7 +15,7 @@ B1 foobar MBF2H332A-AEEOT - MT2113X00000 + MT2113X00000>< PCIeGen4 x8 MBF2H332A-AEEOT 3c53d07eec484d8aab34dabd24fe575aa @@ -25,7 +25,7 @@ fooasset vendorfield0 vendorfield2 - vendorfieldA + !@#$./>< systemfieldB systemfield0 diff --git a/tests/virpcimock.c b/tests/virpcimock.c index 13b37bb23d..2f98b0cf13 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -966,9 +966,9 @@ init_env(void) 't', 'e', 's', 't', 'n', 'a', 'm', 'e', PCI_VPD_LARGE_RESOURCE_FLAG | PCI_VPD_READ_ONLY_LARGE_RESOURCE_FLA= G, 0x16, 0x00, 'P', 'N', 0x02, '4', '2', - 'E', 'C', 0x04, '4', '2', '4', '2', + 'E', 'C', 0x04, '4', '<', '>', '2', 'V', 'A', 0x02, 'E', 'X', - 'R', 'V', 0x02, 0x31, 0x00, + 'R', 'V', 0x02, 0x1D, 0x00, PCI_VPD_RESOURCE_END_VAL }; struct pciVPD exampleVPD =3D { diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index b4dd68b7aa..ae5772d3f5 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -424,7 +424,7 @@ testPCIVPDGetFieldValueFormat(const void *data G_GNUC_U= NUSED) # define VPD_W_EXAMPLE_FIELDS \ 'V', 'Z', 0x02, '4', '2', \ - 'Y', 'A', 0x04, 'I', 'D', '4', '2', \ + 'Y', 'A', 0x04, '!', '<', '>', ':', \ 'Y', 'F', 0x02, 'E', 'X', \ 'Y', 'E', 0x00, \ 'R', 'W', 0x02, 0x00, 0x00 @@ -579,7 +579,7 @@ testVirPCIVPDParseFullVPD(const void *opaque G_GNUC_UNU= SED) if (testVirPCIVPDValidateExampleReadOnlyFields(res)) return -1; - if (STRNEQ_NULLABLE(res->rw->asset_tag, "ID42")) + if (STRNEQ_NULLABLE(res->rw->asset_tag, "!<>:")) return -1; if (!res->rw->vendor_specific) --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706636636390541.6201900809479; Tue, 30 Jan 2024 09:43:56 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0A7D71D7F; Tue, 30 Jan 2024 12:43:54 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 49BD21DAB; Tue, 30 Jan 2024 12:11:08 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2869E1C98; Tue, 30 Jan 2024 12:09:58 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 7A6B41CDF for ; Tue, 30 Jan 2024 12:08:30 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-333-fdYB5tcDOpyekpW2t6VN7Q-1; Tue, 30 Jan 2024 12:08:20 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 54E831C0512C for ; Tue, 30 Jan 2024 17:08:18 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70EC12166B33 for ; Tue, 30 Jan 2024 17:08:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: fdYB5tcDOpyekpW2t6VN7Q-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 07/31] Don't overwrite error message from 'virXPathNodeSet' Date: Tue, 30 Jan 2024 18:07:45 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 3BHM5ZTVCMGEBS6AQHXNWVRKUVPNEPP4 X-Message-ID-Hash: 3BHM5ZTVCMGEBS6AQHXNWVRKUVPNEPP4 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706636638030100001 'virXPathNodeSet' returns -1 only when 'ctxt' or 'xpath' are NULL or when the 'xpath' string is invalid. Both are programmign errors. It doesn't make sense for the code to overwrite the error message for anything supposedly more relevant. The majority of calls to 'virXPathNodeSet' already didn't do this, so this patch fixes the rest to prevent it from spreading again. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 78 +++++++------------------------ src/conf/network_conf.c | 80 ++++++++------------------------ src/conf/node_device_conf.c | 17 ++----- src/conf/numa_conf.c | 15 +++--- src/cpu/cpu_ppc64.c | 5 +- src/qemu/qemu_capabilities.c | 30 +++--------- src/qemu/qemu_domain.c | 23 +++------ src/qemu/qemu_migration_cookie.c | 5 +- src/qemu/qemu_nbdkit.c | 5 +- src/vz/vz_sdk.c | 5 +- 10 files changed, 72 insertions(+), 191 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fb5a5cc351..ea6fb1e48d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17780,11 +17780,8 @@ virDomainResctrlMonDefParse(virDomainDef *def, ctxt->node =3D node; - if ((n =3D virXPathNodeSet("./monitor", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot extract monitor nodes")); + if ((n =3D virXPathNodeSet("./monitor", ctxt, &nodes)) < 0) goto cleanup; - } for (i =3D 0; i < n; i++) { domresmon =3D g_new0(virDomainResctrlMonDef, 1); @@ -17912,11 +17909,8 @@ virDomainCachetuneDefParse(virDomainDef *def, if (virBitmapIsAllClear(vcpus)) return 0; - if ((n =3D virXPathNodeSet("./cache", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot extract cache nodes under cachetune")); + if ((n =3D virXPathNodeSet("./cache", ctxt, &nodes)) < 0) return -1; - } if (virDomainResctrlVcpuMatch(def, vcpus, &resctrl) < 0) return -1; @@ -18182,11 +18176,8 @@ virDomainDefParseMemory(virDomainDef *def, if (virXPathNode("./memoryBacking/hugepages", ctxt)) { /* hugepages will be used */ - if ((n =3D virXPathNodeSet("./memoryBacking/hugepages/page", ctxt,= &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot extract hugepages nodes")); + if ((n =3D virXPathNodeSet("./memoryBacking/hugepages/page", ctxt,= &nodes)) < 0) return -1; - } if (n) { def->mem.hugepages =3D g_new0(virDomainHugePage, n); @@ -18270,11 +18261,8 @@ virDomainMemorytuneDefParse(virDomainDef *def, if (virBitmapIsAllClear(vcpus)) return 0; - if ((n =3D virXPathNodeSet("./node", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot extract memory nodes under memorytune")); + if ((n =3D virXPathNodeSet("./node", ctxt, &nodes)) < 0) return -1; - } if (virDomainResctrlVcpuMatch(def, vcpus, &resctrl) < 0) return -1; @@ -18341,11 +18329,9 @@ virDomainDefTunablesParse(virDomainDef *def, &def->blkio.weight) < 0) def->blkio.weight =3D 0; - if ((n =3D virXPathNodeSet("./blkiotune/device", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot extract blkiotune nodes")); + if ((n =3D virXPathNodeSet("./blkiotune/device", ctxt, &nodes)) < 0) return -1; - } + if (n) def->blkio.devices =3D g_new0(virBlkioDevice, n); @@ -18456,11 +18442,8 @@ virDomainDefTunablesParse(virDomainDef *def, } VIR_FREE(nodes); - if ((n =3D virXPathNodeSet("./cputune/emulatorpin", ctxt, &nodes)) < 0= ) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot extract emulatorpin nodes")); + if ((n =3D virXPathNodeSet("./cputune/emulatorpin", ctxt, &nodes)) < 0) return -1; - } if (n) { if (n > 1) { @@ -18475,11 +18458,8 @@ virDomainDefTunablesParse(virDomainDef *def, VIR_FREE(nodes); - if ((n =3D virXPathNodeSet("./cputune/iothreadpin", ctxt, &nodes)) < 0= ) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot extract iothreadpin nodes")); + if ((n =3D virXPathNodeSet("./cputune/iothreadpin", ctxt, &nodes)) < 0) return -1; - } for (i =3D 0; i < n; i++) { if (virDomainIOThreadPinDefParseXML(nodes[i], def) < 0) @@ -18487,11 +18467,8 @@ virDomainDefTunablesParse(virDomainDef *def, } VIR_FREE(nodes); - if ((n =3D virXPathNodeSet("./cputune/vcpusched", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot extract vcpusched nodes")); + if ((n =3D virXPathNodeSet("./cputune/vcpusched", ctxt, &nodes)) < 0) return -1; - } for (i =3D 0; i < n; i++) { if (virDomainVcpuThreadSchedParse(nodes[i], def) < 0) @@ -18499,11 +18476,8 @@ virDomainDefTunablesParse(virDomainDef *def, } VIR_FREE(nodes); - if ((n =3D virXPathNodeSet("./cputune/iothreadsched", ctxt, &nodes)) <= 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot extract iothreadsched nodes")); + if ((n =3D virXPathNodeSet("./cputune/iothreadsched", ctxt, &nodes)) <= 0) return -1; - } for (i =3D 0; i < n; i++) { if (virDomainIOThreadSchedParse(nodes[i], def) < 0) @@ -18511,11 +18485,8 @@ virDomainDefTunablesParse(virDomainDef *def, } VIR_FREE(nodes); - if ((n =3D virXPathNodeSet("./cputune/emulatorsched", ctxt, &nodes)) <= 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot extract emulatorsched nodes")); + if ((n =3D virXPathNodeSet("./cputune/emulatorsched", ctxt, &nodes)) <= 0) return -1; - } if (n) { if (n > 1) { @@ -18529,11 +18500,8 @@ virDomainDefTunablesParse(virDomainDef *def, } VIR_FREE(nodes); - if ((n =3D virXPathNodeSet("./cputune/cachetune", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot extract cachetune nodes")); + if ((n =3D virXPathNodeSet("./cputune/cachetune", ctxt, &nodes)) < 0) return -1; - } for (i =3D 0; i < n; i++) { if (virDomainCachetuneDefParse(def, ctxt, nodes[i], flags) < 0) @@ -18541,11 +18509,8 @@ virDomainDefTunablesParse(virDomainDef *def, } VIR_FREE(nodes); - if ((n =3D virXPathNodeSet("./cputune/memorytune", ctxt, &nodes)) < 0)= { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot extract memorytune nodes")); + if ((n =3D virXPathNodeSet("./cputune/memorytune", ctxt, &nodes)) < 0) return -1; - } for (i =3D 0; i < n; i++) { if (virDomainMemorytuneDefParse(def, ctxt, nodes[i], flags) < 0) @@ -18849,11 +18814,8 @@ virDomainDefParseXML(xmlXPathContextPtr ctxt, !virDomainIOThreadIDArrayHasPin(def)) def->placement_mode =3D VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO; - if ((n =3D virXPathNodeSet("./resource", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot extract resource nodes")); + if ((n =3D virXPathNodeSet("./resource", ctxt, &nodes)) < 0) return NULL; - } if (n > 1) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -18901,11 +18863,9 @@ virDomainDefParseXML(xmlXPathContextPtr ctxt, return NULL; /* analysis of the resource leases */ - if ((n =3D virXPathNodeSet("./devices/lease", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot extract device leases")); + if ((n =3D virXPathNodeSet("./devices/lease", ctxt, &nodes)) < 0) return NULL; - } + if (n) def->leases =3D g_new0(virDomainLeaseDef *, n); for (i =3D 0; i < n; i++) { @@ -19024,11 +18984,9 @@ virDomainDefParseXML(xmlXPathContextPtr ctxt, } VIR_FREE(nodes); - if ((n =3D virXPathNodeSet("./devices/console", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot extract console devices")); + if ((n =3D virXPathNodeSet("./devices/console", ctxt, &nodes)) < 0) return NULL; - } + if (n) def->consoles =3D g_new0(virDomainChrDef *, n); diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index ed2e72eddf..a2220c05a6 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -892,13 +892,9 @@ virNetworkDNSDefParseXML(const char *networkName, &def->forwardPlainNames) < 0) return -1; - nfwds =3D virXPathNodeSet("./forwarder", ctxt, &fwdNodes); - if (nfwds < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid element found in of ne= twork %1$s"), - networkName); + if ((nfwds =3D virXPathNodeSet("./forwarder", ctxt, &fwdNodes)) < 0) return -1; - } + if (nfwds > 0) { def->forwarders =3D g_new0(virNetworkDNSForwarder, nfwds); @@ -922,13 +918,9 @@ virNetworkDNSDefParseXML(const char *networkName, } } - nhosts =3D virXPathNodeSet("./host", ctxt, &hostNodes); - if (nhosts < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid element found in of network= %1$s"), - networkName); + if ((nhosts =3D virXPathNodeSet("./host", ctxt, &hostNodes)) < 0) return -1; - } + if (nhosts > 0) { def->hosts =3D g_new0(virNetworkDNSHostDef, nhosts); @@ -941,13 +933,9 @@ virNetworkDNSDefParseXML(const char *networkName, } } - nsrvs =3D virXPathNodeSet("./srv", ctxt, &srvNodes); - if (nsrvs < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid element found in of network = %1$s"), - networkName); + if ((nsrvs =3D virXPathNodeSet("./srv", ctxt, &srvNodes)) < 0) return -1; - } + if (nsrvs > 0) { def->srvs =3D g_new0(virNetworkDNSSrvDef, nsrvs); @@ -960,13 +948,9 @@ virNetworkDNSDefParseXML(const char *networkName, } } - ntxts =3D virXPathNodeSet("./txt", ctxt, &txtNodes); - if (ntxts < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid element found in of network = %1$s"), - networkName); + if ((ntxts =3D virXPathNodeSet("./txt", ctxt, &txtNodes)) < 0) return -1; - } + if (ntxts > 0) { def->txts =3D g_new0(virNetworkDNSTxtDef, ntxts); @@ -1222,13 +1206,10 @@ virNetworkForwardNatDefParseXML(const char *network= Name, return -1; /* addresses for SNAT */ - nNatAddrs =3D virXPathNodeSet("./address", ctxt, &natAddrNodes); - if (nNatAddrs < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid
element found in of = network %1$s"), - networkName); + if ((nNatAddrs =3D virXPathNodeSet("./address", ctxt, &natAddrNodes)) = < 0) return -1; - } else if (nNatAddrs > 1) { + + if (nNatAddrs > 1) { virReportError(VIR_ERR_XML_ERROR, _("Only one
element is allowed in i= n in network %1$s"), networkName); @@ -1284,13 +1265,10 @@ virNetworkForwardNatDefParseXML(const char *network= Name, } /* ports for SNAT and MASQUERADE */ - nNatPorts =3D virXPathNodeSet("./port", ctxt, &natPortNodes); - if (nNatPorts < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid element found in of net= work %1$s"), - networkName); + if ((nNatPorts =3D virXPathNodeSet("./port", ctxt, &natPortNodes)) < 0) return -1; - } else if (nNatPorts > 1) { + + if (nNatPorts > 1) { virReportError(VIR_ERR_XML_ERROR, _("Only one element is allowed in in <= forward> in network %1$s"), networkName); @@ -1358,37 +1336,19 @@ virNetworkForwardDefParseXML(const char *networkNam= e, } /* bridge and hostdev modes can use a pool of physical interfaces */ - nForwardIfs =3D virXPathNodeSet("./interface", ctxt, &forwardIfNodes); - if (nForwardIfs < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid element found in o= f network %1$s"), - networkName); + if ((nForwardIfs =3D virXPathNodeSet("./interface", ctxt, &forwardIfNo= des)) < 0) return -1; - } - nForwardAddrs =3D virXPathNodeSet("./address", ctxt, &forwardAddrNodes= ); - if (nForwardAddrs < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid
element found in of = network %1$s"), - networkName); + if ((nForwardAddrs =3D virXPathNodeSet("./address", ctxt, &forwardAddr= Nodes)) < 0) return -1; - } - nForwardPfs =3D virXPathNodeSet("./pf", ctxt, &forwardPfNodes); - if (nForwardPfs < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid element found in of netwo= rk %1$s"), - networkName); + if ((nForwardPfs =3D virXPathNodeSet("./pf", ctxt, &forwardPfNodes)) <= 0) return -1; - } - nForwardNats =3D virXPathNodeSet("./nat", ctxt, &forwardNatNodes); - if (nForwardNats < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid element found in of netw= ork %1$s"), - networkName); + if ((nForwardNats =3D virXPathNodeSet("./nat", ctxt, &forwardNatNodes)= ) < 0) return -1; - } else if (nForwardNats > 1) { + + if (nForwardNats > 1) { virReportError(VIR_ERR_XML_ERROR, _("Only one element is allowed in o= f network %1$s"), networkName); diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 95de77abe9..dd174d3020 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -960,11 +960,9 @@ virNodeDeviceCapVPDParseCustomFields(xmlXPathContextPt= r ctxt, virPCIVPDResource g_autofree xmlNodePtr *nodes =3D NULL; size_t i =3D 0; - if ((nfields =3D virXPathNodeSet("./vendor_field[@index]", ctxt, &node= s)) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("failed to evaluate elements")); + if ((nfields =3D virXPathNodeSet("./vendor_field[@index]", ctxt, &node= s)) < 0) return -1; - } + for (i =3D 0; i < nfields; i++) { g_autofree char *value =3D NULL; g_autofree char *index =3D NULL; @@ -989,11 +987,9 @@ virNodeDeviceCapVPDParseCustomFields(xmlXPathContextPt= r ctxt, virPCIVPDResource VIR_FREE(nodes); if (!readOnly) { - if ((nfields =3D virXPathNodeSet("./system_field[@index]", ctxt, &= nodes)) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("failed to evaluate elements")); + if ((nfields =3D virXPathNodeSet("./system_field[@index]", ctxt, &= nodes)) < 0) return -1; - } + for (i =3D 0; i < nfields; i++) { g_autofree char *value =3D NULL; g_autofree char *index =3D NULL; @@ -1074,11 +1070,8 @@ virNodeDeviceCapVPDParseXML(xmlXPathContextPtr ctxt,= virPCIVPDResource **res) return -1; } - if ((nfields =3D virXPathNodeSet("./fields[@access]", ctxt, &nodes)) <= 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("no VPD elements with an access type attribute = found")); + if ((nfields =3D virXPathNodeSet("./fields[@access]", ctxt, &nodes)) <= 0) return -1; - } for (i =3D 0; i < nfields; i++) { g_autofree char *access =3D NULL; diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index bcd7838e00..d8120de6d2 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -135,11 +135,8 @@ virDomainNumatuneNodeParseXML(virDomainNuma *numa, size_t i =3D 0; g_autofree xmlNodePtr *nodes =3D NULL; - if ((n =3D virXPathNodeSet("./numatune/memnode", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot extract memnode nodes")); + if ((n =3D virXPathNodeSet("./numatune/memnode", ctxt, &nodes)) < 0) return -1; - } if (!n) return 0; @@ -700,7 +697,10 @@ virDomainNumaDefNodeDistanceParseXML(virDomainNuma *de= f, if (!virXPathNode("./distances[1]", ctxt)) return 0; - if ((sibling =3D virXPathNodeSet("./distances[1]/sibling", ctxt, &node= s)) <=3D 0) { + if ((sibling =3D virXPathNodeSet("./distances[1]/sibling", ctxt, &node= s)) < 0) + goto cleanup; + + if (sibling =3D=3D 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("NUMA distances defined without siblings")); goto cleanup; @@ -852,7 +852,10 @@ virDomainNumaDefParseXML(virDomainNuma *def, if (!virXPathNode("./cpu/numa[1]", ctxt)) return 0; - if ((n =3D virXPathNodeSet("./cpu/numa[1]/cell", ctxt, &cell)) <=3D 0)= { + if ((n =3D virXPathNodeSet("./cpu/numa[1]/cell", ctxt, &cell)) < 0) + return -1; + + if (n =3D=3D 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("NUMA topology defined without NUMA cells")); return -1; diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c index e13cdbdf6b..448a0a7d85 100644 --- a/src/cpu/cpu_ppc64.c +++ b/src/cpu/cpu_ppc64.c @@ -334,7 +334,10 @@ ppc64ModelParse(xmlXPathContextPtr ctxt, } } - if ((n =3D virXPathNodeSet("./pvr", ctxt, &nodes)) <=3D 0) { + if ((n =3D virXPathNodeSet("./pvr", ctxt, &nodes)) < 0) + return -1; + + if (n =3D=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing PVR information for CPU model %1$s"), model->name); diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index e24b679060..f4b4f05479 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3986,11 +3986,8 @@ virQEMUCapsLoadCPUModels(virArch arch, int n; xmlNodePtr node; - if ((n =3D virXPathNodeSet(xpath, ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to parse qemu capabilities cpus")); + if ((n =3D virXPathNodeSet(xpath, ctxt, &nodes)) < 0) return -1; - } if (n =3D=3D 0) return 0; @@ -4028,11 +4025,8 @@ virQEMUCapsLoadCPUModels(virArch arch, nblockers =3D virXPathNodeSet("./blocker", ctxt, &blockerNodes); ctxt->node =3D node; - if (nblockers < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to parse CPU blockers in QEMU capabil= ities")); + if (nblockers < 0) return -1; - } if (nblockers > 0) { size_t j; @@ -4071,11 +4065,8 @@ virQEMUCapsLoadMachines(virQEMUCapsAccel *caps, size_t i; int n; - if ((n =3D virXPathNodeSet(xpath, ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to parse qemu capabilities machines")); + if ((n =3D virXPathNodeSet(xpath, ctxt, &nodes)) < 0) return -1; - } if (n =3D=3D 0) return 0; @@ -4288,11 +4279,8 @@ virQEMUCapsParseSGXInfo(virQEMUCaps *qemuCaps, ctxt->node =3D sgxSections; nSgxSections =3D virXPathNodeSet("./section", ctxt, §ionNodes); - if (nSgxSections < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to parse SGX sections in QEMU capabil= ities cache")); + if (nSgxSections < 0) return -1; - } sgx->nSgxSections =3D nSgxSections; sgx->sgxSections =3D g_new0(virSGXSection, nSgxSections); @@ -4375,11 +4363,8 @@ virQEMUCapsParseFlags(virQEMUCaps *qemuCaps, xmlXPat= hContextPtr ctxt) size_t i; int n; - if ((n =3D virXPathNodeSet("./flag", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to parse qemu capabilities flags")); + if ((n =3D virXPathNodeSet("./flag", ctxt, &nodes)) < 0) return -1; - } VIR_DEBUG("Got flags %d", n); for (i =3D 0; i < n; i++) { @@ -4413,11 +4398,8 @@ virQEMUCapsParseGIC(virQEMUCaps *qemuCaps, xmlXPathC= ontextPtr ctxt) size_t i; int n; - if ((n =3D virXPathNodeSet("./gic", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to parse qemu capabilities gic")); + if ((n =3D virXPathNodeSet("./gic", ctxt, &nodes)) < 0) return -1; - } if (n > 0) { unsigned int uintValue; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index dad89954d9..dac9e97ce9 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3155,11 +3155,8 @@ qemuDomainObjPrivateXMLParseSlirpFeatures(xmlNodePtr= featuresNode, ctxt->node =3D featuresNode; - if ((n =3D virXPathNodeSet("./feature", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("failed to parse slirp-helper features")); + if ((n =3D virXPathNodeSet("./feature", ctxt, &nodes)) < 0) return -1; - } for (i =3D 0; i < n; i++) { g_autofree char *str =3D virXMLPropString(nodes[i], "name"); @@ -3273,11 +3270,9 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, } VIR_FREE(nodes); - if ((n =3D virXPathNodeSet("./qemuCaps/flag", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("failed to parse qemu capabilities flags")); + if ((n =3D virXPathNodeSet("./qemuCaps/flag", ctxt, &nodes)) < 0) return -1; - } + if (n > 0) { qemuCaps =3D virQEMUCapsNew(); @@ -3305,11 +3300,9 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, priv->fakeReboot =3D virXPathBoolean("boolean(./fakereboot)", ctxt) = =3D=3D 1; - if ((n =3D virXPathNodeSet("./devices/device", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to parse qemu device list")); + if ((n =3D virXPathNodeSet("./devices/device", ctxt, &nodes)) < 0) return -1; - } + if (n > 0) { /* NULL-terminated list */ priv->qemuDevices =3D g_new0(char *, n + 1); @@ -3325,11 +3318,9 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, } VIR_FREE(nodes); - if ((n =3D virXPathNodeSet("./slirp/helper", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to parse slirp helper list")); + if ((n =3D virXPathNodeSet("./slirp/helper", ctxt, &nodes)) < 0) return -1; - } + for (i =3D 0; i < n; i++) { g_autofree char *alias =3D virXMLPropString(nodes[i], "alias"); g_autofree char *pid =3D virXMLPropString(nodes[i], "pid"); diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_coo= kie.c index 5505fdaf22..4361949cca 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -947,11 +947,8 @@ qemuMigrationCookieNetworkXMLParse(xmlXPathContextPtr = ctxt) g_autofree xmlNodePtr *interfaces =3D NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) - if ((n =3D virXPathNodeSet("./network/interface", ctxt, &interfaces)) = < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing interface information")); + if ((n =3D virXPathNodeSet("./network/interface", ctxt, &interfaces)) = < 0) return NULL; - } optr->nnets =3D n; optr->net =3D g_new0(qemuMigrationCookieNetData, optr->nnets); diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 1c72b6fe6a..acf961b59e 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -400,11 +400,8 @@ qemuNbdkitCapsParseFlags(qemuNbdkitCaps *nbdkitCaps, size_t i; int n; - if ((n =3D virXPathNodeSet("./flag", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to parse qemu capabilities flags")); + if ((n =3D virXPathNodeSet("./flag", ctxt, &nodes)) < 0) return -1; - } VIR_DEBUG("Got flags %d", n); for (i =3D 0; i < n; i++) { diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 6a15d60577..ce4586a3f5 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -4612,11 +4612,8 @@ prlsdkParseSnapshotTree(const char *treexml) "ParallelsSavedStates", &ctxt, NULL, false))) goto cleanup; - if ((n =3D virXPathNodeSet("//SavedStateItem", ctxt, &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot extract snapshot nodes")); + if ((n =3D virXPathNodeSet("//SavedStateItem", ctxt, &nodes)) < 0) goto cleanup; - } for (i =3D 0; i < n; i++) { if (nodes[i]->parent =3D=3D xmlDocGetRootElement(xml)) --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706635320385643.6638618321525; Tue, 30 Jan 2024 09:22:00 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 31DE61C28; Tue, 30 Jan 2024 12:21:59 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C0F3A1D5B; Tue, 30 Jan 2024 12:09:17 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 597831D44; Tue, 30 Jan 2024 12:08:53 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 5FEFC1C98 for ; Tue, 30 Jan 2024 12:08:21 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-385-W9DnaLzmMEaQcupciUVs2A-1; Tue, 30 Jan 2024 12:08:19 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4B697380670B for ; Tue, 30 Jan 2024 17:08:19 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id A50B22166B31 for ; Tue, 30 Jan 2024 17:08:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: W9DnaLzmMEaQcupciUVs2A-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 08/31] tests: virpcivpdtest: Remove 'testVirPCIVPDReadVPDBytes' case Date: Tue, 30 Jan 2024 18:07:46 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: GGVDI6QFOZCJSWWWHKV7N3YSCLBURXIJ X-Message-ID-Hash: GGVDI6QFOZCJSWWWHKV7N3YSCLBURXIJ X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706635321315100001 The case checks only the 'virPCIVPDReadVPDBytes' which is also tested multiple times via 'virPCIVPDParse' as it's used to read the data, thus having a special case for this is pointless. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/virpcivpdtest.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index ae5772d3f5..aadd1b222b 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -429,45 +429,6 @@ testPCIVPDGetFieldValueFormat(const void *data G_GNUC_= UNUSED) 'Y', 'E', 0x00, \ 'R', 'W', 0x02, 0x00, 0x00 -static int -testVirPCIVPDReadVPDBytes(const void *opaque G_GNUC_UNUSED) -{ - VIR_AUTOCLOSE fd =3D -1; - g_autofree uint8_t *buf =3D NULL; - uint8_t csum =3D 0; - size_t readBytes =3D 0; - size_t dataLen =3D 0; - - /* An example of a valid VPD record with one VPD-R resource and 2 fiel= ds. */ - uint8_t fullVPDExample[] =3D { - VPD_STRING_RESOURCE_EXAMPLE_HEADER, VPD_STRING_RESOURCE_EXAMPLE_DA= TA, - VPD_R_FIELDS_EXAMPLE_HEADER, VPD_R_FIELDS_EXAMPLE_DATA, - PCI_VPD_RESOURCE_END_VAL - }; - dataLen =3D G_N_ELEMENTS(fullVPDExample) - 2; - buf =3D g_malloc0(dataLen); - - if ((fd =3D virCreateAnonymousFile(fullVPDExample, dataLen)) < 0) - return -1; - - readBytes =3D virPCIVPDReadVPDBytes(fd, buf, dataLen, 0, &csum); - - if (readBytes !=3D dataLen) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "The number of bytes read %zu is lower than expecte= d %zu ", - readBytes, dataLen); - return -1; - } - - if (csum) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "The sum of all VPD bytes up to and including the c= hecksum byte" - "is equal to zero: 0x%02x", csum); - return -1; - } - return 0; -} - static int testVirPCIVPDParseVPDStringResource(const void *opaque G_GNUC_UNUSED) { @@ -1003,8 +964,6 @@ mymain(void) if (virTestRun("Determining a field value format by a key ", testPCIVPDGetFieldValueFormat, NULL) < 0) ret =3D -1; - if (virTestRun("Reading VPD bytes ", testVirPCIVPDReadVPDBytes, NULL) = < 0) - ret =3D -1; if (virTestRun("Parsing VPD string resources ", testVirPCIVPDParseVPDS= tringResource, NULL) < 0) ret =3D -1; if (virTestRun("Parsing a VPD resource with a zero-length RW ", --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706635424230574.3084790492717; Tue, 30 Jan 2024 09:23:44 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id BDEEC1D4D; Tue, 30 Jan 2024 12:23:35 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C47A61D66; Tue, 30 Jan 2024 12:09:25 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id AC7A71D45; Tue, 30 Jan 2024 12:08:58 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id B16821CBE for ; Tue, 30 Jan 2024 12:08:22 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-386-LEVZQgXqMy65aGnMRWiAmQ-1; Tue, 30 Jan 2024 12:08:20 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3519B101AA57 for ; Tue, 30 Jan 2024 17:08:20 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id A17722166B31 for ; Tue, 30 Jan 2024 17:08:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: LEVZQgXqMy65aGnMRWiAmQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 09/31] util: virpcivpd: Unexport 'virPCIVPDReadVPDBytes' Date: Tue, 30 Jan 2024 18:07:47 +0100 Message-ID: <7ed8372a7d1eb65bb314c2e136c2fe938fb48534.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: HX32YEREHMHOP3IVASTAFEOP2EQZSWIW X-Message-ID-Hash: HX32YEREHMHOP3IVASTAFEOP2EQZSWIW X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706635425859100001 The function is no longer used outside of virpcivpd.c Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 - src/util/virpcivpd.c | 14 +------------- src/util/virpcivpdpriv.h | 3 --- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fc26109029..dbc4e26d79 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3702,7 +3702,6 @@ virVHBAPathExists; virPCIVPDParse; virPCIVPDParseVPDLargeResourceFields; virPCIVPDParseVPDLargeResourceString; -virPCIVPDReadVPDBytes; virPCIVPDResourceCustomCompareIndex; virPCIVPDResourceCustomFree; virPCIVPDResourceCustomUpsertValue; diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 81c7c317b3..373321a836 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -401,7 +401,7 @@ virPCIVPDResourceUpdateKeyword(virPCIVPDResource *res, = const bool readOnly, * descriptor, it is reported and -1 is returned to the caller. If EOF is = occurred, 0 is returned * to the caller. */ -size_t +static size_t virPCIVPDReadVPDBytes(int vpdFileFd, uint8_t *buf, size_t count, off_t off= set, uint8_t *csum) { ssize_t numRead =3D pread(vpdFileFd, buf, count, offset); @@ -732,18 +732,6 @@ virPCIVPDParse(int vpdFileFd) #else /* ! __linux__ */ -size_t -virPCIVPDReadVPDBytes(int vpdFileFd G_GNUC_UNUSED, - uint8_t *buf G_GNUC_UNUSED, - size_t count G_GNUC_UNUSED, - off_t offset G_GNUC_UNUSED, - uint8_t *csum G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_NO_SUPPORT, "%s", - _("PCI VPD reporting not available on this platform")); - return 0; -} - bool virPCIVPDParseVPDLargeResourceString(int vpdFileFd G_GNUC_UNUSED, uint16_t resPos G_GNUC_UNUSED, diff --git a/src/util/virpcivpdpriv.h b/src/util/virpcivpdpriv.h index 0f565f81ae..17e6e14ab7 100644 --- a/src/util/virpcivpdpriv.h +++ b/src/util/virpcivpdpriv.h @@ -69,9 +69,6 @@ virPCIVPDResourceCustomCompareIndex(virPCIVPDResourceCust= om *a, virPCIVPDResourc bool virPCIVPDResourceCustomUpsertValue(GPtrArray *arr, char index, const char = *const value); -size_t -virPCIVPDReadVPDBytes(int vpdFileFd, uint8_t *buf, size_t count, off_t off= set, uint8_t *csum); - bool virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uint16_t resPos, = uint16_t resDataLen, bool readOnly, uint8_t *csum, vi= rPCIVPDResource *res); --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706635506752860.5350116382248; Tue, 30 Jan 2024 09:25:06 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id A48701E2E; Tue, 30 Jan 2024 12:25:05 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D4EF61CDC; Tue, 30 Jan 2024 12:09:42 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 699B11D5D; Tue, 30 Jan 2024 12:09:20 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 6B8631CD1 for ; Tue, 30 Jan 2024 12:08:23 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-_Xi1PLZbNV6uom6LPb8pGg-1; Tue, 30 Jan 2024 12:08:21 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 246031C05139 for ; Tue, 30 Jan 2024 17:08:21 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B4732166B31 for ; Tue, 30 Jan 2024 17:08:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: _Xi1PLZbNV6uom6LPb8pGg-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 10/31] util: pcivpd: Unexport virPCIVPDParseVPDLargeResourceFields Date: Tue, 30 Jan 2024 18:07:48 +0100 Message-ID: <476c475eaec3c5a6b87f680930398b55ce566bb0.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: P2NUA7NOGSQIGVTMIDOH2OBKNATSU5WV X-Message-ID-Hash: P2NUA7NOGSQIGVTMIDOH2OBKNATSU5WV X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706635508074100001 The function is not used in other files. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 - src/util/virpcivpd.c | 15 +-------------- src/util/virpcivpdpriv.h | 3 --- 3 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index dbc4e26d79..89b0d01de6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3700,7 +3700,6 @@ virVHBAPathExists; # util/virpcivpd.h virPCIVPDParse; -virPCIVPDParseVPDLargeResourceFields; virPCIVPDParseVPDLargeResourceString; virPCIVPDResourceCustomCompareIndex; virPCIVPDResourceCustomFree; diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 373321a836..510be65cb6 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -436,7 +436,7 @@ virPCIVPDReadVPDBytes(int vpdFileFd, uint8_t *buf, size= _t count, off_t offset, u * Returns: a pointer to a VPDResource which needs to be freed by the call= er or * NULL if getting it failed for some reason. */ -bool +static bool virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uint16_t resPos, uint1= 6_t resDataLen, bool readOnly, uint8_t *csum, virPCIV= PDResource *res) { @@ -744,19 +744,6 @@ virPCIVPDParseVPDLargeResourceString(int vpdFileFd G_G= NUC_UNUSED, return false; } -bool -virPCIVPDParseVPDLargeResourceFields(int vpdFileFd G_GNUC_UNUSED, - uint16_t resPos G_GNUC_UNUSED, - uint16_t resDataLen G_GNUC_UNUSED, - bool readOnly G_GNUC_UNUSED, - uint8_t *csum G_GNUC_UNUSED, - virPCIVPDResource *res G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_NO_SUPPORT, "%s", - _("PCI VPD reporting not available on this platform")); - return false; -} - virPCIVPDResource * virPCIVPDParse(int vpdFileFd G_GNUC_UNUSED) { diff --git a/src/util/virpcivpdpriv.h b/src/util/virpcivpdpriv.h index 17e6e14ab7..d84f1e9c8a 100644 --- a/src/util/virpcivpdpriv.h +++ b/src/util/virpcivpdpriv.h @@ -69,8 +69,5 @@ virPCIVPDResourceCustomCompareIndex(virPCIVPDResourceCust= om *a, virPCIVPDResourc bool virPCIVPDResourceCustomUpsertValue(GPtrArray *arr, char index, const char = *const value); -bool virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uint16_t resPos, = uint16_t resDataLen, - bool readOnly, uint8_t *csum, vi= rPCIVPDResource *res); - bool virPCIVPDParseVPDLargeResourceString(int vpdFileFd, uint16_t resPos, = uint16_t resDataLen, uint8_t *csum, virPCIVPDResource= *res); --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706635593854788.018211444942; Tue, 30 Jan 2024 09:26:33 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id C79491E69; Tue, 30 Jan 2024 12:26:32 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D1F531D6E; Tue, 30 Jan 2024 12:09:50 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 85CBE1D5F; Tue, 30 Jan 2024 12:09:22 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id E2E141CDB for ; Tue, 30 Jan 2024 12:08:24 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-cYN7FPDsOxeRmw-u1k_DCA-1; Tue, 30 Jan 2024 12:08:22 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1041F10193DD for ; Tue, 30 Jan 2024 17:08:22 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CA622166B33 for ; Tue, 30 Jan 2024 17:08:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: cYN7FPDsOxeRmw-u1k_DCA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 11/31] tests: virpcivpd: Remove 'testVirPCIVPDParseVPDStringResource' case Date: Tue, 30 Jan 2024 18:07:49 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: GZ33NRR7SOFYPCDJHSI655NDYKJS3QKE X-Message-ID-Hash: GZ33NRR7SOFYPCDJHSI655NDYKJS3QKE X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706635594293100001 The test case excercises 'virPCIVPDParseVPDLargeResourceString' which is also tested by other cases which parse the whole VPD block. Remove the specific test case as it's not adding any additional value. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/virpcivpdtest.c | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index aadd1b222b..fddb42f52c 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -429,42 +429,6 @@ testPCIVPDGetFieldValueFormat(const void *data G_GNUC_= UNUSED) 'Y', 'E', 0x00, \ 'R', 'W', 0x02, 0x00, 0x00 -static int -testVirPCIVPDParseVPDStringResource(const void *opaque G_GNUC_UNUSED) -{ - VIR_AUTOCLOSE fd =3D -1; - uint8_t csum =3D 0; - size_t dataLen =3D 0; - bool result =3D false; - - g_autoptr(virPCIVPDResource) res =3D g_new0(virPCIVPDResource, 1); - const char *expectedValue =3D "testname"; - - const uint8_t stringResExample[] =3D { - VPD_STRING_RESOURCE_EXAMPLE_DATA - }; - - dataLen =3D G_N_ELEMENTS(stringResExample); - if ((fd =3D virCreateAnonymousFile(stringResExample, dataLen)) < 0) - return -1; - - result =3D virPCIVPDParseVPDLargeResourceString(fd, 0, dataLen, &csum,= res); - - if (!result) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - "Could not parse the example resource."); - return -1; - } - - if (STRNEQ(expectedValue, res->name)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "Unexpected string resource value: %s, expected: %s= ", - res->name, expectedValue); - return -1; - } - return 0; -} - static int testVirPCIVPDValidateExampleReadOnlyFields(virPCIVPDResource *res) { @@ -964,8 +928,6 @@ mymain(void) if (virTestRun("Determining a field value format by a key ", testPCIVPDGetFieldValueFormat, NULL) < 0) ret =3D -1; - if (virTestRun("Parsing VPD string resources ", testVirPCIVPDParseVPDS= tringResource, NULL) < 0) - ret =3D -1; if (virTestRun("Parsing a VPD resource with a zero-length RW ", testVirPCIVPDParseZeroLengthRW, NULL) < 0) ret =3D -1; --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706635808044206.37879381597372; Tue, 30 Jan 2024 09:30:08 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id EF6811CD5; Tue, 30 Jan 2024 12:30:06 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 326481D7C; Tue, 30 Jan 2024 12:10:08 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3CD5C1D67; Tue, 30 Jan 2024 12:09:32 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 25A8F1D05 for ; Tue, 30 Jan 2024 12:08:27 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-663-hz2izrjCPj2lDHtT5Q5G-w-1; Tue, 30 Jan 2024 12:08:24 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ED1013814E8D for ; Tue, 30 Jan 2024 17:08:22 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66AFD2166B31 for ; Tue, 30 Jan 2024 17:08:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: hz2izrjCPj2lDHtT5Q5G-w-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 12/31] util: virpcivpd: Unexport 'virPCIVPDParseVPDLargeResourceString' Date: Tue, 30 Jan 2024 18:07:50 +0100 Message-ID: <3f06ee9312275062b5ab7fd3a9aa3bb2a662d8b9.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: PPLTFF6CTFKTN3LILEQDOC7LVRV27EAN X-Message-ID-Hash: PPLTFF6CTFKTN3LILEQDOC7LVRV27EAN X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706635809215100001 Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 - src/util/virpcivpd.c | 14 +------------- src/util/virpcivpdpriv.h | 3 --- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 89b0d01de6..035f8c7b5d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3700,7 +3700,6 @@ virVHBAPathExists; # util/virpcivpd.h virPCIVPDParse; -virPCIVPDParseVPDLargeResourceString; virPCIVPDResourceCustomCompareIndex; virPCIVPDResourceCustomFree; virPCIVPDResourceCustomUpsertValue; diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 510be65cb6..b303e161ae 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -595,7 +595,7 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uin= t16_t resPos, uint16_t re * Returns: a pointer to a VPDResource which needs to be freed by the call= er or * NULL if getting it failed for some reason. */ -bool +static bool virPCIVPDParseVPDLargeResourceString(int vpdFileFd, uint16_t resPos, uint16_t resDataLen, uint8_t *csum, v= irPCIVPDResource *res) { @@ -732,18 +732,6 @@ virPCIVPDParse(int vpdFileFd) #else /* ! __linux__ */ -bool -virPCIVPDParseVPDLargeResourceString(int vpdFileFd G_GNUC_UNUSED, - uint16_t resPos G_GNUC_UNUSED, - uint16_t resDataLen G_GNUC_UNUSED, - uint8_t *csum G_GNUC_UNUSED, - virPCIVPDResource *res G_GNUC_UNUSED) -{ - virReportError(VIR_ERR_NO_SUPPORT, "%s", - _("PCI VPD reporting not available on this platform")); - return false; -} - virPCIVPDResource * virPCIVPDParse(int vpdFileFd G_GNUC_UNUSED) { diff --git a/src/util/virpcivpdpriv.h b/src/util/virpcivpdpriv.h index d84f1e9c8a..617991930b 100644 --- a/src/util/virpcivpdpriv.h +++ b/src/util/virpcivpdpriv.h @@ -68,6 +68,3 @@ virPCIVPDResourceCustomCompareIndex(virPCIVPDResourceCust= om *a, virPCIVPDResourc bool virPCIVPDResourceCustomUpsertValue(GPtrArray *arr, char index, const char = *const value); - -bool virPCIVPDParseVPDLargeResourceString(int vpdFileFd, uint16_t resPos, = uint16_t resDataLen, - uint8_t *csum, virPCIVPDResource= *res); --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706635680960444.99682096618085; Tue, 30 Jan 2024 09:28:00 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id D750A1EB7; Tue, 30 Jan 2024 12:27:59 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2B07B1D47; Tue, 30 Jan 2024 12:09:59 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 990081CF6; Tue, 30 Jan 2024 12:09:27 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A378F1CF6 for ; Tue, 30 Jan 2024 12:08:26 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-665-VyYUx-81PeKM9BsnKcAf5g-1; Tue, 30 Jan 2024 12:08:24 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D6C3F83538F for ; Tue, 30 Jan 2024 17:08:23 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E8CA2166B31 for ; Tue, 30 Jan 2024 17:08:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: VyYUx-81PeKM9BsnKcAf5g-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 13/31] virPCIVPDResourceGetKeywordPrefix: Fix logging Date: Tue, 30 Jan 2024 18:07:51 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: UFEGAEG5DTHOE72UJP4CITCAHFXF2V55 X-Message-ID-Hash: UFEGAEG5DTHOE72UJP4CITCAHFXF2V55 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706635682854100001 Use VIR_DEBUG instead of VIR_INFO as that's more appropriate and report relevant information for debugging. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index b303e161ae..67065dec46 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -61,20 +61,20 @@ virPCIVPDResourceGetKeywordPrefix(const char *keyword) g_autofree char *key =3D NULL; /* Keywords must have a length of 2 bytes. */ - if (strlen(keyword) !=3D 2) { - VIR_INFO("The keyword length is not 2 bytes: %s", keyword); - return NULL; - } else if (!(virPCIVPDResourceIsUpperOrNumber(keyword[0]) && - virPCIVPDResourceIsUpperOrNumber(keyword[1]))) { - VIR_INFO("The keyword is not comprised only of uppercase ASCII let= ters or digits"); - return NULL; - } + if (strlen(keyword) !=3D 2 || + !(virPCIVPDResourceIsUpperOrNumber(keyword[0]) && + virPCIVPDResourceIsUpperOrNumber(keyword[1]))) + goto cleanup; + /* Special-case the system-specific keywords since they share the "Y" = prefix with "YA". */ if (virPCIVPDResourceIsSystemKeyword(keyword) || virPCIVPDResourceIsVe= ndorKeyword(keyword)) key =3D g_strndup(keyword, 1); else key =3D g_strndup(keyword, 2); + cleanup: + VIR_DEBUG("keyword=3D'%s' key=3D'%s'", keyword, NULLSTR(key)); + return g_steal_pointer(&key); } --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706635921672566.0179622563418; Tue, 30 Jan 2024 09:32:01 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 705D91D5F; Tue, 30 Jan 2024 12:32:00 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 11B891D4B; Tue, 30 Jan 2024 12:10:16 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3E25F1D26; Tue, 30 Jan 2024 12:09:35 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 541331D07 for ; Tue, 30 Jan 2024 12:08:27 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-182-gvt4KEnCNx2vxuSAQWmdtg-1; Tue, 30 Jan 2024 12:08:25 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C00D685A58B for ; Tue, 30 Jan 2024 17:08:24 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38DE02166B31 for ; Tue, 30 Jan 2024 17:08:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: gvt4KEnCNx2vxuSAQWmdtg-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 14/31] util: virpcivpd: Remove return value from virPCIVPDResourceCustomUpsertValue Date: Tue, 30 Jan 2024 18:07:52 +0100 Message-ID: <0de49962bb2f9fe1a02c22a289fb7744bb6e91d0.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: K7OZTRRDPLHAEPSSQ6SBL4GLXDNA55CQ X-Message-ID-Hash: K7OZTRRDPLHAEPSSQ6SBL4GLXDNA55CQ X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706635923832100001 None of the callers pass NULL, so the NULL check is pointless. Remove it an remove the return value. The function is exported only for use in 'virpcivpdtest' thus marking the arguments as NONNULL is unnecessary. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 18 ++++-------------- src/util/virpcivpdpriv.h | 2 +- tests/virpcivpdtest.c | 12 ++++-------- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 67065dec46..f198faaf42 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -270,7 +270,7 @@ virPCIVPDResourceCustomCompareIndex(virPCIVPDResourceCu= stom *a, virPCIVPDResourc * * Returns: true if a value has been updated successfully, false otherwise. */ -bool +void virPCIVPDResourceCustomUpsertValue(GPtrArray *arr, char index, const char = *const value) { g_autoptr(virPCIVPDResourceCustom) custom =3D NULL; @@ -278,9 +278,6 @@ virPCIVPDResourceCustomUpsertValue(GPtrArray *arr, char= index, const char *const guint pos =3D 0; bool found =3D false; - if (arr =3D=3D NULL || value =3D=3D NULL) - return false; - custom =3D g_new0(virPCIVPDResourceCustom, 1); custom->idx =3D index; custom->value =3D g_strdup(value); @@ -294,7 +291,6 @@ virPCIVPDResourceCustomUpsertValue(GPtrArray *arr, char= index, const char *const } else { g_ptr_array_add(arr, g_steal_pointer(&custom)); } - return true; } /** @@ -348,9 +344,7 @@ virPCIVPDResourceUpdateKeyword(virPCIVPDResource *res, = const bool readOnly, res->ro->serial_number =3D g_strdup(value); return true; } else if (virPCIVPDResourceIsVendorKeyword(keyword)) { - if (!virPCIVPDResourceCustomUpsertValue(res->ro->vendor_specif= ic, keyword[1], value)) { - return false; - } + virPCIVPDResourceCustomUpsertValue(res->ro->vendor_specific, k= eyword[1], value); return true; } else if (STREQ("FG", keyword) || STREQ("LC", keyword) || STREQ("= PG", keyword)) { /* Legacy PICMIG keywords are skipped on purpose. */ @@ -371,14 +365,10 @@ virPCIVPDResourceUpdateKeyword(virPCIVPDResource *res= , const bool readOnly, res->rw->asset_tag =3D g_strdup(value); return true; } else if (virPCIVPDResourceIsVendorKeyword(keyword)) { - if (!virPCIVPDResourceCustomUpsertValue(res->rw->vendor_specif= ic, keyword[1], value)) { - return false; - } + virPCIVPDResourceCustomUpsertValue(res->rw->vendor_specific, k= eyword[1], value); return true; } else if (virPCIVPDResourceIsSystemKeyword(keyword)) { - if (!virPCIVPDResourceCustomUpsertValue(res->rw->system_specif= ic, keyword[1], value)) { - return false; - } + virPCIVPDResourceCustomUpsertValue(res->rw->system_specific, k= eyword[1], value); return true; } } diff --git a/src/util/virpcivpdpriv.h b/src/util/virpcivpdpriv.h index 617991930b..f26b64139d 100644 --- a/src/util/virpcivpdpriv.h +++ b/src/util/virpcivpdpriv.h @@ -66,5 +66,5 @@ bool virPCIVPDResourceIsValidTextValue(const char *value); gboolean virPCIVPDResourceCustomCompareIndex(virPCIVPDResourceCustom *a, virPCIVPDR= esourceCustom *b); -bool +void virPCIVPDResourceCustomUpsertValue(GPtrArray *arr, char index, const char = *const value); diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index fddb42f52c..8a2f337e85 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -244,8 +244,7 @@ testPCIVPDResourceCustomUpsertValue(const void *data G_= GNUC_UNUSED) { g_autoptr(GPtrArray) arr =3D g_ptr_array_new_full(0, (GDestroyNotify)v= irPCIVPDResourceCustomFree); virPCIVPDResourceCustom *custom =3D NULL; - if (!virPCIVPDResourceCustomUpsertValue(arr, 'A', "testval")) - return -1; + virPCIVPDResourceCustomUpsertValue(arr, 'A', "testval"); if (arr->len !=3D 1) return -1; @@ -255,8 +254,7 @@ testPCIVPDResourceCustomUpsertValue(const void *data G_= GNUC_UNUSED) return -1; /* Idempotency */ - if (!virPCIVPDResourceCustomUpsertValue(arr, 'A', "testval")) - return -1; + virPCIVPDResourceCustomUpsertValue(arr, 'A', "testval"); if (arr->len !=3D 1) return -1; @@ -266,8 +264,7 @@ testPCIVPDResourceCustomUpsertValue(const void *data G_= GNUC_UNUSED) return -1; /* Existing value updates. */ - if (!virPCIVPDResourceCustomUpsertValue(arr, 'A', "testvalnew")) - return -1; + virPCIVPDResourceCustomUpsertValue(arr, 'A', "testvalnew"); if (arr->len !=3D 1) return -1; @@ -277,8 +274,7 @@ testPCIVPDResourceCustomUpsertValue(const void *data G_= GNUC_UNUSED) return -1; /* Inserting multiple values */ - if (!virPCIVPDResourceCustomUpsertValue(arr, '1', "42")) - return -1; + virPCIVPDResourceCustomUpsertValue(arr, '1', "42"); if (arr->len !=3D 2) return -1; --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:11 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706636020731917.6066263855457; Tue, 30 Jan 2024 09:33:40 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8A94D1D5F; Tue, 30 Jan 2024 12:33:39 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 360991C4F; Tue, 30 Jan 2024 12:10:25 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 50BE01D69; Tue, 30 Jan 2024 12:09:45 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id C43CF1D0D for ; Tue, 30 Jan 2024 12:08:27 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-379-gXp7zrPUOj6hInTZRcZFuA-1; Tue, 30 Jan 2024 12:08:25 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AC65F1C05139 for ; Tue, 30 Jan 2024 17:08:25 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 220942166B31 for ; Tue, 30 Jan 2024 17:08:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: gXp7zrPUOj6hInTZRcZFuA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 15/31] conf: virNodeDeviceCapVPDParse*: Remove pointless NULL checks Date: Tue, 30 Jan 2024 18:07:53 +0100 Message-ID: <116b3d3e4945b9fd5927ccdd54f794e3ef36cfbb.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: BRZMY6ZPR3XLZ7ELSH772RQ7L22LXUDZ X-Message-ID-Hash: BRZMY6ZPR3XLZ7ELSH772RQ7L22LXUDZ X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706636022188100001 The function are never called with NULL argument so the checks can be removed. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/node_device_conf.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index dd174d3020..d7e1a23034 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -1023,9 +1023,6 @@ virNodeDeviceCapVPDParseReadOnlyFields(xmlXPathContex= tPtr ctxt, virPCIVPDResourc "serial_number", "part_number", NULL}; size_t i =3D 0; - if (res =3D=3D NULL) - return -1; - res->ro =3D virPCIVPDResourceRONew(); while (keywords[i]) { @@ -1061,9 +1058,6 @@ virNodeDeviceCapVPDParseXML(xmlXPathContextPtr ctxt, = virPCIVPDResource **res) size_t i =3D 0; g_autoptr(virPCIVPDResource) newres =3D g_new0(virPCIVPDResource, 1); - if (res =3D=3D NULL) - return -1; - if (!(newres->name =3D virXPathString("string(./name)", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Could not read a device name from the element")); --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706636109507923.6672343974843; Tue, 30 Jan 2024 09:35:09 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 6C73D1C3E; Tue, 30 Jan 2024 12:35:08 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id F2BD21D8B; Tue, 30 Jan 2024 12:10:32 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id D499D1D3D; Tue, 30 Jan 2024 12:09:45 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id CEA751D14 for ; Tue, 30 Jan 2024 12:08:28 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-296-D_68AgpnN6KG-LR-qlEAgg-1; Tue, 30 Jan 2024 12:08:26 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9E76483538D for ; Tue, 30 Jan 2024 17:08:26 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16EAE2166B31 for ; Tue, 30 Jan 2024 17:08:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: D_68AgpnN6KG-LR-qlEAgg-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 16/31] virpcivpdtest: testPCIVPDResourceBasic: Remove tests for uninitialized 'ro'/'rw' section Date: Tue, 30 Jan 2024 18:07:54 +0100 Message-ID: <8a8423965c1cddc4b110cbde39252555d08978e7.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 5MVYG2KU5B7KJ5UKF4FHFVCUWH5ZCMH3 X-Message-ID-Hash: 5MVYG2KU5B7KJ5UKF4FHFVCUWH5ZCMH3 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706636110494100001 This is a synthetic case which tests the behaviour if the 'ro' or 'rw' struct members are uninitialized, basically excercising only a pointless programming-error NULL check in 'virPCIVPDResourceUpdateKeyword' as real usage does always pass a proper pointer. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/virpcivpdtest.c | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index 8a2f337e85..20545759d5 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -64,11 +64,6 @@ testPCIVPDResourceBasic(const void *data G_GNUC_UNUSED) {.keyword =3D "SN", .value =3D "serial2", .actual =3D &ro->serial_= number}, {.keyword =3D "serial_number", .value =3D "serial3", .actual =3D &= ro->serial_number}, }; - const TestPCIVPDKeywordValue readWriteCases[] =3D { - {.keyword =3D "YA", .value =3D "tag1", .actual =3D &ro->change_lev= el}, - {.keyword =3D "YA", .value =3D "tag2", .actual =3D &ro->change_lev= el}, - {.keyword =3D "asset_tag", .value =3D "tag3", .actual =3D &ro->cha= nge_level}, - }; const TestPCIVPDKeywordValue unsupportedFieldCases[] =3D { {.keyword =3D "FG", .value =3D "42", .actual =3D NULL}, {.keyword =3D "LC", .value =3D "42", .actual =3D NULL}, @@ -77,7 +72,6 @@ testPCIVPDResourceBasic(const void *data G_GNUC_UNUSED) {.keyword =3D "EX", .value =3D "42", .actual =3D NULL}, }; 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; @@ -85,20 +79,6 @@ testPCIVPDResourceBasic(const void *data G_GNUC_UNUSED) g_autofree char *val =3D g_strdup("testval"); res->name =3D g_steal_pointer(&val); - /* RO has not been initialized - make sure updates fail. */ - for (i =3D 0; i < numROCases; ++i) { - if (virPCIVPDResourceUpdateKeyword(res, true, - readOnlyCases[i].keyword, - readOnlyCases[i].value)) - return -1; - } - /* RW has not been initialized - make sure updates fail. */ - for (i =3D 0; i < numRWCases; ++i) { - if (virPCIVPDResourceUpdateKeyword(res, false, - readWriteCases[i].keyword, - readWriteCases[i].value)) - return -1; - } /* Initialize RO */ res->ro =3D g_steal_pointer(&ro); @@ -131,13 +111,6 @@ testPCIVPDResourceBasic(const void *data G_GNUC_UNUSED) return -1; } - /* Check that RW updates fail if RW has not been initialized. */ - if (virPCIVPDResourceUpdateKeyword(res, false, "YA", "tag1")) - return -1; - - if (virPCIVPDResourceUpdateKeyword(res, false, "asset_tag", "tag1")) - return -1; - /* Initialize RW */ res->rw =3D g_steal_pointer(&rw); if (!virPCIVPDResourceUpdateKeyword(res, false, "YA", "tag1") --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706636193054591.0637426956009; Tue, 30 Jan 2024 09:36:33 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id F208D1D44; Tue, 30 Jan 2024 12:36:31 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 136471D91; Tue, 30 Jan 2024 12:10:42 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 5722E1D0D; Tue, 30 Jan 2024 12:09:48 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 21B291D15 for ; Tue, 30 Jan 2024 12:08:30 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-457-mP0gxa6KN-23sQr-Lek3uw-1; Tue, 30 Jan 2024 12:08:28 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 98EAE1C05156 for ; Tue, 30 Jan 2024 17:08:27 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 005F92166B31 for ; Tue, 30 Jan 2024 17:08:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: mP0gxa6KN-23sQr-Lek3uw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 17/31] util: virPCIVPDResourceUpdateKeyword: Remove impossible checks Date: Tue, 30 Jan 2024 18:07:55 +0100 Message-ID: <396728e352291507eabbdad6adc0908d6916d722.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: N62R36AD2AL3LS4TWR6NK6APP3C36OEX X-Message-ID-Hash: N62R36AD2AL3LS4TWR6NK6APP3C36OEX X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706636195295100001 All callers satisfy these callers as they are just for programming errors. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index f198faaf42..3beb405252 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -313,20 +313,7 @@ bool virPCIVPDResourceUpdateKeyword(virPCIVPDResource *res, const bool readOnly, const char *const keyword, const char *cons= t value) { - if (!res) { - VIR_INFO("Cannot update the resource: a NULL resource pointer has = been provided."); - return false; - } else if (!keyword) { - VIR_INFO("Cannot update the resource: a NULL keyword pointer has b= een provided."); - return false; - } - if (readOnly) { - if (!res->ro) { - VIR_INFO("Cannot update the read-only keyword: RO section not = initialized."); - return false; - } - if (STREQ("EC", keyword) || STREQ("change_level", keyword)) { g_free(res->ro->change_level); res->ro->change_level =3D g_strdup(value); @@ -353,13 +340,7 @@ virPCIVPDResourceUpdateKeyword(virPCIVPDResource *res,= const bool readOnly, /* The CP keyword is currently not supported and is skipped. */ return true; } - } else { - if (!res->rw) { - VIR_INFO("Cannot update the read-write keyword: read-write sec= tion not initialized."); - return false; - } - if (STREQ("YA", keyword) || STREQ("asset_tag", keyword)) { g_free(res->rw->asset_tag); res->rw->asset_tag =3D g_strdup(value); --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 17066364177811009.9363040377983; Tue, 30 Jan 2024 09:40:17 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9B4061D4B; Tue, 30 Jan 2024 12:40:16 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 6E6861DA3; Tue, 30 Jan 2024 12:11:00 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9994A1CBC; Tue, 30 Jan 2024 12:09:56 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 96F4E1C19 for ; Tue, 30 Jan 2024 12:08:31 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-HR-0Ij-wOQ-WvJ6wsXb7qA-1; Tue, 30 Jan 2024 12:08:29 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 130E03814E8B for ; Tue, 30 Jan 2024 17:08:29 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21E4F2166B31 for ; Tue, 30 Jan 2024 17:08:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: HR-0Ij-wOQ-WvJ6wsXb7qA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 18/31] conf: node_device: Refactor 'virNodeDeviceCapVPDParseCustomFields' to fix error reporting Date: Tue, 30 Jan 2024 18:07:56 +0100 Message-ID: <6ae63db9573885b9ff656b5a1192c40db7e438b9.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: SIBGA6ZKIL62BY3LEIO6VVTIP4P2P6JF X-Message-ID-Hash: SIBGA6ZKIL62BY3LEIO6VVTIP4P2P6JF X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706636419430100001 The errors raised in virNodeDeviceCapVPDParseCustomFields were actually ignored by continuing the parse rather than raised. Rather than just replace 'continue' by 'return -1' this patch refactors the whole parser to simplify it as well as report reasonable errors. Parsing of individual fields is done without XPath and is extracted into a common helper. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/node_device_conf.c | 81 ++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index d7e1a23034..0f2c341967 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -953,63 +953,62 @@ virNodeDevCapMdevTypesParseXML(xmlXPathContextPtr ctx= t, return ret; } + static int -virNodeDeviceCapVPDParseCustomFields(xmlXPathContextPtr ctxt, virPCIVPDRes= ource *res, bool readOnly) +virNodeDeviceCapVPDParseCustomFieldOne(xmlNodePtr node, + virPCIVPDResource *res, + bool read_only, + const char keyword_prefix) +{ + g_autofree char *value =3D NULL; + g_autofree char *index =3D NULL; + g_autofree char *keyword =3D NULL; + + if (!(index =3D virXMLPropStringRequired(node, "index"))) + return -1; + + if (strlen(index) !=3D 1) { + virReportError(VIR_ERR_XML_ERROR, + _("'%1$s' 'index' value '%2$s' malformed"), + node->name, index); + return -1; + } + + keyword =3D g_strdup_printf("%c%c", keyword_prefix, index[0]); + + if (!(value =3D virXMLNodeContentString(node))) + return -1; + + virPCIVPDResourceUpdateKeyword(res, read_only, keyword, value); + return 0; +} + + +static int +virNodeDeviceCapVPDParseCustomFields(xmlXPathContextPtr ctxt, + virPCIVPDResource *res, + bool readOnly) { int nfields =3D -1; g_autofree xmlNodePtr *nodes =3D NULL; size_t i =3D 0; - if ((nfields =3D virXPathNodeSet("./vendor_field[@index]", ctxt, &node= s)) < 0) + if ((nfields =3D virXPathNodeSet("./vendor_field", ctxt, &nodes)) < 0) 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 virXPathString("string(./@index[1])", ctxt)) || - strlen(index) > 1) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _(" evaluation has failed")); - continue; - } - if (!(value =3D virXPathString("string(./text())", ctxt))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _(" value evaluation has failed")); - continue; - } - keyword =3D g_strdup_printf("V%c", index[0]); - virPCIVPDResourceUpdateKeyword(res, readOnly, keyword, value); + if (virNodeDeviceCapVPDParseCustomFieldOne(nodes[i], res, readOnly= , 'V') < 0) + return -1; } VIR_FREE(nodes); if (!readOnly) { - if ((nfields =3D virXPathNodeSet("./system_field[@index]", ctxt, &= nodes)) < 0) + if ((nfields =3D virXPathNodeSet("./system_field", ctxt, &nodes)) = < 0) 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 virXPathString("string(./@index[1])", ctxt)) || - strlen(index) > 1) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _(" evaluation has failed")); - continue; - } - if (!(value =3D virXPathString("string(./text())", ctxt))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _(" value evaluation has failed")); - continue; - } - keyword =3D g_strdup_printf("Y%c", index[0]); - virPCIVPDResourceUpdateKeyword(res, readOnly, keyword, value); + if (virNodeDeviceCapVPDParseCustomFieldOne(nodes[i], res, read= Only, 'Y') < 0) + return -1; } } --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706636285640528.0295495174882; Tue, 30 Jan 2024 09:38:05 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8F1A717EC; Tue, 30 Jan 2024 12:38:04 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id CD9541D9C; Tue, 30 Jan 2024 12:10:51 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id EE2441C95; Tue, 30 Jan 2024 12:09:55 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A80B01C58 for ; Tue, 30 Jan 2024 12:08:33 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-353-gtx0zBtCMeCSZxzq-GhRNQ-1; Tue, 30 Jan 2024 12:08:31 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9D54B84AE41 for ; Tue, 30 Jan 2024 17:08:31 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04F252166B31 for ; Tue, 30 Jan 2024 17:08:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: gtx0zBtCMeCSZxzq-GhRNQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 19/31] virNodeDeviceCapVPDParseXML: Fix error reporting Date: Tue, 30 Jan 2024 18:07:57 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: PT4AFHWK2VOZQGXSEDMPXUAA4ACKX2NU X-Message-ID-Hash: PT4AFHWK2VOZQGXSEDMPXUAA4ACKX2NU X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706636287074100001 Don't overwrite already reported errors and improve parsing of attributes. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/node_device_conf.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 0f2c341967..c68ac3af78 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -1059,11 +1059,11 @@ virNodeDeviceCapVPDParseXML(xmlXPathContextPtr ctxt= , virPCIVPDResource **res) if (!(newres->name =3D virXPathString("string(./name)", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", - _("Could not read a device name from the element")); + _("Could not read a device name from the ele= ment")); return -1; } - if ((nfields =3D virXPathNodeSet("./fields[@access]", ctxt, &nodes)) <= 0) + if ((nfields =3D virXPathNodeSet("./fields", ctxt, &nodes)) < 0) return -1; for (i =3D 0; i < nfields; i++) { @@ -1071,27 +1071,19 @@ virNodeDeviceCapVPDParseXML(xmlXPathContextPtr ctxt= , virPCIVPDResource **res) 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")); + + if (!(access =3D virXMLPropStringRequired(nodes[i], "access"))) return -1; - } if (STREQ(access, "readonly")) { - if (virNodeDeviceCapVPDParseReadOnlyFields(ctxt, newres) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Could not parse %1$s VPD resource fields"), acc= ess); + if (virNodeDeviceCapVPDParseReadOnlyFields(ctxt, newres) < 0) return -1; - } } else if (STREQ(access, "readwrite")) { - if (virNodeDeviceCapVPDParseReadWriteFields(ctxt, newres) < 0)= { - virReportError(VIR_ERR_XML_ERROR, - _("Could not parse %1$s VPD resource fields"), acc= ess); + if (virNodeDeviceCapVPDParseReadWriteFields(ctxt, newres) < 0) return -1; - } } else { virReportError(VIR_ERR_XML_ERROR, - _("Unsupported VPD field access type specified = %1$s"), + _("Unsupported VPD field access type '%1$s'"), access); return -1; } --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706637051288796.4341777975905; Tue, 30 Jan 2024 09:50:51 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 35D0A1E88; Tue, 30 Jan 2024 12:50:50 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3E8461CB8; Tue, 30 Jan 2024 12:11:40 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9CB031C07; Tue, 30 Jan 2024 12:10:18 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 05E561D28 for ; Tue, 30 Jan 2024 12:08:34 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-562-XGfT887eMh6O3m9LZfhNxA-1; Tue, 30 Jan 2024 12:08:32 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8AAC8185A786 for ; Tue, 30 Jan 2024 17:08:32 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id F319D2166B31 for ; Tue, 30 Jan 2024 17:08:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: XGfT887eMh6O3m9LZfhNxA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 20/31] util: virpcivpd: Remove return value from virPCIVPDResourceUpdateKeyword Date: Tue, 30 Jan 2024 18:07:58 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: W4MOL45ZZSV7FMOSOIECVAEXWUW7XAIZ X-Message-ID-Hash: W4MOL45ZZSV7FMOSOIECVAEXWUW7XAIZ X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706637053189100001 The function always succeeded and after the removal of programing error checks doesn't even have a 'return false' case. Additionally one of the tests in 'virpcivpdtest' tested that this function never failed on wrong data. Embrace this logic and remove the return value and adjust logging to VIR_DEBUG level to avoid spamming logs. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 31 +++++++++++-------------------- src/util/virpcivpd.h | 8 +++++--- tests/virpcivpdtest.c | 38 ++++++++++++++++++-------------------- 3 files changed, 34 insertions(+), 43 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 3beb405252..0021a88f2d 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -307,54 +307,48 @@ virPCIVPDResourceCustomUpsertValue(GPtrArray *arr, ch= ar index, const char *const * used in XML elements. For vendor-specific and system-specific keywords = only V%s and Y%s * (except "YA" which is an asset tag) formatted values are accepted. * - * Returns: true if a keyword has been updated successfully, false otherwi= se. + * Unknown or malformed values are ignored. */ -bool -virPCIVPDResourceUpdateKeyword(virPCIVPDResource *res, const bool readOnly, - const char *const keyword, const char *cons= t value) +void +virPCIVPDResourceUpdateKeyword(virPCIVPDResource *res, + const bool readOnly, + const char *const keyword, + const char *const value) { if (readOnly) { if (STREQ("EC", keyword) || STREQ("change_level", keyword)) { g_free(res->ro->change_level); res->ro->change_level =3D g_strdup(value); - return true; } else if (STREQ("MN", keyword) || STREQ("manufacture_id", keyword= )) { g_free(res->ro->manufacture_id); res->ro->manufacture_id =3D g_strdup(value); - return true; } else if (STREQ("PN", keyword) || STREQ("part_number", keyword)) { g_free(res->ro->part_number); res->ro->part_number =3D g_strdup(value); - return true; } else if (STREQ("SN", keyword) || STREQ("serial_number", keyword)= ) { g_free(res->ro->serial_number); res->ro->serial_number =3D g_strdup(value); - return true; } else if (virPCIVPDResourceIsVendorKeyword(keyword)) { virPCIVPDResourceCustomUpsertValue(res->ro->vendor_specific, k= eyword[1], value); - return true; } else if (STREQ("FG", keyword) || STREQ("LC", keyword) || STREQ("= PG", keyword)) { /* Legacy PICMIG keywords are skipped on purpose. */ - return true; } else if (STREQ("CP", keyword)) { /* The CP keyword is currently not supported and is skipped. */ - return true; + } else { + VIR_DEBUG("unhandled PCI VPD r/o keyword '%s'(val=3D'%s')", ke= yword, value); } } else { if (STREQ("YA", keyword) || STREQ("asset_tag", keyword)) { g_free(res->rw->asset_tag); res->rw->asset_tag =3D g_strdup(value); - return true; } else if (virPCIVPDResourceIsVendorKeyword(keyword)) { virPCIVPDResourceCustomUpsertValue(res->rw->vendor_specific, k= eyword[1], value); - return true; } else if (virPCIVPDResourceIsSystemKeyword(keyword)) { virPCIVPDResourceCustomUpsertValue(res->rw->system_specific, k= eyword[1], value); - return true; + } else { + VIR_DEBUG("unhandled PCI VPD r/w keyword '%s'(val=3D'%s')", ke= yword, value); } } - VIR_WARN("Tried to update an unsupported keyword %s: skipping.", keywo= rd); - return true; } #ifdef __linux__ @@ -527,10 +521,7 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, ui= nt16_t resPos, uint16_t re res->rw =3D virPCIVPDResourceRWNew(); } /* The field format, keyword and value are determined. Attempt to = update the resource. */ - if (!virPCIVPDResourceUpdateKeyword(res, readOnly, fieldKeyword, f= ieldValue)) { - VIR_INFO("Could not update the VPD resource keyword: %s", fiel= dKeyword); - return false; - } + virPCIVPDResourceUpdateKeyword(res, readOnly, fieldKeyword, fieldV= alue); } /* May have exited the loop prematurely in case RV or RW were encounte= red and diff --git a/src/util/virpcivpd.h b/src/util/virpcivpd.h index 9bfec43e03..d8d3dd3075 100644 --- a/src/util/virpcivpd.h +++ b/src/util/virpcivpd.h @@ -67,9 +67,11 @@ void virPCIVPDResourceRWFree(virPCIVPDResourceRW *rw); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIVPDResourceRW, virPCIVPDResourceRWFree= ); -bool -virPCIVPDResourceUpdateKeyword(virPCIVPDResource *res, const bool readOnly, - const char *const keyword, const char *cons= t value); +void +virPCIVPDResourceUpdateKeyword(virPCIVPDResource *res, + const bool readOnly, + const char *const keyword, + const char *const value); void virPCIVPDResourceCustomFree(virPCIVPDResourceCustom *custom); diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index 20545759d5..a6311bfe76 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -84,17 +84,15 @@ testPCIVPDResourceBasic(const void *data G_GNUC_UNUSED) /* Update keywords one by one and compare actual values with the expec= ted ones. */ for (i =3D 0; i < numROCases; ++i) { - if (!virPCIVPDResourceUpdateKeyword(res, true, - readOnlyCases[i].keyword, - readOnlyCases[i].value)) - return -1; + virPCIVPDResourceUpdateKeyword(res, true, + readOnlyCases[i].keyword, + readOnlyCases[i].value); if (STRNEQ(readOnlyCases[i].value, *readOnlyCases[i].actual)) return -1; } /* Do a basic vendor field check. */ - if (!virPCIVPDResourceUpdateKeyword(res, true, "V0", "vendor0")) - return -1; + virPCIVPDResourceUpdateKeyword(res, true, "V0", "vendor0"); if (res->ro->vendor_specific->len !=3D 1) return -1; @@ -105,25 +103,23 @@ testPCIVPDResourceBasic(const void *data G_GNUC_UNUSE= D) /* Make sure unsupported RO keyword updates are not fatal. */ for (i =3D 0; i < numUnsupportedCases; ++i) { - if (!virPCIVPDResourceUpdateKeyword(res, true, - unsupportedFieldCases[i].keywo= rd, - unsupportedFieldCases[i].value= )) - return -1; + virPCIVPDResourceUpdateKeyword(res, true, + unsupportedFieldCases[i].keyword, + unsupportedFieldCases[i].value); } /* Initialize RW */ res->rw =3D g_steal_pointer(&rw); - if (!virPCIVPDResourceUpdateKeyword(res, false, "YA", "tag1") - || STRNEQ(res->rw->asset_tag, "tag1")) + virPCIVPDResourceUpdateKeyword(res, false, "YA", "tag1"); + if (STRNEQ(res->rw->asset_tag, "tag1")) return -1; - if (!virPCIVPDResourceUpdateKeyword(res, false, "asset_tag", "tag2") - || STRNEQ(res->rw->asset_tag, "tag2")) + virPCIVPDResourceUpdateKeyword(res, false, "asset_tag", "tag2"); + if (STRNEQ(res->rw->asset_tag, "tag2")) return -1; /* Do a basic system field check. */ - if (!virPCIVPDResourceUpdateKeyword(res, false, "Y0", "system0")) - return -1; + virPCIVPDResourceUpdateKeyword(res, false, "Y0", "system0"); if (res->rw->system_specific->len !=3D 1) return -1; @@ -134,10 +130,12 @@ testPCIVPDResourceBasic(const void *data G_GNUC_UNUSE= D) /* Make sure unsupported RW keyword updates are not fatal. */ for (i =3D 0; i < numUnsupportedCases; ++i) { - if (!virPCIVPDResourceUpdateKeyword(res, false, - unsupportedFieldCases[i].keywo= rd, - unsupportedFieldCases[i].value= )) - return -1; + /* This test is deliberately left in despite + * virPCIVPDResourceUpdateKeyword always succeeding to prevent + * possible regressions if the function is ever rewritten */ + virPCIVPDResourceUpdateKeyword(res, false, + unsupportedFieldCases[i].keyword, + unsupportedFieldCases[i].value); } --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706636762011153.34135014756328; Tue, 30 Jan 2024 09:46:02 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id E350C1DBA; Tue, 30 Jan 2024 12:46:00 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 55FC51D68; Tue, 30 Jan 2024 12:11:17 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4F3301D89; Tue, 30 Jan 2024 12:10:16 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 555CF1C62 for ; Tue, 30 Jan 2024 12:08:36 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-6XmBcWqxOiCJVQ3mcDMRCw-1; Tue, 30 Jan 2024 12:08:34 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BFFD63CBD501 for ; Tue, 30 Jan 2024 17:08:33 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF87B2166B31 for ; Tue, 30 Jan 2024 17:08:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: 6XmBcWqxOiCJVQ3mcDMRCw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 21/31] virPCIDeviceHasVPD: Refactor "debug" messages Date: Tue, 30 Jan 2024 18:07:59 +0100 Message-ID: <26188f865bd956f5ac5ff1c45ab3d5bbe1fd63c1.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 6BUJRPCQMWPN7QIJS3PXSUJJ5BYIZJJG X-Message-ID-Hash: 6BUJRPCQMWPN7QIJS3PXSUJJ5BYIZJJG X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706636762521100001 A checker function should not raise VIR_INFO or VIR_WARN messages especially if they contain information useful only for debugging. Turn the message into a VIR_DEBUG with universal meaning. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpci.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 6c04e57038..99e6e6cbb1 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -3081,17 +3081,12 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_d= evice_path, bool virPCIDeviceHasVPD(virPCIDevice *dev) { - g_autofree char *vpdPath =3D NULL; + g_autofree char *vpdPath =3D virPCIFile(dev->name, "vpd"); + bool ret =3D virFileIsRegular(vpdPath); - vpdPath =3D virPCIFile(dev->name, "vpd"); - if (!virFileExists(vpdPath)) { - VIR_INFO("Device VPD file does not exist %s", vpdPath); - return false; - } else if (!virFileIsRegular(vpdPath)) { - VIR_WARN("VPD path does not point to a regular file %s", vpdPath); - return false; - } - return true; + VIR_DEBUG("path=3D'%s', exists=3D'%d'", vpdPath, ret); + + return ret; } /** --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706636848247134.83604911651685; Tue, 30 Jan 2024 09:47:28 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1DFDC1852; Tue, 30 Jan 2024 12:47:25 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 674711DC6; Tue, 30 Jan 2024 12:11:24 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 82B871C46; Tue, 30 Jan 2024 12:10:17 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id C3C8A1C67 for ; Tue, 30 Jan 2024 12:08:37 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-426-d53GLvTWMMmIerGfCz66RQ-1; Tue, 30 Jan 2024 12:08:35 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C0CFF84AE41 for ; Tue, 30 Jan 2024 17:08:34 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B3B92166B31 for ; Tue, 30 Jan 2024 17:08:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: d53GLvTWMMmIerGfCz66RQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 22/31] virPCIDeviceGetVPD: Fix multiple error handling bugs Date: Tue, 30 Jan 2024 18:08:00 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: ZY7ATRWYTOFLY5XDPAGJ2RVIRKETWNRA X-Message-ID-Hash: ZY7ATRWYTOFLY5XDPAGJ2RVIRKETWNRA X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706636848661100001 - fix passing of 'errno' to 'virReportSystemError' The 'open' syscall returns '-1' and sets 'errno' on failure. The code passed '-fd' as 'errno' rather than errno itself, thus always reporting EPERM. - don't overwrite errors when closing FD Use VIR_AUTOCLOSE to avoid overwriting the errors from virPCIVPDParse. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpci.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 99e6e6cbb1..780b4f9eec 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -3103,28 +3103,21 @@ virPCIDeviceHasVPD(virPCIDevice *dev) virPCIVPDResource * virPCIDeviceGetVPD(virPCIDevice *dev) { - g_autofree char *vpdPath =3D NULL; - int fd; - g_autoptr(virPCIVPDResource) res =3D NULL; + g_autofree char *vpdPath =3D virPCIFile(dev->name, "vpd"); + VIR_AUTOCLOSE fd =3D -1; - vpdPath =3D virPCIFile(dev->name, "vpd"); if (!virPCIDeviceHasVPD(dev)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Device %1$s does not hav= e a VPD"), - virPCIDeviceGetName(dev)); - return NULL; - } - if ((fd =3D open(vpdPath, O_RDONLY)) < 0) { - virReportSystemError(-fd, _("Failed to open a VPD file '%1$s'"), v= pdPath); + virPCIDeviceGetName(dev)); return NULL; } - res =3D virPCIVPDParse(fd); - if (VIR_CLOSE(fd) < 0) { - virReportSystemError(errno, _("Unable to close the VPD file, fd: %= 1$d"), fd); + if ((fd =3D open(vpdPath, O_RDONLY)) < 0) { + virReportSystemError(errno, _("Failed to open a VPD file '%1$s'"),= vpdPath); return NULL; } - return g_steal_pointer(&res); + return virPCIVPDParse(fd); } #else --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 170663692707217.76991362437252; Tue, 30 Jan 2024 09:48:47 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 042211DC6; Tue, 30 Jan 2024 12:48:46 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 470481D1C; Tue, 30 Jan 2024 12:11:32 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 209391C67; Tue, 30 Jan 2024 12:10:18 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 3203C1C07 for ; Tue, 30 Jan 2024 12:08:38 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-478-ng3GCRJfMfuzWk1hV7kJjw-1; Tue, 30 Jan 2024 12:08:35 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AE232846D67 for ; Tue, 30 Jan 2024 17:08:35 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27BA12166B31 for ; Tue, 30 Jan 2024 17:08:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: ng3GCRJfMfuzWk1hV7kJjw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 23/31] virPCIDeviceGetVPD: Handle errors in callers Date: Tue, 30 Jan 2024 18:08:01 +0100 Message-ID: <7c6af312a2dee26d61d2c63efa4ef321e4da8ba9.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 4YT4LFJSY3OLAXRPEZXPTVHIGNQ77GP6 X-Message-ID-Hash: 4YT4LFJSY3OLAXRPEZXPTVHIGNQ77GP6 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706636928909100001 Until now 'virPCIDeviceGetVPD' couldn't reallistically raise an error, but that will change. Handle the errors by either resetting it if we'd be ignoring it or forward it. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/node_device_conf.c | 2 ++ tests/virpcitest.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index c68ac3af78..b8c91d6ecd 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -3052,6 +3052,8 @@ virNodeDeviceGetPCIVPDDynamicCap(virNodeDevCapPCIDev = *devCapPCIDev) if ((res =3D virPCIDeviceGetVPD(pciDev))) { devCapPCIDev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VPD; devCapPCIDev->vpd =3D g_steal_pointer(&res); + } else { + virResetLastError(); } } return 0; diff --git a/tests/virpcitest.c b/tests/virpcitest.c index d69a1b5118..017c283a44 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -344,7 +344,8 @@ testVirPCIDeviceGetVPD(const void *opaque) if (!dev) return -1; - res =3D virPCIDeviceGetVPD(dev); + if (!(res =3D virPCIDeviceGetVPD(dev))) + return -1; /* Only basic checks - full parser validation is done elsewhere. */ if (res->ro =3D=3D NULL) --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 17066376429121012.765302844204; Tue, 30 Jan 2024 10:00:42 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id CE7121E15; Tue, 30 Jan 2024 13:00:41 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id AF4631D27; Tue, 30 Jan 2024 12:12:33 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1A85A1D90; Tue, 30 Jan 2024 12:10:42 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 88D1B1C7D for ; Tue, 30 Jan 2024 12:08:44 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-59-3rDLhzdhNneWoiGRCDQPkQ-1; Tue, 30 Jan 2024 12:08:36 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A003985A58B for ; Tue, 30 Jan 2024 17:08:36 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FA3A2166B31 for ; Tue, 30 Jan 2024 17:08:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: 3rDLhzdhNneWoiGRCDQPkQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 24/31] virPCIVPDReadVPDBytes: Refactor error handling Date: Tue, 30 Jan 2024 18:08:02 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 47J7F6TW7C66ACJNFAKS4B5QCSUF6OX7 X-Message-ID-Hash: 47J7F6TW7C66ACJNFAKS4B5QCSUF6OX7 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706637644210100001 Each caller was checking that the function read as many bytes as it expected. Move the check inside virPCIVPDReadVPDBytes and make it report a proper error rather than just a combination of VIR_DEBUG inside the function and a random VIR_INFO in the caller. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 73 +++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 0021a88f2d..10cabff0b9 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -361,34 +361,40 @@ virPCIVPDResourceUpdateKeyword(virPCIVPDResource *res, * @offset: The offset at which bytes need to be read. * @csum: A pointer to a byte containing the current checksum value. Mutat= ed by this function. * - * Returns: the number of VPD bytes read from the specified file descripto= r. The csum value is + * Returns 0 if exactly @count bytes were read from @vpdFileFd. The csum v= alue is * also modified as bytes are read. If an error occurs while reading data = from the VPD file - * descriptor, it is reported and -1 is returned to the caller. If EOF is = occurred, 0 is returned - * to the caller. + * descriptor, it is reported and -1 is returned to the caller. */ -static size_t -virPCIVPDReadVPDBytes(int vpdFileFd, uint8_t *buf, size_t count, off_t off= set, uint8_t *csum) +static int +virPCIVPDReadVPDBytes(int vpdFileFd, + uint8_t *buf, + size_t count, + off_t offset, + uint8_t *csum) { ssize_t numRead =3D pread(vpdFileFd, buf, count, offset); - if (numRead =3D=3D -1) { - VIR_DEBUG("Unable to read %zu bytes at offset %zd from fd: %d", - count, (ssize_t)offset, vpdFileFd); - } else if (numRead) { - /* - * Update the checksum for every byte read. Per the PCI(e) specs - * the checksum is correct if the sum of all bytes in VPD from - * VPD address 0 up to and including the VPD-R RV field's first - * data byte is zero. - */ - while (count--) { - *csum +=3D *buf; - buf++; - } + if (numRead !=3D count) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to read the PCI VPD data")); + return -1; + } + + /* + * Update the checksum for every byte read. Per the PCI(e) specs + * the checksum is correct if the sum of all bytes in VPD from + * VPD address 0 up to and including the VPD-R RV field's first + * data byte is zero. + */ + while (count--) { + *csum +=3D *buf; + buf++; } - return numRead; + + return 0; } + /** * virPCIVPDParseVPDLargeResourceFields: * @vpdFileFd: A file descriptor associated with a file containing PCI dev= ice VPD. @@ -423,12 +429,9 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, ui= nt16_t resPos, uint16_t re 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 - * That VPD has invalid format and bail. */ - VIR_INFO("Could not read a resource field header - VPD has inv= alid format"); + if (virPCIVPDReadVPDBytes(vpdFileFd, buf, 3, fieldPos, csum) < 0) return false; - } + fieldDataLen =3D buf[2]; /* Change the position to the field's data portion skipping the ke= yword and length bytes. */ fieldPos +=3D 3; @@ -474,10 +477,10 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, u= int16_t resPos, uint16_t re VIR_INFO("A field data length violates the resource length bou= ndary."); return false; } - if (virPCIVPDReadVPDBytes(vpdFileFd, buf, bytesToRead, fieldPos, c= sum) !=3D bytesToRead) { - VIR_INFO("Could not parse a resource field data - VPD has inva= lid format"); + + if (virPCIVPDReadVPDBytes(vpdFileFd, buf, bytesToRead, fieldPos, c= sum) < 0) return false; - } + /* Advance the position to the first byte of the next field. */ fieldPos +=3D fieldDataLen; @@ -566,10 +569,9 @@ virPCIVPDParseVPDLargeResourceString(int vpdFileFd, ui= nt16_t resPos, /* The resource value is not NULL-terminated so add one more byte. */ g_autofree char *buf =3D g_malloc0(resDataLen + 1); - if (virPCIVPDReadVPDBytes(vpdFileFd, (uint8_t *)buf, resDataLen, resPo= s, csum) !=3D resDataLen) { - VIR_INFO("Could not read a part of a resource - VPD has invalid fo= rmat"); + if (virPCIVPDReadVPDBytes(vpdFileFd, (uint8_t *)buf, resDataLen, resPo= s, csum) < 0) return false; - } + resValue =3D g_strdup(g_strstrip(buf)); if (!virPCIVPDResourceIsValidTextValue(resValue)) { VIR_INFO("The string resource has invalid characters in its value"= ); @@ -610,8 +612,8 @@ virPCIVPDParse(int vpdFileFd) while (resPos <=3D PCI_VPD_ADDR_MASK) { /* Read the resource data type tag. */ - if (virPCIVPDReadVPDBytes(vpdFileFd, &tag, 1, resPos, &csum) !=3D = 1) - break; + if (virPCIVPDReadVPDBytes(vpdFileFd, &tag, 1, resPos, &csum) < 0) + return NULL; /* 0x80 =3D=3D 0b10000000 - the large resource data type flag. */ if (tag & PCI_VPD_LARGE_RESOURCE_FLAG) { @@ -620,9 +622,10 @@ virPCIVPDParse(int vpdFileFd) * where the end tag should be. */ break; } + /* Read the two length bytes of the large resource record. */ - if (virPCIVPDReadVPDBytes(vpdFileFd, headerBuf, 2, resPos + 1,= &csum) !=3D 2) - break; + if (virPCIVPDReadVPDBytes(vpdFileFd, headerBuf, 2, resPos + 1,= &csum) < 0) + return NULL; resDataLen =3D headerBuf[0] + (headerBuf[1] << 8); /* Change the position to the byte following the tag and lengt= h bytes. */ --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706637138802917.3642879822647; Tue, 30 Jan 2024 09:52:18 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id BE80C181C; Tue, 30 Jan 2024 12:52:17 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4C12B1DE2; Tue, 30 Jan 2024 12:11:49 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id A33A71D0F; Tue, 30 Jan 2024 12:10:23 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 9D1D51D2D for ; Tue, 30 Jan 2024 12:08:40 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-695-15NQSKYmPRyhCaYYs_JT0Q-1; Tue, 30 Jan 2024 12:08:37 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8ECE8101377B for ; Tue, 30 Jan 2024 17:08:37 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04A3E2166B31 for ; Tue, 30 Jan 2024 17:08:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: 15NQSKYmPRyhCaYYs_JT0Q-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 25/31] virPCIVPDParseVPDLargeResourceString: Properly report errors Date: Tue, 30 Jan 2024 18:08:03 +0100 Message-ID: <6a5971c223338504b5461fbccc94b99e0ccf6f8b.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: KFL3TM3VY5Y5GY5MVM27HQQWQWOBNAYA X-Message-ID-Hash: KFL3TM3VY5Y5GY5MVM27HQQWQWOBNAYA X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706637139373100001 Replace VIR_INFO being used as form of error reporting with proper virReportError and the usual return values. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 10cabff0b9..ddd79fa8bc 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -557,10 +557,9 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, ui= nt16_t resPos, uint16_t re * @resDataLen: A length of the data portion of a resource. * @csum: A pointer to a 1-byte checksum. * - * Returns: a pointer to a VPDResource which needs to be freed by the call= er or - * NULL if getting it failed for some reason. + * Returns: 0 on success -1 and an error on failure */ -static bool +static int virPCIVPDParseVPDLargeResourceString(int vpdFileFd, uint16_t resPos, uint16_t resDataLen, uint8_t *csum, v= irPCIVPDResource *res) { @@ -570,15 +569,16 @@ virPCIVPDParseVPDLargeResourceString(int vpdFileFd, u= int16_t resPos, g_autofree char *buf =3D g_malloc0(resDataLen + 1); if (virPCIVPDReadVPDBytes(vpdFileFd, (uint8_t *)buf, resDataLen, resPo= s, csum) < 0) - return false; + return -1; resValue =3D g_strdup(g_strstrip(buf)); if (!virPCIVPDResourceIsValidTextValue(resValue)) { - VIR_INFO("The string resource has invalid characters in its value"= ); - return false; + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to parse PCI VPD string value with invali= d characters")); + return -1; } res->name =3D g_steal_pointer(&resValue); - return true; + return 0; } /** @@ -652,8 +652,11 @@ virPCIVPDParse(int vpdFileFd) switch (tag) { /* Large resource type which is also a string: 0x80 | 0x02= =3D 0x82 */ case PCI_VPD_LARGE_RESOURCE_FLAG | PCI_VPD_STRING_RESOURCE_FLA= G: - isWellFormed =3D virPCIVPDParseVPDLargeResourceString(vpdF= ileFd, resPos, resDataLen, - &csum,= res); + if (virPCIVPDParseVPDLargeResourceString(vpdFileFd, resPos= , resDataLen, + &csum, res) < 0) + return NULL; + + isWellFormed =3D true; break; /* Large resource type which is also a VPD-R: 0x80 | 0x10 = =3D=3D 0x90 */ case PCI_VPD_LARGE_RESOURCE_FLAG | PCI_VPD_READ_ONLY_LARGE_RES= OURCE_FLAG: --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706637287947895.3655116412086; Tue, 30 Jan 2024 09:54:47 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9D2781DED; Tue, 30 Jan 2024 12:54:31 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E757B1DE9; Tue, 30 Jan 2024 12:11:58 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1F2171D5D; Tue, 30 Jan 2024 12:10:25 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id EF09E1C54 for ; Tue, 30 Jan 2024 12:08:40 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-226-mg82xY0-PJOGFYmol1dfiQ-1; Tue, 30 Jan 2024 12:08:38 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7BFA9846D7D for ; Tue, 30 Jan 2024 17:08:38 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6C2F2166B31 for ; Tue, 30 Jan 2024 17:08:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: mg82xY0-PJOGFYmol1dfiQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 26/31] virPCIVPDParseVPDLargeResourceFields: Merge logic conditions Date: Tue, 30 Jan 2024 18:08:04 +0100 Message-ID: <653e8e0b990d191bc2946cd345fc64577574c11a.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: UUIZLH5R32DSUN3SZQLEGNCCA4ZG5YOK X-Message-ID-Hash: UUIZLH5R32DSUN3SZQLEGNCCA4ZG5YOK X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706637288848100001 Merge the pre-checks with the 'switch' statement which is operating on the same values to simplify further refactoring. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index ddd79fa8bc..ba05014e40 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -438,23 +438,27 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, u= int16_t resPos, uint16_t re fieldKeyword =3D g_strndup((char *)buf, 2); fieldFormat =3D virPCIVPDResourceGetFieldValueFormat(fieldKeyword); - /* Handle special cases first */ - if (!readOnly && fieldFormat =3D=3D VIR_PCI_VPD_RESOURCE_FIELD_VAL= UE_FORMAT_RESVD) { - VIR_INFO("Unexpected RV keyword in the read-write section."); - return false; - } else if (readOnly && fieldFormat =3D=3D VIR_PCI_VPD_RESOURCE_FIE= LD_VALUE_FORMAT_RDWR) { - VIR_INFO("Unexpected RW keyword in the read-only section."); - return false; - } - /* Determine how many bytes to read per field value type. */ switch (fieldFormat) { case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_TEXT: - case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RDWR: case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_BINARY: bytesToRead =3D fieldDataLen; break; + + case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RDWR: + if (readOnly) { + VIR_INFO("Unexpected RW keyword in the read-only secti= on."); + return false; + } + + bytesToRead =3D fieldDataLen; + break; + case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RESVD: + if (!readOnly) { + VIR_INFO("Unexpected RV keyword in the read-write sect= ion."); + return false; + } /* Only need one byte to be read and accounted towards * the checksum calculation. */ bytesToRead =3D 1; --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706637449191279.89764115199876; Tue, 30 Jan 2024 09:57:29 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 20B76187F; Tue, 30 Jan 2024 12:57:28 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2D8341E0A; Tue, 30 Jan 2024 12:12:15 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 5EBB91C6A; Tue, 30 Jan 2024 12:10:33 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 465CD1C84 for ; Tue, 30 Jan 2024 12:08:43 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-518-BdVL9wjBMkGobeokG75ngw-1; Tue, 30 Jan 2024 12:08:39 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6AB473CBD534 for ; Tue, 30 Jan 2024 17:08:39 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id D81A32166B31 for ; Tue, 30 Jan 2024 17:08:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: BdVL9wjBMkGobeokG75ngw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 27/31] virPCIVPDParseVPDLargeResourceFields: Remove impossible 'default' swithch case Date: Tue, 30 Jan 2024 18:08:05 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: P3PLQLFNEAOQ3MZD5F7Y5XBTIEISIJ36 X-Message-ID-Hash: P3PLQLFNEAOQ3MZD5F7Y5XBTIEISIJ36 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706637451291100001 The 'fieldFormat' variable is guaranteed to have only the proper enum values by virPCIVPDResourceGetFieldValueFormat. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index ba05014e40..25c4c2c5ec 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -470,9 +470,6 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uin= t16_t resPos, uint16_t re VIR_DEBUG("Could not determine a field value format for ke= yword: %s", fieldKeyword); bytesToRead =3D fieldDataLen; break; - default: - VIR_INFO("Unexpected field value format encountered."); - return false; } if (resPos + resDataLen < fieldPos + fieldDataLen) { --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706637363616620.5488635758956; Tue, 30 Jan 2024 09:56:03 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8C4A61E8C; Tue, 30 Jan 2024 12:56:02 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 528CE1DB3; Tue, 30 Jan 2024 12:12:07 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 41D9C1C68; Tue, 30 Jan 2024 12:10:32 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 29A2C1D34 for ; Tue, 30 Jan 2024 12:08:43 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-696-tJYgvRKdOCCh6JhUkI8umQ-1; Tue, 30 Jan 2024 12:08:41 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6107584852C for ; Tue, 30 Jan 2024 17:08:40 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA0672166B31 for ; Tue, 30 Jan 2024 17:08:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: tJYgvRKdOCCh6JhUkI8umQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 28/31] virPCIVPDParseVPDLargeResourceFields: Refactor processing of read data Date: Tue, 30 Jan 2024 18:08:06 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 2ACKWA22YOQTYNUPHIFCWOX4WAE3N7FQ X-Message-ID-Hash: 2ACKWA22YOQTYNUPHIFCWOX4WAE3N7FQ X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706637365272100001 Use a 'switch' statement instead of a bunch of if/elseif statements. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 66 +++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 25c4c2c5ec..60e520c46f 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -485,36 +485,43 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, u= int16_t resPos, uint16_t re /* Advance the position to the first byte of the next field. */ fieldPos +=3D fieldDataLen; - if (fieldFormat =3D=3D VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_TEX= T) { - /* Trim whitespace around a retrieved value and set it to be a= field's value. Cases - * where unnecessary whitespace was present around a field val= ue have been encountered - * in the wild. - */ - fieldValue =3D g_strstrip(g_strndup((char *)buf, fieldDataLen)= ); - if (!virPCIVPDResourceIsValidTextValue(fieldValue)) { - /* 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); + switch (fieldFormat) { + case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_TEXT: + /* Trim whitespace around a retrieved value and set it to = be a field's value. Cases + * where unnecessary whitespace was present around a field= value have been encountered + * in the wild. + */ + fieldValue =3D g_strstrip(g_strndup((char *)buf, fieldData= Len)); + if (!virPCIVPDResourceIsValidTextValue(fieldValue)) { + /* Skip fields with invalid values - this is safe assu= ming field length is + * correctly specified. */ + VIR_DEBUG("A value for field %s contains invalid chara= cters", fieldKeyword); + continue; + } + break; + + case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_BINARY: + fieldValue =3D g_malloc(fieldDataLen); + memcpy(fieldValue, buf, fieldDataLen); + break; + + case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RDWR: + /* Skip the read-write space since it is used for indicati= on only. */ + hasRW =3D true; + goto done; + + case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RESVD: + if (*csum) { + /* All bytes up to and including the checksum byte sho= uld add up to 0. */ + VIR_INFO("Checksum validation has failed"); + return false; + } + hasChecksum =3D true; + goto done; + + case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_LAST: + /* Skip unknown fields */ continue; - } - } else if (fieldFormat =3D=3D VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FOR= MAT_RESVD) { - if (*csum) { - /* All bytes up to and including the checksum byte should = add up to 0. */ - VIR_INFO("Checksum validation has failed"); - return false; - } - hasChecksum =3D true; - 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; - break; - } else if (fieldFormat =3D=3D VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FOR= MAT_LAST) { - /* Skip unknown fields */ - continue; - } else { - fieldValue =3D g_malloc(fieldDataLen); - memcpy(fieldValue, buf, fieldDataLen); } if (readOnly) { @@ -528,6 +535,7 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uin= t16_t resPos, uint16_t re virPCIVPDResourceUpdateKeyword(res, readOnly, fieldKeyword, fieldV= alue); } + done: /* May have exited the loop prematurely in case RV or RW were encounte= red and * they were not the last fields in the section. */ endReached =3D (fieldPos >=3D resPos + resDataLen); --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706637546241405.0446708550236; Tue, 30 Jan 2024 09:59:06 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 23B471E5E; Tue, 30 Jan 2024 12:59:05 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8EF951890; Tue, 30 Jan 2024 12:12:24 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id EB6E31C3D; Tue, 30 Jan 2024 12:10:40 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id EDD981C86 for ; Tue, 30 Jan 2024 12:08:44 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-177-SSOTL_N9M3-AdchJE7pw6A-1; Tue, 30 Jan 2024 12:08:41 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 49A3D1C05139 for ; Tue, 30 Jan 2024 17:08:41 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id B77242166B31 for ; Tue, 30 Jan 2024 17:08:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: SSOTL_N9M3-AdchJE7pw6A-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 29/31] virPCIVPDParseVPDLargeResourceFields: Refactor return logic Date: Tue, 30 Jan 2024 18:08:07 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 6Q72KIZ2A5BOEAZ63D2IVDZV2Z3MYGMI X-Message-ID-Hash: 6Q72KIZ2A5BOEAZ63D2IVDZV2Z3MYGMI X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706637547551100001 Rewrite the conditions after exiting the parser so that they are easier to understand. This partially decreases the granularity of "error" messages as they are not strictly necessary albeit for debugging. As it was already observed in this code the logic itself often does something else than the comment claims, thus the code logic is preserved. Changes: - any case when not all data was processed is agregated together and gets a common "error" message - absence of 'checksum' field is checked separately - helper variables are removed as they are no longer needed Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 60e520c46f..be19f7b747 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -415,10 +415,7 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, ui= nt16_t resPos, uint16_t re g_autofree uint8_t *buf =3D g_malloc0(PCI_VPD_MAX_FIELD_SIZE + 1); uint16_t fieldDataLen =3D 0, bytesToRead =3D 0; uint16_t fieldPos =3D resPos; - bool hasChecksum =3D false; - bool hasRW =3D false; - bool endReached =3D false; /* Note the equal sign - fields may have a zero length in which case t= hey will * just occupy 3 header bytes. In the in case of the RW field this may= mean that @@ -507,7 +504,9 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uin= t16_t resPos, uint16_t re case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RDWR: /* Skip the read-write space since it is used for indicati= on only. */ - hasRW =3D true; + /* The lack of RW is allowed on purpose in the read-write = section since some vendors + * violate the PCI/PCIe specs and do not include it, howev= er, this does not prevent parsing + * of valid data. */ goto done; case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RESVD: @@ -531,6 +530,7 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uin= t16_t resPos, uint16_t re if (!res->rw) res->rw =3D virPCIVPDResourceRWNew(); } + /* The field format, keyword and value are determined. Attempt to = update the resource. */ virPCIVPDResourceUpdateKeyword(res, readOnly, fieldKeyword, fieldV= alue); } @@ -538,27 +538,21 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, u= int16_t resPos, uint16_t re done: /* May have exited the loop prematurely in case RV or RW were encounte= red and * they were not the last fields in the section. */ - endReached =3D (fieldPos >=3D resPos + resDataLen); - if (readOnly && !(hasChecksum && endReached)) { - VIR_DEBUG("VPD-R does not contain the mandatory RV field as the la= st field"); + if ((fieldPos < resPos + resDataLen)) { + /* unparsed data still present */ + VIR_DEBUG("PCI VPD data parsing failed"); + return false; + } + + if (readOnly && !hasChecksum) { + VIR_DEBUG("VPD-R does not contain the mandatory checksum"); return false; - } else if (!readOnly && !endReached) { - /* The lack of RW is allowed on purpose in the read-write section = since some vendors - * violate the PCI/PCIe specs and do not include it, however, this= does not prevent parsing - * of valid data. If the RW is present, however, we make sure it i= s the last field in - * the read-write section. */ - if (hasRW) { - VIR_DEBUG("VPD-W section parsing ended prematurely (RW is not = the last field)."); - return false; - } else { - VIR_DEBUG("VPD-W section parsing ended prematurely."); - return false; - } } return true; } + /** * virPCIVPDParseVPDLargeResourceString: * @vpdFileFd: A file descriptor associated with a file containing PCI dev= ice VPD. --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706637780550105.22385221855382; Tue, 30 Jan 2024 10:03:00 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 84E451DA4; Tue, 30 Jan 2024 13:02:59 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A4D7A1DDA; Tue, 30 Jan 2024 12:12:43 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id AC33D1CA5; Tue, 30 Jan 2024 12:10:44 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 4118F1D37 for ; Tue, 30 Jan 2024 12:08:45 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-0-uX61d4MaOE3eNhJsOv-Q-1; Tue, 30 Jan 2024 12:08:42 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 40A95185A78B for ; Tue, 30 Jan 2024 17:08:42 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7F3E2166B31 for ; Tue, 30 Jan 2024 17:08:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: 0-uX61d4MaOE3eNhJsOv-Q-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 30/31] virPCIVPDParseVPDLargeResourceFields: Report proper errors Date: Tue, 30 Jan 2024 18:08:08 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: TB4MCIMDQDCN7XXDTPFRZZ5QWOCLT7HI X-Message-ID-Hash: TB4MCIMDQDCN7XXDTPFRZZ5QWOCLT7HI X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706637783131100001 The code abused 'VIR_INFO' as an attempt at error reporting. Rework the code to return the usual 0/-1 and raise proper errors. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 67 +++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index be19f7b747..4a440c2aea 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -404,12 +404,15 @@ virPCIVPDReadVPDBytes(int vpdFileFd, * @csum: A pointer to a 1-byte checksum. * @res: A pointer to virPCIVPDResource. * - * Returns: a pointer to a VPDResource which needs to be freed by the call= er or - * NULL if getting it failed for some reason. + * Returns 0 if the field was parsed sucessfully; -1 on error */ -static bool -virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uint16_t resPos, uint1= 6_t resDataLen, - bool readOnly, uint8_t *csum, virPCIV= PDResource *res) +static int +virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, + uint16_t resPos, + uint16_t resDataLen, + bool readOnly, + uint8_t *csum, + virPCIVPDResource *res) { /* 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); @@ -427,7 +430,7 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uin= t16_t resPos, uint16_t re /* Keyword resources consist of keywords (2 ASCII bytes per the sp= ec) and 1-byte length. */ if (virPCIVPDReadVPDBytes(vpdFileFd, buf, 3, fieldPos, csum) < 0) - return false; + return -1; fieldDataLen =3D buf[2]; /* Change the position to the field's data portion skipping the ke= yword and length bytes. */ @@ -444,8 +447,9 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uin= t16_t resPos, uint16_t re case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RDWR: if (readOnly) { - VIR_INFO("Unexpected RW keyword in the read-only secti= on."); - return false; + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to read the PCI VPD data: une= xpected RW keyword in read-only section")); + return -1; } bytesToRead =3D fieldDataLen; @@ -453,8 +457,9 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uin= t16_t resPos, uint16_t re case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RESVD: if (!readOnly) { - VIR_INFO("Unexpected RV keyword in the read-write sect= ion."); - return false; + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to read the PCI VPD data: une= xpected RV keyword in read-write section")); + return -1; } /* Only need one byte to be read and accounted towards * the checksum calculation. */ @@ -472,12 +477,13 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, u= int16_t resPos, uint16_t re if (resPos + resDataLen < fieldPos + fieldDataLen) { /* In this case the field cannot simply be skipped since the p= osition of the * next field is determined based on the length of a previous = field. */ - VIR_INFO("A field data length violates the resource length bou= ndary."); - return false; + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to read the PCI VPD data: data field = length invalid")); + return -1; } if (virPCIVPDReadVPDBytes(vpdFileFd, buf, bytesToRead, fieldPos, c= sum) < 0) - return false; + return -1; /* Advance the position to the first byte of the next field. */ fieldPos +=3D fieldDataLen; @@ -492,7 +498,6 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uin= t16_t resPos, uint16_t re if (!virPCIVPDResourceIsValidTextValue(fieldValue)) { /* Skip fields with invalid values - this is safe assu= ming field length is * correctly specified. */ - VIR_DEBUG("A value for field %s contains invalid chara= cters", fieldKeyword); continue; } break; @@ -512,8 +517,9 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, uin= t16_t resPos, uint16_t re case VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FORMAT_RESVD: if (*csum) { /* All bytes up to and including the checksum byte sho= uld add up to 0. */ - VIR_INFO("Checksum validation has failed"); - return false; + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to read the PCI VPD data: inv= alid checksum")); + return -1; } hasChecksum =3D true; goto done; @@ -540,16 +546,18 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, u= int16_t resPos, uint16_t re * they were not the last fields in the section. */ if ((fieldPos < resPos + resDataLen)) { /* unparsed data still present */ - VIR_DEBUG("PCI VPD data parsing failed"); - return false; + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to read the PCI VPD data: parsing ended p= rematurely")); + return -1; } if (readOnly && !hasChecksum) { - VIR_DEBUG("VPD-R does not contain the mandatory checksum"); - return false; + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to read the PCI VPD data: missing mandato= ry checksum")); + return -1; } - return true; + return 0; } @@ -606,7 +614,6 @@ virPCIVPDParse(int vpdFileFd) uint8_t csum =3D 0; uint8_t headerBuf[2]; - bool isWellFormed =3D false; uint16_t resPos =3D 0, resDataLen; uint8_t tag =3D 0; bool endResReached =3D false, hasReadOnly =3D false; @@ -659,20 +666,21 @@ virPCIVPDParse(int vpdFileFd) &csum, res) < 0) return NULL; - isWellFormed =3D true; break; /* Large resource type which is also a VPD-R: 0x80 | 0x10 = =3D=3D 0x90 */ case PCI_VPD_LARGE_RESOURCE_FLAG | PCI_VPD_READ_ONLY_LARGE_RES= OURCE_FLAG: - isWellFormed =3D virPCIVPDParseVPDLargeResourceFields(vpdF= ileFd, resPos, - resDat= aLen, true, &csum, res); + if (virPCIVPDParseVPDLargeResourceFields(vpdFileFd, resPos, + resDataLen, true,= &csum, res) < 0) + return NULL; /* Encountered the VPD-R tag. The resource record parsing = also validates * the presence of the required checksum in the RV field. = */ hasReadOnly =3D true; break; /* Large resource type which is also a VPD-W: 0x80 | 0x11 = =3D=3D 0x91 */ case PCI_VPD_LARGE_RESOURCE_FLAG | PCI_VPD_READ_WRITE_LARGE_RE= SOURCE_FLAG: - isWellFormed =3D virPCIVPDParseVPDLargeResourceFields(vpdF= ileFd, resPos, resDataLen, - false,= &csum, res); + if (virPCIVPDParseVPDLargeResourceFields(vpdFileFd, resPos= , resDataLen, + false, &csum, res= ) < 0) + return NULL; break; default: /* While we cannot parse unknown resource types, they can = still be skipped @@ -682,11 +690,6 @@ virPCIVPDParse(int vpdFileFd) continue; } - if (!isWellFormed) { - VIR_DEBUG("Encountered an invalid VPD"); - return NULL; - } - /* Continue processing other resource records. */ resPos +=3D resDataLen; } --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Thu May 9 15:44:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706637864345757.8530353627027; Tue, 30 Jan 2024 10:04:24 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4E59C1CD3; Tue, 30 Jan 2024 13:04:23 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BFC311CA7; Tue, 30 Jan 2024 12:12:52 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 60C891C72; Tue, 30 Jan 2024 12:10:46 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 53E7B1C5D for ; Tue, 30 Jan 2024 12:08:54 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-333-GJx99PUSMGueMhCgsojzyw-1; Tue, 30 Jan 2024 12:08:47 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5429F84AE41 for ; Tue, 30 Jan 2024 17:08:43 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1F442166B31 for ; Tue, 30 Jan 2024 17:08:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: GJx99PUSMGueMhCgsojzyw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 31/31] virPCIVPDParse: Do reasonable error reporting Date: Tue, 30 Jan 2024 18:08:09 +0100 Message-ID: <718f4f35bda4b5476f67086974146148787b96db.1706633776.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: SM5KRWGTMH5746VKM635EDLLIAJQ6II2 X-Message-ID-Hash: SM5KRWGTMH5746VKM635EDLLIAJQ6II2 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706637865106100001 Remove the wannabe error reporting via 'VIR_DEBUG/VIR_INFO' in favor of proper errors. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virpcivpd.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 4a440c2aea..16df468875 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -616,7 +616,7 @@ virPCIVPDParse(int vpdFileFd) uint16_t resPos =3D 0, resDataLen; uint8_t tag =3D 0; - bool endResReached =3D false, hasReadOnly =3D false; + bool hasReadOnly =3D false; g_autoptr(virPCIVPDResource) res =3D g_new0(virPCIVPDResource, 1); @@ -628,9 +628,8 @@ virPCIVPDParse(int vpdFileFd) /* 0x80 =3D=3D 0b10000000 - the large resource data type flag. */ if (tag & PCI_VPD_LARGE_RESOURCE_FLAG) { if (resPos > PCI_VPD_ADDR_MASK + 1 - 3) { - /* Bail if the large resource starts at the position - * where the end tag should be. */ - break; + /* Bail if the large resource starts at the position where= the end tag should be. */ + goto malformed; } /* Read the two length bytes of the large resource record. */ @@ -649,14 +648,21 @@ virPCIVPDParse(int vpdFileFd) /* Change the position to the byte past the byte containing ta= g and length bits. */ resPos +=3D 1; } + if (tag =3D=3D PCI_VPD_RESOURCE_END_TAG) { /* Stop VPD traversal since the end tag was encountered. */ - endResReached =3D true; - break; + if (!hasReadOnly) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to read the PCI VPD data: missing= read-only section")); + return NULL; + } + + return g_steal_pointer(&res); } + if (resDataLen > PCI_VPD_ADDR_MASK + 1 - resPos) { /* Bail if the resource is too long to fit into the VPD addres= s space. */ - break; + goto malformed; } switch (tag) { @@ -686,22 +692,16 @@ virPCIVPDParse(int vpdFileFd) /* While we cannot parse unknown resource types, they can = still be skipped * based on the header and data length. */ VIR_DEBUG("Encountered an unexpected VPD resource tag: %#x= ", tag); - resPos +=3D resDataLen; - continue; } /* Continue processing other resource records. */ resPos +=3D resDataLen; } - if (!hasReadOnly) { - VIR_DEBUG("Encountered an invalid VPD: does not have a VPD-R recor= d"); - return NULL; - } else if (!endResReached) { - /* Does not have an end tag. */ - VIR_DEBUG("Encountered an invalid VPD"); - return NULL; - } - return g_steal_pointer(&res); + + malformed: + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to read the PCI VPD data: malformed data")); + return NULL; } #else /* ! __linux__ */ --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org