[PATCH 25/27] virTPMCreateCancelPath: Refactor value returning

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

 



Automatically free 'path' inside the loop which fills it and return the
values directly.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/util/virtpm.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/src/util/virtpm.c b/src/util/virtpm.c
index c02b42f948..8005708522 100644
--- a/src/util/virtpm.c
+++ b/src/util/virtpm.c
@@ -59,7 +59,6 @@ VIR_ENUM_IMPL(virTPMSwtpmSetupFeature,
 char *
 virTPMCreateCancelPath(const char *devpath)
 {
-    char *path = NULL;
     const char *dev;
     const char *prefix[] = {"misc/", "tpm/"};
     size_t i;
@@ -77,18 +76,14 @@ virTPMCreateCancelPath(const char *devpath)

     dev++;
     for (i = 0; i < G_N_ELEMENTS(prefix); i++) {
-        path = g_strdup_printf("/sys/class/%s%s/device/cancel", prefix[i],
-                               dev);
+        g_autofree char *path = g_strdup_printf("/sys/class/%s%s/device/cancel",
+                                                prefix[i], dev);

         if (virFileExists(path))
-            break;
-
-        VIR_FREE(path);
+            return g_steal_pointer(&path);
     }
-    if (!path)
-        path = g_strdup("/dev/null");

-    return path;
+    return g_strdup("/dev/null");
 }

 /*
-- 
2.34.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux