All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] PCI: Add a pci_dev_depth() helper function
@ 2021-11-29 12:19 Hans de Goede
  2021-11-29 12:19 ` [PATCH 2/2] PCI: pciehp: Use down_read/write_nested(reset_lock) to fix lockdep errors Hans de Goede
  0 siblings, 1 reply; 9+ messages in thread
From: Hans de Goede @ 2021-11-29 12:19 UTC (permalink / raw)
  To: Bjorn Helgaas, Lukas Wunner
  Cc: Hans de Goede, Theodore Ts'o, Andreas Noever, Michael Jamet,
	Mika Westerberg, Yehezkel Bernat, linux-pci

Add a pci_dev_depth() helper function, which returns the depth
of a device in the PCI hierarchy.

This is useful to have for lockdep annotations for dealing with
nested locked when traversing the hierarchy.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 include/linux/pci.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/include/linux/pci.h b/include/linux/pci.h
index 7d825637d7ca..6ad78cc67aa8 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -691,6 +691,26 @@ static inline bool pci_is_bridge(struct pci_dev *dev)
 		dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
 }
 
+/**
+ * pci_dev_depth - Return the depth of a device in the PCI hierarchy
+ * @dev: PCI device
+ *
+ * Return the depth (number of parent busses above) the device in
+ * the PCI hierarchy.
+ */
+static inline int pci_dev_depth(struct pci_dev *dev)
+{
+	struct pci_bus *bus = dev->bus;
+	int depth = 0;
+
+	while (bus->parent) {
+		depth++;
+		bus = bus->parent;
+	}
+
+	return depth;
+}
+
 #define for_each_pci_bridge(dev, bus)				\
 	list_for_each_entry(dev, &bus->devices, bus_list)	\
 		if (!pci_is_bridge(dev)) {} else
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-12-02 11:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-29 12:19 [PATCH 1/2] PCI: Add a pci_dev_depth() helper function Hans de Goede
2021-11-29 12:19 ` [PATCH 2/2] PCI: pciehp: Use down_read/write_nested(reset_lock) to fix lockdep errors Hans de Goede
2021-11-29 15:39   ` Lukas Wunner
2021-11-29 18:59     ` Lukas Wunner
2021-11-30 10:15       ` Hans de Goede
2021-11-30 19:39         ` Lukas Wunner
2021-12-02 11:52           ` Hans de Goede
2021-11-29 15:45   ` Lukas Wunner
2021-11-29 23:45   ` Bjorn Helgaas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.