@@ -812,10 +812,15 @@ static uint32_t pci_data_read_common(PCIDevice *pci_dev,
static inline PCIDevice *pci_addr_to_dev(PCIBus *bus, uint32_t addr)
{
- int bus_num = (addr >> 16) & 0xff;
- unsigned int devfn = (addr >> 8) & 0xff;
+ uint8_t bus_num = (addr >> 16) & 0xff;
+ uint8_t devfn = (addr >> 8) & 0xff;
+ PCIBus *s = pci_find_bus(bus, bus_num);
- return pci_find_device(bus, bus_num, PCI_SLOT(devfn), PCI_FUNC(devfn));
+ if (!s) {
+ return NULL;
+ }
+
+ return pci_find_device(s, bus_num, PCI_SLOT(devfn), PCI_FUNC(devfn));
}
static inline uint32_t pci_addr_to_config(uint32_t addr)