summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2017-10-10 00:55:56 +0200
committerStefan Berger <stefanb@linux.vnet.ibm.com>2017-10-19 11:42:28 -0400
commitc106ede9c85bf4b38c52dbee96b00c2aa0a97dee (patch)
tree0659466edcc05950d5b4e8628cecc1184e82b68e
parent0e43b7e61ce677e154584523943c1651779baccf (diff)
downloadqemu-c106ede9c85bf4b38c52dbee96b00c2aa0a97dee.tar.gz
tpm-emulator: fix error handling
The previous patch cleaned up a bit error handling, and exposed an existing bug: error_report_err() could be called with a NULL error. Instead, make tpm_emulator_set_locality() set the error. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
-rw-r--r--hw/tpm/tpm_emulator.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c
index 0b1a99fcc5..a613cec456 100644
--- a/hw/tpm/tpm_emulator.c
+++ b/hw/tpm/tpm_emulator.c
@@ -141,7 +141,8 @@ static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu,
return 0;
}
-static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_number)
+static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_number,
+ Error **errp)
{
ptm_loc loc;
@@ -155,15 +156,15 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_number)
loc.u.req.loc = locty_number;
if (tpm_emulator_ctrlcmd(&tpm_emu->ctrl_chr, CMD_SET_LOCALITY, &loc,
sizeof(loc), sizeof(loc)) < 0) {
- error_report("tpm-emulator: could not set locality : %s",
- strerror(errno));
+ error_setg(errp, "tpm-emulator: could not set locality : %s",
+ strerror(errno));
return -1;
}
loc.u.resp.tpm_result = be32_to_cpu(loc.u.resp.tpm_result);
if (loc.u.resp.tpm_result != 0) {
- error_report("tpm-emulator: TPM result for set locality : 0x%x",
- loc.u.resp.tpm_result);
+ error_setg(errp, "tpm-emulator: TPM result for set locality : 0x%x",
+ loc.u.resp.tpm_result);
return -1;
}
@@ -179,7 +180,8 @@ static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd *cmd)
DPRINTF("processing TPM command");
- if (tpm_emulator_set_locality(tpm_emu, tb->tpm_state->locty_number) < 0) {
+ if (tpm_emulator_set_locality(tpm_emu,
+ tb->tpm_state->locty_number, &err) < 0) {
goto error;
}