pci: fix handling of PCI bridges with subordinate bus number 0xff
PATCH 1/1 pci: fix handling of PCI bridges with subordinate bus number 0xff
Bus number 0xff is valid according to the PCI spec. Using u8 typed sub_bus and assigning 0xff to it will result in the following loop getting stuck.
for ( ; sec_bus <= sub_bus; sec_bus++ ) {...}Just change its type to u16 the same way that is already handled in dmar_scope_add_buses().
--- xen/drivers/passthrough/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/drivers/passthrough/pci.c +1 -1
@@ -364,7 +364,7 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn)switch ( pdev->type =pdev_type (pseg->nr, bus, devfn) ) {u16 cap; -u8 sec_bus, sub_bus; +u16 sec_bus, sub_bus;case DEV_TYPE_PCIe2PCI_BRIDGE:case DEV_TYPE_LEGACY_PCI_BRIDGE :
Signature · 1 line
2.7.4
xen/drivers/passthrough/pci.c static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn) · line 370
Quoted 11 lines · Igor Druzhinin
xen/drivers/passthrough/pci.c +1
-1@@ -364,7 +364,7 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn)switch ( pdev->type =pdev_type (pseg->nr, bus, devfn) ) {u16 cap; -u8 sec_bus, sub_bus; +u16 sec_bus, sub_bus;case DEV_TYPE_PCIe2PCI_BRIDGE:case DEV_TYPE_LEGACY_PCI_BRIDGE :
First of all you want to also address the same issue in free_pdev() then. Further, since we're switching away from u16, uint16_t would be the legitimate replacement. Plus, since cap is then of the same type, fold all three variable declarations into a single line. Finally, as per ./CODING_STYLE, fixed width types should be used only where strictly needed. I can't see a reason for any of these to be other than "unsigned int".
Jan