On 3/19/21 4:57 PM, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twied...@redhat.com>
---
  src/conf/domain_conf.c | 14 ++------------
  1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9e106b8846..7dfbca12e5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1447,10 +1447,9 @@ static int
  virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap,
                                    xmlNodePtr node)
  {
-    int state_type;
+    virTristateSwitch state_type = VIR_TRISTATE_SWITCH_ABSENT;

Strictly speaking, initializing this is not necessary, because the value is required (by passing true below). At the same time, I like having initialized variables. So this is correct.

      int name_type;
      g_autofree char *name = NULL;
-    g_autofree char *state = NULL;
if (!(name = virXMLPropString(node, "name"))) {
          virReportError(VIR_ERR_CONF_SYNTAX, "%s",
@@ -1464,17 +1463,8 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr 
keywrap,
          return -1;
      }
- if (!(state = virXMLPropString(node, "state"))) {
-        virReportError(VIR_ERR_CONF_SYNTAX,
-                       _("missing state for cipher named %s"), name);
-        return -1;
-    }
-
-    if ((state_type = virTristateSwitchTypeFromString(state)) < 0) {
-        virReportError(VIR_ERR_CONF_SYNTAX,
-                       _("%s is not a supported cipher state"), state);
+    if (virXMLPropTristateSwitch(node, "state", true, &state_type) < 0)
          return -1;
-    }
switch ((virDomainKeyWrapCipherName) name_type) {
      case VIR_DOMAIN_KEY_WRAP_CIPHER_NAME_AES:


Michal

Reply via email to