[libvirt PATCH 02/10] qemu: eliminate ret variable in qemuExtTPMStartEmulator

Ján Tomko posted 10 patches 6 years ago
[libvirt PATCH 02/10] qemu: eliminate ret variable in qemuExtTPMStartEmulator
Posted by Ján Tomko 6 years ago
Now that the cleanup section is empty, eliminate the cleanup
label as well as the 'ret' variable.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_tpm.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index c2132250eb..21792f6992 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -793,7 +793,6 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver,
                         virDomainObjPtr vm,
                         bool incomingMigration)
 {
-    int ret = -1;
     g_autoptr(virCommand) cmd = NULL;
     int exitstatus = 0;
     g_autofree char *errbuf = NULL;
@@ -817,23 +816,23 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver,
                                             cfg->swtpm_group,
                                             cfg->swtpmStateDir, shortName,
                                             incomingMigration)))
-        goto cleanup;
+        return -1;
 
     if (qemuExtDeviceLogCommand(driver, vm, cmd, "TPM Emulator") < 0)
-        goto cleanup;
+        return -1;
 
     virCommandSetErrorBuffer(cmd, &errbuf);
 
     if (qemuSecurityStartTPMEmulator(driver, vm, cmd,
                                      cfg->swtpm_user, cfg->swtpm_group,
                                      &exitstatus, &cmdret) < 0)
-        goto cleanup;
+        return -1;
 
     if (cmdret < 0 || exitstatus != 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Could not start 'swtpm'. exitstatus: %d, "
                          "error: %s"), exitstatus, errbuf);
-        goto cleanup;
+        return -1;
     }
 
     /* check that the swtpm has written its pid into the file */
@@ -852,15 +851,12 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver,
     if (timeout <= 0)
         goto error;
 
-    ret = 0;
-
- cleanup:
-    return ret;
+    return 0;
 
  error:
     virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                    _("swtpm failed to start"));
-    goto cleanup;
+    return -1;
 }
 
 
-- 
2.21.0

Re: [libvirt PATCH 02/10] qemu: eliminate ret variable in qemuExtTPMStartEmulator
Posted by Peter Krempa 6 years ago
On Tue, Jan 28, 2020 at 11:31:18 +0100, Ján Tomko wrote:
> Now that the cleanup section is empty, eliminate the cleanup
> label as well as the 'ret' variable.
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> ---
>  src/qemu/qemu_tpm.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)

It's a shame this code uses hand-rolled waiting loop for the process
rather than the backoff timer.

Also would be great to get rid of the error label too.

But those comments are out of scope of this patch thus:

Reviewed-by: Peter Krempa <pkrempa@redhat.com>