提交 d96eb28e 编写于 作者: E Erik Skultety

qemu: Define and use a auto cleanup function with virSEVCapability

Keep with the recent effort of replacing as many explicit *Free
functions with their automatic equivalents.
Signed-off-by: NErik Skultety <eskultet@redhat.com>
Acked-by: NPeter Krempa <pkrempa@redhat.com>
上级 6c50cef8
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
# include "internal.h" # include "internal.h"
# include "domain_conf.h" # include "domain_conf.h"
# include "viralloc.h"
typedef const char * (*virDomainCapsValToStr)(int value); typedef const char * (*virDomainCapsValToStr)(int value);
...@@ -215,4 +216,7 @@ char * virDomainCapsFormat(virDomainCapsPtr const caps); ...@@ -215,4 +216,7 @@ char * virDomainCapsFormat(virDomainCapsPtr const caps);
void void
virSEVCapabilitiesFree(virSEVCapability *capabilities); virSEVCapabilitiesFree(virSEVCapability *capabilities);
VIR_DEFINE_AUTOPTR_FUNC(virSEVCapability, virSEVCapabilitiesFree);
#endif /* __DOMAIN_CAPABILITIES_H__ */ #endif /* __DOMAIN_CAPABILITIES_H__ */
...@@ -5263,9 +5263,8 @@ static int ...@@ -5263,9 +5263,8 @@ static int
virQEMUCapsFillDomainFeatureSEVCaps(virQEMUCapsPtr qemuCaps, virQEMUCapsFillDomainFeatureSEVCaps(virQEMUCapsPtr qemuCaps,
virDomainCapsPtr domCaps) virDomainCapsPtr domCaps)
{ {
virSEVCapability *sev;
virSEVCapability *cap = qemuCaps->sevCapabilities; virSEVCapability *cap = qemuCaps->sevCapabilities;
int ret = -1; VIR_AUTOPTR(virSEVCapability) sev = NULL;
if (!cap) if (!cap)
return 0; return 0;
...@@ -5274,19 +5273,16 @@ virQEMUCapsFillDomainFeatureSEVCaps(virQEMUCapsPtr qemuCaps, ...@@ -5274,19 +5273,16 @@ virQEMUCapsFillDomainFeatureSEVCaps(virQEMUCapsPtr qemuCaps,
return -1; return -1;
if (VIR_STRDUP(sev->pdh, cap->pdh) < 0) if (VIR_STRDUP(sev->pdh, cap->pdh) < 0)
goto cleanup; return -1;
if (VIR_STRDUP(sev->cert_chain, cap->cert_chain) < 0) if (VIR_STRDUP(sev->cert_chain, cap->cert_chain) < 0)
goto cleanup; return -1;
sev->cbitpos = cap->cbitpos; sev->cbitpos = cap->cbitpos;
sev->reduced_phys_bits = cap->reduced_phys_bits; sev->reduced_phys_bits = cap->reduced_phys_bits;
VIR_STEAL_PTR(domCaps->sev, sev); VIR_STEAL_PTR(domCaps->sev, sev);
ret = 0; return 0;
cleanup:
virSEVCapabilitiesFree(sev);
return ret;
} }
......
...@@ -6443,9 +6443,11 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitorPtr mon, ...@@ -6443,9 +6443,11 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitorPtr mon,
virJSONValuePtr cmd; virJSONValuePtr cmd;
virJSONValuePtr reply = NULL; virJSONValuePtr reply = NULL;
virJSONValuePtr caps; virJSONValuePtr caps;
virSEVCapability *capability = NULL; const char *pdh = NULL;
const char *pdh = NULL, *cert_chain = NULL; const char *cert_chain = NULL;
unsigned int cbitpos, reduced_phys_bits; unsigned int cbitpos;
unsigned int reduced_phys_bits;
VIR_AUTOPTR(virSEVCapability) capability = NULL;
*capabilities = NULL; *capabilities = NULL;
...@@ -6476,7 +6478,7 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitorPtr mon, ...@@ -6476,7 +6478,7 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitorPtr mon,
} }
if (virJSONValueObjectGetNumberUint(caps, "reduced-phys-bits", if (virJSONValueObjectGetNumberUint(caps, "reduced-phys-bits",
&reduced_phys_bits) < 0) { &reduced_phys_bits) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-sev-capabilities reply was missing" _("query-sev-capabilities reply was missing"
" 'reduced-phys-bits' field")); " 'reduced-phys-bits' field"));
...@@ -6512,7 +6514,6 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitorPtr mon, ...@@ -6512,7 +6514,6 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitorPtr mon,
ret = 0; ret = 0;
cleanup: cleanup:
virSEVCapabilitiesFree(capability);
virJSONValueFree(cmd); virJSONValueFree(cmd);
virJSONValueFree(reply); virJSONValueFree(reply);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册