mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
domain_conf.c: modernize virDomainDefControllersParse()
The 'error' label is just returning -1, so let's 'return -1' directly. Use g_autoptr() with virDomainControllerDefPtr to remove the need to call virDomainControllerDefFree() in the error path. There is no need to VIR_FREE(nodes) explictly since 'nodes' is using g_autofree. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
491bc80d6b
commit
0436a14468
@ -21731,38 +21731,36 @@ virDomainDefControllersParse(virDomainDefPtr def,
|
||||
int n;
|
||||
|
||||
if ((n = virXPathNodeSet("./devices/controller", ctxt, &nodes)) < 0)
|
||||
goto error;
|
||||
return -1;
|
||||
|
||||
if (n)
|
||||
def->controllers = g_new0(virDomainControllerDefPtr, n);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
virDomainControllerDefPtr controller = virDomainControllerDefParseXML(xmlopt,
|
||||
nodes[i],
|
||||
ctxt,
|
||||
flags);
|
||||
g_autoptr(virDomainControllerDef) controller = NULL;
|
||||
|
||||
controller = virDomainControllerDefParseXML(xmlopt, nodes[i],
|
||||
ctxt, flags);
|
||||
|
||||
if (!controller)
|
||||
goto error;
|
||||
return -1;
|
||||
|
||||
/* sanitize handling of "none" usb controller */
|
||||
if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) {
|
||||
if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) {
|
||||
if (usb_other || *usb_none) {
|
||||
virDomainControllerDefFree(controller);
|
||||
virReportError(VIR_ERR_XML_DETAIL, "%s",
|
||||
_("Can't add another USB controller: "
|
||||
"USB is disabled for this domain"));
|
||||
goto error;
|
||||
return -1;
|
||||
}
|
||||
*usb_none = true;
|
||||
} else {
|
||||
if (*usb_none) {
|
||||
virDomainControllerDefFree(controller);
|
||||
virReportError(VIR_ERR_XML_DETAIL, "%s",
|
||||
_("Can't add another USB controller: "
|
||||
"USB is disabled for this domain"));
|
||||
goto error;
|
||||
return -1;
|
||||
}
|
||||
usb_other = true;
|
||||
}
|
||||
@ -21771,20 +21769,16 @@ virDomainDefControllersParse(virDomainDefPtr def,
|
||||
usb_master = true;
|
||||
}
|
||||
|
||||
virDomainControllerInsertPreAlloced(def, controller);
|
||||
virDomainControllerInsertPreAlloced(def, g_steal_pointer(&controller));
|
||||
}
|
||||
VIR_FREE(nodes);
|
||||
|
||||
if (usb_other && !usb_master) {
|
||||
virReportError(VIR_ERR_XML_DETAIL, "%s",
|
||||
_("No master USB controller specified"));
|
||||
goto error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static virDomainDefPtr
|
||||
|
Loading…
x
Reference in New Issue
Block a user