[PATCH i-g-t 1/3] lib/kms: Avoid local iterator variable in for_each_output()

Ville Syrjala
2026-04-13T20:00:47Z

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Rewrite for_each_output() into a form where we don't need the
extra iterator variable. This will allow nested use of the
iterator.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
lib/igt_kms.h | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 9a3fa980d89d..57824b82f5f9 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -689,9 +689,10 @@ static inline bool igt_crtc_connector_valid(igt_crtc_t *crtc, igt_output_t *outp
*
* This for loop iterates over all outputs.
*/
-#define for_each_output(display, output) \
- for (int i__ = 0; assert(igt_can_fail()), i__ < (display)->n_outputs; i__++) \
- for_each_if (((output) = (&(display)->outputs[i__])))
+#define for_each_output(display, output) \
+ for ((output) = &(display)->outputs[0]; \
+ (output) < &(display)->outputs[(display)->n_outputs]; \
+ (output)++)

/**
* for_each_connected_output:
--
2.52.0