Blame SOURCES/kvm-pci-Validate-interfaces-on-base_class_init.patch

9bac43
From 091efe6a8488e0eac52d78fd5db2db76efb891d3 Mon Sep 17 00:00:00 2001
9bac43
From: Eduardo Habkost <ehabkost@redhat.com>
9bac43
Date: Fri, 20 Oct 2017 18:29:17 +0200
9bac43
Subject: [PATCH 12/19] pci: Validate interfaces on base_class_init
9bac43
9bac43
RH-Author: Eduardo Habkost <ehabkost@redhat.com>
9bac43
Message-id: <20171020182917.10771-8-ehabkost@redhat.com>
9bac43
Patchwork-id: 77427
9bac43
O-Subject: [RHV7.5 qemu-kvm-rhev PATCH v2 7/7] pci: Validate interfaces on base_class_init
9bac43
Bugzilla: 1390348
9bac43
RH-Acked-by: Marcel Apfelbaum <marcel@redhat.com>
9bac43
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
9bac43
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
9bac43
9bac43
Make sure we don't forget to add the Conventional PCI or PCI
9bac43
Express interface names on PCI device classes in the future.
9bac43
9bac43
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
9bac43
Revieed-by: David Gibson <david@gibson.dropbear.id.au>
9bac43
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
9bac43
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
9bac43
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
9bac43
(cherry picked from commit 2fefa16cec5a719f5cbc26c0672dd2099cd2ed9b)
9bac43
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
---
9bac43
 hw/pci/pci.c | 12 ++++++++++++
9bac43
 1 file changed, 12 insertions(+)
9bac43
9bac43
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
9bac43
index 1226696..f0c98cd 100644
9bac43
--- a/hw/pci/pci.c
9bac43
+++ b/hw/pci/pci.c
9bac43
@@ -2525,6 +2525,17 @@ static void pci_device_class_init(ObjectClass *klass, void *data)
9bac43
     pc->realize = pci_default_realize;
9bac43
 }
9bac43
 
9bac43
+static void pci_device_class_base_init(ObjectClass *klass, void *data)
9bac43
+{
9bac43
+    if (!object_class_is_abstract(klass)) {
9bac43
+        ObjectClass *conventional =
9bac43
+            object_class_dynamic_cast(klass, INTERFACE_CONVENTIONAL_PCI_DEVICE);
9bac43
+        ObjectClass *pcie =
9bac43
+            object_class_dynamic_cast(klass, INTERFACE_PCIE_DEVICE);
9bac43
+        assert(conventional || pcie);
9bac43
+    }
9bac43
+}
9bac43
+
9bac43
 AddressSpace *pci_device_iommu_address_space(PCIDevice *dev)
9bac43
 {
9bac43
     PCIBus *bus = PCI_BUS(dev->bus);
9bac43
@@ -2649,6 +2660,7 @@ static const TypeInfo pci_device_type_info = {
9bac43
     .abstract = true,
9bac43
     .class_size = sizeof(PCIDeviceClass),
9bac43
     .class_init = pci_device_class_init,
9bac43
+    .class_base_init = pci_device_class_base_init,
9bac43
 };
9bac43
 
9bac43
 static void pci_register_types(void)
9bac43
-- 
9bac43
1.8.3.1
9bac43