[PATCH v1] stubdom/vtpmmgr: simplify handling of hardware_version

Olaf Hering posted 1 patch 3 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/xen tags/patchew/20200617061349.7623-1-olaf@aepfle.de
Maintainers: Daniel De Graaf <dgdegra@tycho.nsa.gov>, Samuel Thibault <samuel.thibault@ens-lyon.org>, Quan Xu <quan.xu0@gmail.com>
stubdom/vtpmmgr/vtpmmgr.c | 8 +++-----
stubdom/vtpmmgr/vtpmmgr.h | 9 ---------
2 files changed, 3 insertions(+), 14 deletions(-)
[PATCH v1] stubdom/vtpmmgr: simplify handling of hardware_version
Posted by Olaf Hering 3 years, 10 months ago
Remove complicated code which deals with a simple boolean, to make gcc10 happy.

ld: /home/abuild/rpmbuild/BUILD/xen-4.14.20200616T103126.3625b04991/non-dbg/stubdom/vtpmmgr/vtpmmgr.a(vtpm_cmd_handler.o):(.bss+0x0): multiple definition of `tpm_version'; /home/abuild/rpmbuild/BUILD/xen-4.14.20200616T103126.3625b04991/non-dbg/stubdom/vtpmmgr/vtpmmgr.a(vtpmmgr.o):(.bss+0x0): first defined here

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 stubdom/vtpmmgr/vtpmmgr.c | 8 +++-----
 stubdom/vtpmmgr/vtpmmgr.h | 9 ---------
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/stubdom/vtpmmgr/vtpmmgr.c b/stubdom/vtpmmgr/vtpmmgr.c
index 9fddaa24f8..94578adbff 100644
--- a/stubdom/vtpmmgr/vtpmmgr.c
+++ b/stubdom/vtpmmgr/vtpmmgr.c
@@ -45,9 +45,7 @@
 #include "vtpmmgr.h"
 #include "tcg.h"
 
-struct tpm_hardware_version hardware_version = {
-    .hw_version = TPM1_HARDWARE,
-};
+static int hardware_version;
 
 int parse_cmdline_hw(int argc, char** argv)
 {
@@ -55,7 +53,7 @@ int parse_cmdline_hw(int argc, char** argv)
 
     for (i = 1; i < argc; ++i) {
         if (!strcmp(argv[i], TPM2_EXTRA_OPT)) {
-            hardware_version.hw_version = TPM2_HARDWARE;
+            hardware_version = 2;
             break;
         }
     }
@@ -64,7 +62,7 @@ int parse_cmdline_hw(int argc, char** argv)
 
 int hw_is_tpm2(void)
 {
-    return (hardware_version.hw_version == TPM2_HARDWARE) ? 1 : 0;
+    return hardware_version == 2 ? 1 : 0;
 }
 
 void main_loop(void) {
diff --git a/stubdom/vtpmmgr/vtpmmgr.h b/stubdom/vtpmmgr/vtpmmgr.h
index 2e6f8de9e4..6523604bdc 100644
--- a/stubdom/vtpmmgr/vtpmmgr.h
+++ b/stubdom/vtpmmgr/vtpmmgr.h
@@ -50,16 +50,7 @@
 #define RSA_KEY_SIZE 0x0800
 #define RSA_CIPHER_SIZE (RSA_KEY_SIZE / 8)
 
-enum {
-    TPM1_HARDWARE = 1,
-    TPM2_HARDWARE,
-} tpm_version;
 
-struct tpm_hardware_version {
-    int hw_version;
-};
-
-extern struct tpm_hardware_version hardware_version;
 
 struct vtpm_globals {
    int tpm_fd;

Re: [PATCH v1] stubdom/vtpmmgr: simplify handling of hardware_version
Posted by Samuel Thibault 3 years, 10 months ago
Olaf Hering, le mer. 17 juin 2020 08:13:49 +0200, a ecrit:
>  int hw_is_tpm2(void)
>  {
> -    return (hardware_version.hw_version == TPM2_HARDWARE) ? 1 : 0;
> +    return hardware_version == 2 ? 1 : 0;
>  }

Or even

return hardware_version == 2;

?

Either case,

Acked-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Thanks!
Samuel

Re: [PATCH v1] stubdom/vtpmmgr: simplify handling of hardware_version
Posted by Jason Andryuk 3 years, 10 months ago
On Wed, Jun 17, 2020 at 2:16 AM Olaf Hering <olaf@aepfle.de> wrote:
>
> Remove complicated code which deals with a simple boolean, to make gcc10 happy.
>
> ld: /home/abuild/rpmbuild/BUILD/xen-4.14.20200616T103126.3625b04991/non-dbg/stubdom/vtpmmgr/vtpmmgr.a(vtpm_cmd_handler.o):(.bss+0x0): multiple definition of `tpm_version'; /home/abuild/rpmbuild/BUILD/xen-4.14.20200616T103126.3625b04991/non-dbg/stubdom/vtpmmgr/vtpmmgr.a(vtpmmgr.o):(.bss+0x0): first defined here
>
> Signed-off-by: Olaf Hering <olaf@aepfle.de>

Nice simplification.

Reviewed-by: Jason Andryuk <jandryuk@gmail.com>