[Intel-gfx] [PATCH] drm/i915: Make for_each_intel_* macros typesafe
Ander Conselvan de Oliveira
ander.conselvan.de.oliveira at intel.com
Mon Mar 16 05:51:00 PDT 2015
So that the compiler warns if we get something wrong.
v2: Don't break 'if (foo) for_each_*' usage. (Jani & Chris)
Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>
---
drivers/gpu/drm/i915/i915_drv.h | 63 ++++++++++++++++++++++++++---------------
1 file changed, 40 insertions(+), 23 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index ae4ba6a..55fc10d 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -232,30 +232,47 @@ enum hpd_pin {
(__s) < INTEL_INFO(__dev_priv)->num_sprites[(__p)]; \
(__s)++)
-#define for_each_crtc(dev, crtc) \
- list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
-
-#define for_each_intel_crtc(dev, intel_crtc) \
- list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, base.head)
-
-#define for_each_intel_encoder(dev, intel_encoder) \
- list_for_each_entry(intel_encoder, \
- &(dev)->mode_config.encoder_list, \
- base.head)
-
-#define for_each_intel_connector(dev, intel_connector) \
- list_for_each_entry(intel_connector, \
- &dev->mode_config.connector_list, \
- base.head)
+#define __list_for_each_entry_type(pos, head, type, member) \
+ for (pos = list_first_entry(head, type, member); \
+ &pos->member != (head); \
+ pos = list_next_entry(pos, member))
-
-#define for_each_encoder_on_crtc(dev, __crtc, intel_encoder) \
- list_for_each_entry((intel_encoder), &(dev)->mode_config.encoder_list, base.head) \
- if ((intel_encoder)->base.crtc == (__crtc))
-
-#define for_each_connector_on_encoder(dev, __encoder, intel_connector) \
- list_for_each_entry((intel_connector), &(dev)->mode_config.connector_list, base.head) \
- if ((intel_connector)->base.encoder == (__encoder))
+#define for_each_crtc(dev, crtc) \
+ __list_for_each_entry_type(crtc, \
+ &dev->mode_config.crtc_list, \
+ struct drm_crtc, \
+ head)
+
+#define for_each_intel_crtc(dev, crtc) \
+ __list_for_each_entry_type(crtc, \
+ &dev->mode_config.crtc_list, \
+ struct intel_crtc, base.head)
+
+#define for_each_intel_encoder(dev, encoder) \
+ __list_for_each_entry_type(encoder, \
+ &(dev)->mode_config.encoder_list, \
+ struct intel_encoder, \
+ base.head)
+
+#define for_each_intel_connector(dev, connector) \
+ __list_for_each_entry_type(connector, \
+ &dev->mode_config.connector_list, \
+ struct intel_connector, \
+ base.head)
+
+
+#define for_each_encoder_on_crtc(dev, __crtc, encoder) \
+ __list_for_each_entry_type((encoder), \
+ &(dev)->mode_config.encoder_list,\
+ struct intel_encoder, base.head) \
+ if ((encoder)->base.crtc == (__crtc))
+
+#define for_each_connector_on_encoder(dev, __encoder, connector) \
+ __list_for_each_entry_type((connector), \
+ &(dev)->mode_config.connector_list, \
+ struct intel_connector, \
+ base.head) \
+ if ((connector)->base.encoder == (__encoder))
#define for_each_power_domain(domain, mask) \
for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
--
2.1.0
More information about the Intel-gfx
mailing list