Skip to content

Commit 9f8bee9

Browse files
jgross1David Vrabel
authored andcommitted
xen/pciback: avoid multiple entries in slot list
The Xen pciback driver has a list of all pci devices it is ready to seize. There is no check whether a to be added entry already exists. While this might be no problem in the common case it might confuse those which consume the list via sysfs. Modify the handling of this list by not adding an entry which already exists. As this will be needed later split out the list handling into a separate function. Signed-off-by: Juergen Gross <[email protected]> Signed-off-by: David Vrabel <[email protected]>
1 parent 1af916b commit 9f8bee9

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

drivers/xen/xen-pciback/pci_stub.c

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,36 @@ static int __init pcistub_init_devices_late(void)
478478
return 0;
479479
}
480480

481+
static void pcistub_device_id_add_list(struct pcistub_device_id *new,
482+
int domain, int bus, unsigned int devfn)
483+
{
484+
struct pcistub_device_id *pci_dev_id;
485+
unsigned long flags;
486+
int found = 0;
487+
488+
spin_lock_irqsave(&device_ids_lock, flags);
489+
490+
list_for_each_entry(pci_dev_id, &pcistub_device_ids, slot_list) {
491+
if (pci_dev_id->domain == domain && pci_dev_id->bus == bus &&
492+
pci_dev_id->devfn == devfn) {
493+
found = 1;
494+
break;
495+
}
496+
}
497+
498+
if (!found) {
499+
new->domain = domain;
500+
new->bus = bus;
501+
new->devfn = devfn;
502+
list_add_tail(&new->slot_list, &pcistub_device_ids);
503+
}
504+
505+
spin_unlock_irqrestore(&device_ids_lock, flags);
506+
507+
if (found)
508+
kfree(new);
509+
}
510+
481511
static int pcistub_seize(struct pci_dev *dev)
482512
{
483513
struct pcistub_device *psdev;
@@ -1012,7 +1042,6 @@ static inline int str_to_quirk(const char *buf, int *domain, int *bus, int
10121042
static int pcistub_device_id_add(int domain, int bus, int slot, int func)
10131043
{
10141044
struct pcistub_device_id *pci_dev_id;
1015-
unsigned long flags;
10161045
int rc = 0, devfn = PCI_DEVFN(slot, func);
10171046

10181047
if (slot < 0) {
@@ -1042,16 +1071,10 @@ static int pcistub_device_id_add(int domain, int bus, int slot, int func)
10421071
if (!pci_dev_id)
10431072
return -ENOMEM;
10441073

1045-
pci_dev_id->domain = domain;
1046-
pci_dev_id->bus = bus;
1047-
pci_dev_id->devfn = devfn;
1048-
10491074
pr_debug("wants to seize %04x:%02x:%02x.%d\n",
10501075
domain, bus, slot, func);
10511076

1052-
spin_lock_irqsave(&device_ids_lock, flags);
1053-
list_add_tail(&pci_dev_id->slot_list, &pcistub_device_ids);
1054-
spin_unlock_irqrestore(&device_ids_lock, flags);
1077+
pcistub_device_id_add_list(pci_dev_id, domain, bus, devfn);
10551078

10561079
return 0;
10571080
}

0 commit comments

Comments
 (0)