]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Make switch statements more strict
authorAndrea Bolognani <abologna@redhat.com>
Tue, 21 Feb 2017 19:13:47 +0000 (20:13 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Wed, 22 Feb 2017 17:55:55 +0000 (18:55 +0100)
When switching over the values in the virDomainControllerModelPCI
enumeration, make sure the proper cast is in place so that the
compiler can warn us when the coverage is not exaustive.

For the same reason, remove the 'default' case from one of the
existing switch statements.

src/conf/domain_addr.c
src/conf/domain_conf.c

index 519cc6bb233c1711222ac8fdb3a4b315d435c096..35bdc34537e158f5365ada8461cff94069a4365e 100644 (file)
@@ -344,9 +344,9 @@ virDomainPCIAddressBusSetModel(virDomainPCIAddressBusPtr bus,
         bus->maxSlot = VIR_PCI_ADDRESS_SLOT_LAST;
         break;
 
-    default:
+    case VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Invalid PCI controller model %d"), model);
+                       "%s", _("PCI controller model was not set correctly"));
         return -1;
     }
 
index f718b9abc5133d6050be3027a7bcf109fd7377d3..b7b5b7e7d7abda2f6fd8c66a9ba500173f160a99 100644 (file)
@@ -8834,7 +8834,7 @@ virDomainControllerDefParseXML(xmlNodePtr node,
         break;
     }
     case VIR_DOMAIN_CONTROLLER_TYPE_PCI:
-        switch (def->model) {
+        switch ((virDomainControllerModelPCI) def->model) {
         case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT:
         case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT: {
             unsigned long long bytes;
@@ -8859,6 +8859,16 @@ virDomainControllerDefParseXML(xmlNodePtr node,
                 def->opts.pciopts.pcihole64 = true;
             def->opts.pciopts.pcihole64size = VIR_DIV_UP(bytes, 1024);
         }
+        case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
+        case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE:
+        case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT:
+        case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT:
+        case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_DOWNSTREAM_PORT:
+        case VIR_DOMAIN_CONTROLLER_MODEL_PCI_EXPANDER_BUS:
+        case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_EXPANDER_BUS:
+        case VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST:
+            /* Other controller models don't require extra checks */
+            break;
         }
         if (modelName &&
             (def->opts.pciopts.modelName