Skip to contentSkip to conversation

PCI: define max devices number on PCIBus as PCIBus_MAX_DEVICES in pci.h

PATCH New Ken CC 1 participant 2 messages Aug 12, 2010

lore
Share & tools
lore

Ken CC

author
#0 lore raw

PATCH 1/1 PCI: define max devices number on PCIBus as PCIBus_MAX_DEVICES in pci.h

---
 hw/pci.c |    2 +-
 hw/pci.h |    1 +
 2 files changed, 2 insertions(+), 1 deletions(-)
hw/pci.c +1 -1
index a98d6f3..a09fbac 100644
@@ -44,7 +44,7 @@ struct PCIBus {
     pci_hotplug_fn hotplug;
     DeviceState *hotplug_qdev;
     void *irq_opaque;
-    PCIDevice *devices[256];
+    PCIDevice *devices[PCIBUS_MAX_DEVICES];
     PCIDevice *parent_dev;
     target_phys_addr_t mem_base;
 
hw/pci.h +1 -0
index 1eab7e7..5f6c85b 100644
@@ -92,6 +92,7 @@ typedef struct PCIIORegion {
 
 #define PCI_ROM_SLOT 6
 #define PCI_NUM_REGIONS 7
+#define PCIBUS_MAX_DEVICES 256
 
 #include "pci_regs.h"
 
author
#1 lore raw

PATCH 2/2 pci init: Check if devfn exceeding the max devices number supported on bus

Check before trying subindexing.

---
 hw/pci.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
hw/pci.c +4 -0
index a09fbac..f6f00c6 100644
@@ -675,6 +675,10 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
         error_report("PCI: no slot/function available for %s, all in use", name);
         return NULL;
     found: ;
+    } else if (devfn > PCIBUS_MAX_DEVICES - 1) {
+        error_report("PCI: devfn is out of bus capacity."
+                        " Only %d devices supported.", PCIBUS_MAX_DEVICES);
+        return NULL;
     } else if (bus->devices[devfn]) {
         error_report("PCI: slot %d function %d not available for %s, in use by %s",
                      PCI_SLOT(devfn), PCI_FUNC(devfn), name, bus->devices[devfn]->name);