qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 32/42] tpm-passthrough: make it safer to destroy


From: Stefan Berger
Subject: Re: [Qemu-devel] [PATCH 32/42] tpm-passthrough: make it safer to destroy after creation
Date: Tue, 10 Oct 2017 14:13:31 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0

On 10/09/2017 06:56 PM, Marc-André Lureau wrote:
Check fds values before closing, to avoid close(-1).

Signed-off-by: Marc-André Lureau <address@hidden>

Typicall free() can be called with a NULL pointer. I am also fine with this change here, but could we move the fd < 0 check into qemu_close?

Reviewed-by: Stefan Berger <address@hidden>

---
  hw/tpm/tpm_passthrough.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c
index 7371d50739..aa9167e3c6 100644
--- a/hw/tpm/tpm_passthrough.c
+++ b/hw/tpm/tpm_passthrough.c
@@ -347,8 +347,12 @@ static void tpm_passthrough_inst_finalize(Object *obj)
tpm_passthrough_cancel_cmd(TPM_BACKEND(obj)); - qemu_close(tpm_pt->tpm_fd);
-    qemu_close(tpm_pt->cancel_fd);
+    if (tpm_pt->tpm_fd >= 0) {
+        qemu_close(tpm_pt->tpm_fd);
+    }
+    if (tpm_pt->cancel_fd >= 0) {
+        qemu_close(tpm_pt->cancel_fd);
+    }
      qapi_free_TPMPassthroughOptions(tpm_pt->options);
  }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]