virTPMCreateCancelPath: Refactor value returning

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-02-09 13:44:06 +01:00
parent ad81aa8ad0
commit d42be77208

View File

@ -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");
}
/*