PCI: Document pci_bus_for_each_resource()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 30 Mar 2023 16:24:31 +0000 (19:24 +0300)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 4 Apr 2023 15:47:11 +0000 (10:47 -0500)
There might be confusion about why pci_bus_for_each_resource() uses
Logical OR. Document the entire macro and explain how it works and why the
conditional needs to be like that.

Link: https://lore.kernel.org/r/20230330162434.35055-5-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
include/linux/pci.h

index 2234ef9..db31555 100644 (file)
@@ -1444,6 +1444,26 @@ int devm_request_pci_bus_resources(struct device *dev,
 /* Temporary until new and working PCI SBR API in place */
 int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
 
+/**
+ * pci_bus_for_each_resource - iterate over PCI bus resources
+ * @bus: the PCI bus
+ * @res: pointer to the current resource
+ * @i: index of the current resource
+ *
+ * Iterate over PCI bus resources. The first part is to go over PCI bus
+ * resource array, which has at most the %PCI_BRIDGE_RESOURCE_NUM entries.
+ * After that continue with the separate list of the additional resources,
+ * if not empty. That's why the Logical OR is being used.
+ *
+ * Possible usage:
+ *
+ *     struct pci_bus *bus = ...;
+ *     struct resource *res;
+ *     unsigned int i;
+ *
+ *     pci_bus_for_each_resource(bus, res, i)
+ *             pr_info("PCI bus resource[%u]: %pR\n", i, res);
+ */
 #define pci_bus_for_each_resource(bus, res, i)                         \
        for (i = 0;                                                     \
            (res = pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \