]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/bridge: add drm_for_each_bridge_in_chain_from()
authorLuca Ceresoli <luca.ceresoli@bootlin.com>
Fri, 8 Aug 2025 14:49:15 +0000 (16:49 +0200)
committerLuca Ceresoli <luca.ceresoli@bootlin.com>
Tue, 16 Sep 2025 13:02:50 +0000 (15:02 +0200)
Add variant of drm_for_each_bridge_in_chain_scoped() that iterates on the
encoder bridge from a given bridge until the end of the chain.

Reviewed-by: Maxime Ripard <mripard@kernel.org>
Link: https://lore.kernel.org/r/20250808-drm-bridge-alloc-getput-for_each_bridge-v2-8-edb6ee81edf1@bootlin.com
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
include/drm/drm_bridge.h

index c45dece368ad3913e3025d1f8a268eca8946e5ff..d1aba4e25d354205d588480dc8032b969d92b912 100644 (file)
@@ -1471,6 +1471,25 @@ drm_bridge_get_next_bridge_and_put(struct drm_bridge *bridge)
             bridge;                                                    \
             bridge = drm_bridge_get_next_bridge_and_put(bridge))
 
+/**
+ * drm_for_each_bridge_in_chain_from - iterate over all bridges starting
+ *                                     from the given bridge
+ * @first_bridge: the bridge to start from
+ * @bridge: a bridge pointer updated to point to the current bridge at each
+ *         iteration
+ *
+ * Iterate over all bridges in the encoder chain starting from
+ * @first_bridge, included.
+ *
+ * Automatically gets/puts the bridge reference while iterating, and puts
+ * the reference even if returning or breaking in the middle of the loop.
+ */
+#define drm_for_each_bridge_in_chain_from(first_bridge, bridge)                \
+       for (struct drm_bridge *bridge __free(drm_bridge_put) =         \
+                    drm_bridge_get(first_bridge);                      \
+            bridge;                                                    \
+            bridge = drm_bridge_get_next_bridge_and_put(bridge))
+
 enum drm_mode_status
 drm_bridge_chain_mode_valid(struct drm_bridge *bridge,
                            const struct drm_display_info *info,