From: Peter Krempa Date: Wed, 9 Feb 2022 12:44:06 +0000 (+0100) Subject: virTPMCreateCancelPath: Refactor value returning X-Git-Tag: v8.1.0-rc1~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d42be7720897f3bbc0b29493f84d7e8db2f1328a;p=thirdparty%2Flibvirt.git virTPMCreateCancelPath: Refactor value returning Automatically free 'path' inside the loop which fills it and return the values directly. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- diff --git a/src/util/virtpm.c b/src/util/virtpm.c index ca7506d82e..65126f8160 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"); } /*