[PATCH] drm/i915: Make for_each_intel_* macros typesafe

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



So that the compiler warns if we get something wrong.

Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@xxxxxxxxx>
---
 drivers/gpu/drm/i915/i915_drv.h | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index ae4ba6a..871d77a 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -232,30 +232,43 @@ enum hpd_pin {
 	     (__s) < INTEL_INFO(__dev_priv)->num_sprites[(__p)];	\
 	     (__s)++)
 
-#define for_each_crtc(dev, crtc) \
+#define type_check(variable, type)				\
+	{							\
+		typeof(variable) __dummy_ptr = NULL;		\
+		const type *__type_check = __dummy_ptr;		\
+		(void) __type_check;				\
+	}
+
+#define for_each_crtc(dev, crtc)				\
+	type_check(crtc, struct drm_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_crtc(dev, crtc)				\
+	type_check(crtc, struct intel_crtc)			\
+	list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head)
 
-#define for_each_intel_encoder(dev, intel_encoder)		\
-	list_for_each_entry(intel_encoder,			\
+#define for_each_intel_encoder(dev, encoder)			\
+	type_check(encoder, struct intel_encoder)		\
+	list_for_each_entry(encoder,				\
 			    &(dev)->mode_config.encoder_list,	\
 			    base.head)
 
-#define for_each_intel_connector(dev, intel_connector)		\
-	list_for_each_entry(intel_connector,			\
+#define for_each_intel_connector(dev, connector)		\
+	type_check(connector, struct intel_connector);		\
+	list_for_each_entry(connector,				\
 			    &dev->mode_config.connector_list,	\
 			    base.head)
 
 
-#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_encoder_on_crtc(dev, __crtc, encoder)		\
+	type_check(encoder, struct intel_encoder)		\
+	list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, base.head) \
+		if ((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_connector_on_encoder(dev, __encoder, connector) \
+	type_check(connector, struct intel_connector)		\
+	list_for_each_entry((connector), &(dev)->mode_config.connector_list, 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

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/intel-gfx





[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux