domain_conf.c: use g_autoptr() with virDomainVideoDefPtr

This will modernize virDomainVideoDefParseXML() and
virDomainDefAddImplicitVideo() by removing unneeded
cleanup labels.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Daniel Henrique Barboza 2020-11-19 17:02:35 -03:00
parent 18d29844c6
commit af7b910c4e

View File

@ -16127,7 +16127,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
unsigned int flags) unsigned int flags)
{ {
virDomainVideoDefPtr def; g_autoptr(virDomainVideoDef) def = NULL;
xmlNodePtr cur; xmlNodePtr cur;
VIR_XPATH_NODE_AUTORESTORE(ctxt) VIR_XPATH_NODE_AUTORESTORE(ctxt)
g_autofree char *type = NULL; g_autofree char *type = NULL;
@ -16168,12 +16168,12 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
if (def->accel == NULL && if (def->accel == NULL &&
virXMLNodeNameEqual(child, "acceleration")) { virXMLNodeNameEqual(child, "acceleration")) {
if ((def->accel = virDomainVideoAccelDefParseXML(child)) == NULL) if ((def->accel = virDomainVideoAccelDefParseXML(child)) == NULL)
goto error; return NULL;
} }
if (def->res == NULL && if (def->res == NULL &&
virXMLNodeNameEqual(child, "resolution")) { virXMLNodeNameEqual(child, "resolution")) {
if ((def->res = virDomainVideoResolutionDefParseXML(child)) == NULL) if ((def->res = virDomainVideoResolutionDefParseXML(child)) == NULL)
goto error; return NULL;
} }
} }
child = child->next; child = child->next;
@ -16181,7 +16181,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
} }
if (virXMLNodeNameEqual(cur, "driver")) { if (virXMLNodeNameEqual(cur, "driver")) {
if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0)
goto error; return NULL;
driver_name = virXMLPropString(cur, "name"); driver_name = virXMLPropString(cur, "name");
} }
} }
@ -16192,7 +16192,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
if ((def->type = virDomainVideoTypeFromString(type)) < 0) { if ((def->type = virDomainVideoTypeFromString(type)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown video model '%s'"), type); _("unknown video model '%s'"), type);
goto error; return NULL;
} }
} else { } else {
def->type = VIR_DOMAIN_VIDEO_TYPE_DEFAULT; def->type = VIR_DOMAIN_VIDEO_TYPE_DEFAULT;
@ -16203,7 +16203,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
if ((backend = virDomainVideoBackendTypeFromString(driver_name)) <= 0) { if ((backend = virDomainVideoBackendTypeFromString(driver_name)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown video driver '%s'"), driver_name); _("unknown video driver '%s'"), driver_name);
goto error; return NULL;
} }
def->backend = backend; def->backend = backend;
} else { } else {
@ -16214,12 +16214,12 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
if (def->type != VIR_DOMAIN_VIDEO_TYPE_QXL) { if (def->type != VIR_DOMAIN_VIDEO_TYPE_QXL) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("ram attribute only supported for type of qxl")); _("ram attribute only supported for type of qxl"));
goto error; return NULL;
} }
if (virStrToLong_uip(ram, NULL, 10, &def->ram) < 0) { if (virStrToLong_uip(ram, NULL, 10, &def->ram) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("cannot parse video ram '%s'"), ram); _("cannot parse video ram '%s'"), ram);
goto error; return NULL;
} }
} }
@ -16227,7 +16227,7 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
if (virStrToLong_uip(vram, NULL, 10, &def->vram) < 0) { if (virStrToLong_uip(vram, NULL, 10, &def->vram) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("cannot parse video vram '%s'"), vram); _("cannot parse video vram '%s'"), vram);
goto error; return NULL;
} }
} }
@ -16235,12 +16235,12 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
if (def->type != VIR_DOMAIN_VIDEO_TYPE_QXL) { if (def->type != VIR_DOMAIN_VIDEO_TYPE_QXL) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("vram64 attribute only supported for type of qxl")); _("vram64 attribute only supported for type of qxl"));
goto error; return NULL;
} }
if (virStrToLong_uip(vram64, NULL, 10, &def->vram64) < 0) { if (virStrToLong_uip(vram64, NULL, 10, &def->vram64) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("cannot parse video vram64 '%s'"), vram64); _("cannot parse video vram64 '%s'"), vram64);
goto error; return NULL;
} }
} }
@ -16248,12 +16248,12 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
if (def->type != VIR_DOMAIN_VIDEO_TYPE_QXL) { if (def->type != VIR_DOMAIN_VIDEO_TYPE_QXL) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("vgamem attribute only supported for type of qxl")); _("vgamem attribute only supported for type of qxl"));
goto error; return NULL;
} }
if (virStrToLong_uip(vgamem, NULL, 10, &def->vgamem) < 0) { if (virStrToLong_uip(vgamem, NULL, 10, &def->vgamem) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("cannot parse video vgamem '%s'"), vgamem); _("cannot parse video vgamem '%s'"), vgamem);
goto error; return NULL;
} }
} }
@ -16261,20 +16261,16 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
if (virStrToLong_uip(heads, NULL, 10, &def->heads) < 0) { if (virStrToLong_uip(heads, NULL, 10, &def->heads) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse video heads '%s'"), heads); _("cannot parse video heads '%s'"), heads);
goto error; return NULL;
} }
} }
if (virDomainDeviceInfoParseXML(xmlopt, node, &def->info, flags) < 0) if (virDomainDeviceInfoParseXML(xmlopt, node, &def->info, flags) < 0)
goto error; return NULL;
def->driver = virDomainVideoDriverDefParseXML(node); def->driver = virDomainVideoDriverDefParseXML(node);
return def; return g_steal_pointer(&def);
error:
virDomainVideoDefFree(def);
return NULL;
} }
static virDomainHostdevDefPtr static virDomainHostdevDefPtr
@ -25008,8 +25004,7 @@ virDomainDefAddImplicitControllers(virDomainDefPtr def)
static int static int
virDomainDefAddImplicitVideo(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt) virDomainDefAddImplicitVideo(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt)
{ {
int ret = -1; g_autoptr(virDomainVideoDef) video = NULL;
virDomainVideoDefPtr video = NULL;
/* For backwards compatibility, if no <video> tag is set but there /* For backwards compatibility, if no <video> tag is set but there
* is a <graphics> tag, then we add a single video tag */ * is a <graphics> tag, then we add a single video tag */
@ -25017,15 +25012,12 @@ virDomainDefAddImplicitVideo(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt)
return 0; return 0;
if (!(video = virDomainVideoDefNew(xmlopt))) if (!(video = virDomainVideoDefNew(xmlopt)))
goto cleanup; return -1;
video->type = VIR_DOMAIN_VIDEO_TYPE_DEFAULT; video->type = VIR_DOMAIN_VIDEO_TYPE_DEFAULT;
if (VIR_APPEND_ELEMENT(def->videos, def->nvideos, video) < 0) if (VIR_APPEND_ELEMENT(def->videos, def->nvideos, video) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
virDomainVideoDefFree(video);
return ret;
} }
int int