Skip to content

Commit

Permalink
PCI: Use list_for_each_entry() for bus->devices traversal
Browse files Browse the repository at this point in the history
Replace list_for_each() + pci_dev_b() with the simpler
list_for_each_entry().

Tested-by: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
  • Loading branch information
Bjorn Helgaas committed Aug 22, 2012
1 parent 125e14b commit 66455f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
13 changes: 6 additions & 7 deletions drivers/pci/remove.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,17 @@ void pci_stop_and_remove_bus_device(struct pci_dev *dev)

static void __pci_remove_behind_bridge(struct pci_dev *dev)
{
struct list_head *l, *n;
struct pci_dev *child, *tmp;

if (dev->subordinate)
list_for_each_safe(l, n, &dev->subordinate->devices)
__pci_remove_bus_device(pci_dev_b(l));
list_for_each_entry_safe(child, tmp,
&dev->subordinate->devices, bus_list)
__pci_remove_bus_device(child);
}

static void pci_stop_bus_devices(struct pci_bus *bus)
{
struct list_head *l, *n;
struct pci_dev *dev, *tmp;

/*
* VFs could be removed by pci_stop_and_remove_bus_device() in the
Expand All @@ -133,10 +134,8 @@ static void pci_stop_bus_devices(struct pci_bus *bus)
* We can iterate the list backwards to get prev valid PF instead
* of removed VF.
*/
list_for_each_prev_safe(l, n, &bus->devices) {
struct pci_dev *dev = pci_dev_b(l);
list_for_each_entry_safe_reverse(dev, tmp, &bus->devices, bus_list)
pci_stop_bus_device(dev);
}
}

/**
Expand Down
6 changes: 2 additions & 4 deletions drivers/pci/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,14 @@ pci_find_next_bus(const struct pci_bus *from)
* decrement the reference count by calling pci_dev_put().
* If no device is found, %NULL is returned.
*/
struct pci_dev * pci_get_slot(struct pci_bus *bus, unsigned int devfn)
struct pci_dev *pci_get_slot(struct pci_bus *bus, unsigned int devfn)
{
struct list_head *tmp;
struct pci_dev *dev;

WARN_ON(in_interrupt());
down_read(&pci_bus_sem);

list_for_each(tmp, &bus->devices) {
dev = pci_dev_b(tmp);
list_for_each_entry(dev, &bus->devices, bus_list) {
if (dev->devfn == devfn)
goto out;
}
Expand Down

0 comments on commit 66455f5

Please sign in to comment.