Browse Source

tpm: Clean up error reporting in tpm_init_tpmdev()

Calling error_report() in a function that takes an Error ** argument
is suspicious.  tpm_init_tpmdev() does that, and then fails without
setting an error.  Its caller main(), via tpm_init() and
qemu_opts_foreach(), is fine with it, but clean it up anyway.

Cc: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Message-Id: <2018101708.5581-30-armbru@redhat.com>
tags/v3.1.0-rc0
Markus Armbruster 8 months ago
parent
commit
d10e05f15d
4 changed files with 12 additions and 19 deletions
  1. 1
    1
      include/sysemu/tpm.h
  2. 1
    2
      stubs/tpm.c
  3. 9
    13
      tpm.c
  4. 1
    3
      vl.c

+ 1
- 1
include/sysemu/tpm.h View File

@@ -16,7 +16,7 @@
16 16
 #include "qom/object.h"
17 17
 
18 18
 int tpm_config_parse(QemuOptsList *opts_list, const char *optarg);
19
-int tpm_init(void);
19
+void tpm_init(void);
20 20
 void tpm_cleanup(void);
21 21
 
22 22
 typedef enum TPMVersion {

+ 1
- 2
stubs/tpm.c View File

@@ -9,9 +9,8 @@
9 9
 #include "qapi/qapi-commands-tpm.h"
10 10
 #include "sysemu/tpm.h"
11 11
 
12
-int tpm_init(void)
12
+void tpm_init(void)
13 13
 {
14
-    return 0;
15 14
 }
16 15
 
17 16
 void tpm_cleanup(void)

+ 9
- 13
tpm.c View File

@@ -89,19 +89,19 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)
89 89
     int i;
90 90
 
91 91
     if (!QLIST_EMPTY(&tpm_backends)) {
92
-        error_report("Only one TPM is allowed.");
92
+        error_setg(errp, "Only one TPM is allowed.");
93 93
         return 1;
94 94
     }
95 95
 
96 96
     id = qemu_opts_id(opts);
97 97
     if (id == NULL) {
98
-        error_report(QERR_MISSING_PARAMETER, "id");
98
+        error_setg(errp, QERR_MISSING_PARAMETER, "id");
99 99
         return 1;
100 100
     }
101 101
 
102 102
     value = qemu_opt_get(opts, "type");
103 103
     if (!value) {
104
-        error_report(QERR_MISSING_PARAMETER, "type");
104
+        error_setg(errp, QERR_MISSING_PARAMETER, "type");
105 105
         tpm_display_backend_drivers();
106 106
         return 1;
107 107
     }
@@ -109,8 +109,8 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)
109 109
     i = qapi_enum_parse(&TpmType_lookup, value, -1, NULL);
110 110
     be = i >= 0 ? tpm_be_find_by_type(i) : NULL;
111 111
     if (be == NULL) {
112
-        error_report(QERR_INVALID_PARAMETER_VALUE,
113
-                     "type", "a TPM backend type");
112
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
113
+                   "a TPM backend type");
114 114
         tpm_display_backend_drivers();
115 115
         return 1;
116 116
     }
@@ -118,7 +118,7 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)
118 118
     /* validate backend specific opts */
119 119
     qemu_opts_validate(opts, be->opts, &local_err);
120 120
     if (local_err) {
121
-        error_report_err(local_err);
121
+        error_propagate(errp, local_err);
122 122
         return 1;
123 123
     }
124 124
 
@@ -151,14 +151,10 @@ void tpm_cleanup(void)
151 151
  * Initialize the TPM. Process the tpmdev command line options describing the
152 152
  * TPM backend.
153 153
  */
154
-int tpm_init(void)
154
+void tpm_init(void)
155 155
 {
156
-    if (qemu_opts_foreach(qemu_find_opts("tpmdev"),
157
-                          tpm_init_tpmdev, NULL, NULL)) {
158
-        return -1;
159
-    }
160
-
161
-    return 0;
156
+    qemu_opts_foreach(qemu_find_opts("tpmdev"),
157
+                      tpm_init_tpmdev, NULL, &error_fatal);
162 158
 }
163 159
 
164 160
 /*

+ 1
- 3
vl.c View File

@@ -4360,9 +4360,7 @@ int main(int argc, char **argv, char **envp)
4360 4360
                       user_creatable_add_opts_foreach,
4361 4361
                       object_create_delayed, &error_fatal);
4362 4362
 
4363
-    if (tpm_init() < 0) {
4364
-        exit(1);
4365
-    }
4363
+    tpm_init();
4366 4364
 
4367 4365
     /* init the bluetooth world */
4368 4366
     if (foreach_device_config(DEV_BT, bt_parse))

Loading…
Cancel
Save