From nobody Thu May 2 21:54:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1528303677860231.78183490431695; Wed, 6 Jun 2018 09:47:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C4EED3001C56; Wed, 6 Jun 2018 16:47:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2E827280D1; Wed, 6 Jun 2018 16:47:55 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1BF64180BA80; Wed, 6 Jun 2018 16:47:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w56Gl3CS005798 for ; Wed, 6 Jun 2018 12:47:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5B450201CB9F; Wed, 6 Jun 2018 16:47:03 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id A561C2156602; Wed, 6 Jun 2018 16:47:02 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 6 Jun 2018 17:47:00 +0100 Message-Id: <20180606164700.7176-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] Don't use enums in TPM struct fields X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 06 Jun 2018 16:47:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 When using an enum in a struct field, the compiler is free to decide to make it an unsigned type if it desires. This in turn leads to bugs when code does if ((def->foo =3D virDomainFooTypeFromString(str)) < 0) ... because 'def->foo' can't technically have an unsigned value from the compiler's POV. While it is possible to add (int) casts in the code example above, this is not desirable because it is easy to miss out such casts. eg the code fixed here caused an error with clang builds ../../src/conf/domain_conf.c:12838:73: error: comparison of unsigned enum e= xpression < 0 is always false [-Werror,-Wtautological-compare] if ((def->version =3D virDomainTPMVersionTypeFromString(version)) <= 0) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~ Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/domain_conf.c | 4 ++-- src/conf/domain_conf.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) Pushed as a FreeBSD build fix diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c1f2583c29..5be773cda4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12795,7 +12795,7 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlop= t, =20 model =3D virXMLPropString(node, "model"); if (model !=3D NULL && - (int)(def->model =3D virDomainTPMModelTypeFromString(model)) < 0) { + (def->model =3D virDomainTPMModelTypeFromString(model)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown TPM frontend model '%s'"), model); goto error; @@ -12824,7 +12824,7 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlop= t, goto error; } =20 - if ((int)(def->type =3D virDomainTPMBackendTypeFromString(backend)) < = 0) { + if ((def->type =3D virDomainTPMBackendTypeFromString(backend)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown TPM backend type '%s'"), backend); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5f8960d90b..8a8121bf83 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1307,10 +1307,10 @@ typedef enum { # define VIR_DOMAIN_TPM_DEFAULT_DEVICE "/dev/tpm0" =20 struct _virDomainTPMDef { - virDomainTPMBackendType type; + int type; /* virDomainTPMBackendType */ virDomainDeviceInfo info; - virDomainTPMModel model; - virDomainTPMVersion version; + int model; /* virDomainTPMModel */ + int version; /* virDomainTPMVersion */ union { struct { virDomainChrSourceDef source; --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list