]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: domain: Parse 'type' attribute via virXMLPropEnum in virSysinfoParseXML
authorPeter Krempa <pkrempa@redhat.com>
Thu, 6 Oct 2022 10:30:26 +0000 (12:30 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 2 Nov 2022 08:22:56 +0000 (09:22 +0100)
Rewrite the code to use the simple helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c

index f32eeaa94feb44770261385a3a7e2ae2a07f02fd..2537aa808f6b9d0aab895c2b56f92efd3bf089a7 100644 (file)
@@ -12395,8 +12395,6 @@ virSysinfoParseXML(xmlNodePtr node,
 {
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     virSysinfoDef *def;
-    g_autofree char *typeStr = NULL;
-    int type;
 
     ctxt->node = node;
 
@@ -12408,18 +12406,9 @@ virSysinfoParseXML(xmlNodePtr node,
 
     def = g_new0(virSysinfoDef, 1);
 
-    typeStr = virXMLPropString(node, "type");
-    if (typeStr == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("sysinfo must contain a type attribute"));
-        goto error;
-    }
-    if ((type = virSysinfoTypeFromString(typeStr)) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown sysinfo type '%s'"), typeStr);
+    if (virXMLPropEnum(node, "type", virSysinfoTypeFromString,
+                       VIR_XML_PROP_REQUIRED, &def->type) < 0)
         goto error;
-    }
-    def->type = type;
 
     switch (def->type) {
     case VIR_SYSINFO_SMBIOS: