]> Pileus Git - ~andy/linux/commitdiff
PCI / ACPI: Use acpi_find_child_device() for child devices lookup
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 28 Nov 2013 22:58:08 +0000 (23:58 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Sat, 7 Dec 2013 00:05:48 +0000 (01:05 +0100)
It is much more efficient to use acpi_find_child_device()
for child devices lookup in acpi_pci_find_device() and pass
ACPI_COMPANION(dev->parent) to it directly instead of obtaining
ACPI_HANDLE() of ACPI_COMPANION(dev->parent) and passing it to
acpi_find_child() which has to run acpi_bus_get_device() to
obtain ACPI_COMPANION(dev->parent) from that again.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com>
drivers/acpi/glue.c
drivers/pci/pci-acpi.c

index ea77512ad70c58e9d660628929cad52c76ab863f..9d200d5029ca5403c7813e9c220de5df90e664ee 100644 (file)
@@ -106,6 +106,9 @@ struct acpi_device *acpi_find_child_device(struct acpi_device *parent,
        struct acpi_device *adev, *ret = NULL;
        int ret_score = 0;
 
+       if (!parent)
+               return NULL;
+
        list_for_each_entry(adev, &parent->children, node) {
                unsigned long long addr;
                acpi_status status;
index 43e3179913265d0801fb60db213cfce8f90b28fe..adbf340039950e1e25b10a2a2840f80352d8fe7b 100644 (file)
@@ -306,7 +306,8 @@ void acpi_pci_remove_bus(struct pci_bus *bus)
 static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
 {
        struct pci_dev *pci_dev = to_pci_dev(dev);
-       bool is_bridge;
+       struct acpi_device *adev;
+       bool check_children;
        u64 addr;
 
        /*
@@ -314,14 +315,17 @@ static int acpi_pci_find_device(struct device *dev, acpi_handle *handle)
         * is set only after acpi_pci_find_device() has been called for the
         * given device.
         */
-       is_bridge = pci_dev->hdr_type == PCI_HEADER_TYPE_BRIDGE
+       check_children = pci_dev->hdr_type == PCI_HEADER_TYPE_BRIDGE
                        || pci_dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
        /* Please ref to ACPI spec for the syntax of _ADR */
        addr = (PCI_SLOT(pci_dev->devfn) << 16) | PCI_FUNC(pci_dev->devfn);
-       *handle = acpi_find_child(ACPI_HANDLE(dev->parent), addr, is_bridge);
-       if (!*handle)
-               return -ENODEV;
-       return 0;
+       adev = acpi_find_child_device(ACPI_COMPANION(dev->parent), addr,
+                                     check_children);
+       if (adev) {
+               *handle = adev->handle;
+               return 0;
+       }
+       return -ENODEV;
 }
 
 static void pci_acpi_setup(struct device *dev)