提交 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 @@
# include "internal.h"
# include "domain_conf.h"
# include "viralloc.h"
typedef const char * (*virDomainCapsValToStr)(int value);
......@@ -215,4 +216,7 @@ char * virDomainCapsFormat(virDomainCapsPtr const caps);
void
virSEVCapabilitiesFree(virSEVCapability *capabilities);
VIR_DEFINE_AUTOPTR_FUNC(virSEVCapability, virSEVCapabilitiesFree);
#endif /* __DOMAIN_CAPABILITIES_H__ */
......@@ -5263,9 +5263,8 @@ static int
virQEMUCapsFillDomainFeatureSEVCaps(virQEMUCapsPtr qemuCaps,
virDomainCapsPtr domCaps)
{
virSEVCapability *sev;
virSEVCapability *cap = qemuCaps->sevCapabilities;
int ret = -1;
VIR_AUTOPTR(virSEVCapability) sev = NULL;
if (!cap)
return 0;
......@@ -5274,19 +5273,16 @@ virQEMUCapsFillDomainFeatureSEVCaps(virQEMUCapsPtr qemuCaps,
return -1;
if (VIR_STRDUP(sev->pdh, cap->pdh) < 0)
goto cleanup;
return -1;
if (VIR_STRDUP(sev->cert_chain, cap->cert_chain) < 0)
goto cleanup;
return -1;
sev->cbitpos = cap->cbitpos;
sev->reduced_phys_bits = cap->reduced_phys_bits;
VIR_STEAL_PTR(domCaps->sev, sev);
ret = 0;
cleanup:
virSEVCapabilitiesFree(sev);
return ret;
return 0;
}
......
......@@ -6443,9 +6443,11 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitorPtr mon,
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr caps;
virSEVCapability *capability = NULL;
const char *pdh = NULL, *cert_chain = NULL;
unsigned int cbitpos, reduced_phys_bits;
const char *pdh = NULL;
const char *cert_chain = NULL;
unsigned int cbitpos;
unsigned int reduced_phys_bits;
VIR_AUTOPTR(virSEVCapability) capability = NULL;
*capabilities = NULL;
......@@ -6476,7 +6478,7 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitorPtr mon,
}
if (virJSONValueObjectGetNumberUint(caps, "reduced-phys-bits",
&reduced_phys_bits) < 0) {
&reduced_phys_bits) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-sev-capabilities reply was missing"
" 'reduced-phys-bits' field"));
......@@ -6512,7 +6514,6 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitorPtr mon,
ret = 0;
cleanup:
virSEVCapabilitiesFree(capability);
virJSONValueFree(cmd);
virJSONValueFree(reply);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册