[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH] PCI: avoid bogus calls to get_pseg()
When passed -1, the function (taking a u16) will look for segment 0xffff, which might exist. If it exists, we may find (return) the wrong device. Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx> --- An alternative would be to declare that both functions cannot be called with "wildcards" anymore. The last such use went away with f591755823a7 ("IOMMU/PCI: don't let domain cleanup continue when device de-assignment failed") afaict. Each time I look at this pair of functions I wonder why we have two copies of almost the same code (with a curious difference of only one having ASSERT(pcidevs_locked())). Any opinions on deleting either one, subsuming its functionality into the other one by allowing the domain pointer to be NULL to signify "any"? --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -578,20 +578,19 @@ int __init pci_ro_device(int seg, int bu struct pci_dev *pci_get_pdev(int seg, int bus, int devfn) { - struct pci_seg *pseg = get_pseg(seg); + struct pci_seg *pseg = NULL; struct pci_dev *pdev = NULL; ASSERT(pcidevs_locked()); ASSERT(seg != -1 || bus == -1); ASSERT(bus != -1 || devfn == -1); + if ( seg == -1 ) + radix_tree_gang_lookup(&pci_segments, (void **)&pseg, 0, 1); + else + pseg = get_pseg(seg); if ( !pseg ) - { - if ( seg == -1 ) - radix_tree_gang_lookup(&pci_segments, (void **)&pseg, 0, 1); - if ( !pseg ) - return NULL; - } + return NULL; do { list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) @@ -628,19 +627,18 @@ struct pci_dev *pci_get_real_pdev(int se struct pci_dev *pci_get_pdev_by_domain(const struct domain *d, int seg, int bus, int devfn) { - struct pci_seg *pseg = get_pseg(seg); + struct pci_seg *pseg = NULL; struct pci_dev *pdev = NULL; ASSERT(seg != -1 || bus == -1); ASSERT(bus != -1 || devfn == -1); + if ( seg == -1 ) + radix_tree_gang_lookup(&pci_segments, (void **)&pseg, 0, 1); + else + pseg = get_pseg(seg); if ( !pseg ) - { - if ( seg == -1 ) - radix_tree_gang_lookup(&pci_segments, (void **)&pseg, 0, 1); - if ( !pseg ) - return NULL; - } + return NULL; do { list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list )
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |