summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/qemu/qemu/0001-tpm-Clean-up-driver-registration-lookup.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/qemu/qemu/0001-tpm-Clean-up-driver-registration-lookup.patch')
-rw-r--r--meta/recipes-devtools/qemu/qemu/0001-tpm-Clean-up-driver-registration-lookup.patch154
1 files changed, 0 insertions, 154 deletions
diff --git a/meta/recipes-devtools/qemu/qemu/0001-tpm-Clean-up-driver-registration-lookup.patch b/meta/recipes-devtools/qemu/qemu/0001-tpm-Clean-up-driver-registration-lookup.patch
deleted file mode 100644
index 1a484b91c3..0000000000
--- a/meta/recipes-devtools/qemu/qemu/0001-tpm-Clean-up-driver-registration-lookup.patch
+++ /dev/null
@@ -1,154 +0,0 @@
1From a0f8d150794164f41cd7288c9ed059bbf21c95ec Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
3Date: Thu, 24 Aug 2017 10:45:58 +0200
4Subject: [PATCH 01/12] tpm: Clean up driver registration & lookup
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9We have a strict separation between enum TpmType and be_drivers[]:
10
11* TpmType may have any number of members. It just happens to have one.
12
13* tpm_register_driver() uses the first empty slot in be_drivers[].
14
15 If you register more than tpm_models[] has space,
16 tpm_register_driver() fails. Its caller silently ignores the
17 failure.
18
19 If you register more than one with a given TpmType,
20 tpm_display_backend_drivers() will shows all of them, but
21 tpm_driver_find_by_type() and tpm_get_backend_driver() will find
22 only the one one that registered first.
23
24Since we only ever register one driver, and be_drivers[] has space for
25just that one, this contraption even works.
26
27Turn be_drivers[] into a straight map from enum TpmType to driver.
28Much simpler, and has a decent chance to actually work should we ever
29acquire additional drivers.
30
31While there, use qapi_enum_parse() in tpm_get_backend_driver().
32
33Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
34Message-Id: <20170822132255.23945-8-marcandre.lureau@redhat.com>
35Reviewed-by: Markus Armbruster <armbru@redhat.com>
36[Rebased, superfluous initializer dropped, commit message rewritten]
37Cc: Stefan Berger <stefanb@us.ibm.com>
38Signed-off-by: Markus Armbruster <armbru@redhat.com>
39Message-Id: <1503564371-26090-4-git-send-email-armbru@redhat.com>
40
41Upstream-Status: Backport
42---
43 include/sysemu/tpm_backend.h | 2 +-
44 tpm.c | 45 +++++++++++++-------------------------------
45 2 files changed, 14 insertions(+), 33 deletions(-)
46
47diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
48index b58f52d39f..1d21c6b19b 100644
49--- a/include/sysemu/tpm_backend.h
50+++ b/include/sysemu/tpm_backend.h
51@@ -227,6 +227,6 @@ TPMBackend *qemu_find_tpm(const char *id);
52
53 const TPMDriverOps *tpm_get_backend_driver(const char *type);
54 int tpm_register_model(enum TpmModel model);
55-int tpm_register_driver(const TPMDriverOps *tdo);
56+void tpm_register_driver(const TPMDriverOps *tdo);
57
58 #endif
59diff --git a/tpm.c b/tpm.c
60index 9a7c7114d3..bb45d0c08e 100644
61--- a/tpm.c
62+++ b/tpm.c
63@@ -14,6 +14,7 @@
64 #include "qemu/osdep.h"
65
66 #include "qapi/qmp/qerror.h"
67+#include "qapi/util.h"
68 #include "sysemu/tpm_backend.h"
69 #include "sysemu/tpm.h"
70 #include "qemu/config-file.h"
71@@ -25,11 +26,8 @@ static QLIST_HEAD(, TPMBackend) tpm_backends =
72
73
74 #define TPM_MAX_MODELS 1
75-#define TPM_MAX_DRIVERS 1
76
77-static TPMDriverOps const *be_drivers[TPM_MAX_DRIVERS] = {
78- NULL,
79-};
80+static TPMDriverOps const *be_drivers[TPM_TYPE__MAX];
81
82 static enum TpmModel tpm_models[TPM_MAX_MODELS] = {
83 TPM_MODEL__MAX,
84@@ -63,31 +61,18 @@ static bool tpm_model_is_registered(enum TpmModel model)
85
86 const TPMDriverOps *tpm_get_backend_driver(const char *type)
87 {
88- int i;
89-
90- for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) {
91- if (!strcmp(TpmType_lookup[be_drivers[i]->type], type)) {
92- return be_drivers[i];
93- }
94- }
95+ int i = qapi_enum_parse(TpmType_lookup, type, TPM_TYPE__MAX, -1, NULL);
96
97- return NULL;
98+ return i >= 0 ? be_drivers[i] : NULL;
99 }
100
101 #ifdef CONFIG_TPM
102
103-int tpm_register_driver(const TPMDriverOps *tdo)
104+void tpm_register_driver(const TPMDriverOps *tdo)
105 {
106- int i;
107+ assert(!be_drivers[tdo->type]);
108
109- for (i = 0; i < TPM_MAX_DRIVERS; i++) {
110- if (!be_drivers[i]) {
111- be_drivers[i] = tdo;
112- return 0;
113- }
114- }
115- error_report("Could not register TPM driver");
116- return 1;
117+ be_drivers[tdo->type] = tdo;
118 }
119
120 /*
121@@ -100,9 +85,12 @@ static void tpm_display_backend_drivers(void)
122
123 fprintf(stderr, "Supported TPM types (choose only one):\n");
124
125- for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) {
126+ for (i = 0; i < TPM_TYPE__MAX; i++) {
127+ if (be_drivers[i] == NULL) {
128+ continue;
129+ }
130 fprintf(stderr, "%12s %s\n",
131- TpmType_lookup[be_drivers[i]->type], be_drivers[i]->desc());
132+ TpmType_lookup[i], be_drivers[i]->desc());
133 }
134 fprintf(stderr, "\n");
135 }
136@@ -239,14 +227,7 @@ int tpm_config_parse(QemuOptsList *opts_list, const char *optarg)
137
138 static const TPMDriverOps *tpm_driver_find_by_type(enum TpmType type)
139 {
140- int i;
141-
142- for (i = 0; i < TPM_MAX_DRIVERS && be_drivers[i] != NULL; i++) {
143- if (be_drivers[i]->type == type) {
144- return be_drivers[i];
145- }
146- }
147- return NULL;
148+ return be_drivers[type];
149 }
150
151 static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv)
152--
1532.11.0
154