* [PATCH] drm/i915: Replace __I915__ with typesafe variant
@ 2014-08-13 11:14 Chris Wilson
2014-08-13 11:40 ` Daniel Vetter
0 siblings, 1 reply; 2+ messages in thread
From: Chris Wilson @ 2014-08-13 11:14 UTC (permalink / raw)
To: intel-gfx
Ville pointed out the GCCism __builtin_types_compatible_p() that we
could use to replace our heavily casted presumption __I915__ macro that
was based on comparing struct sizes.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_dma.c | 3 ---
drivers/gpu/drm/i915/i915_drv.h | 12 ++++++++++--
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 5e3b1390ac5c..b2e4dbcb77ae 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1582,9 +1582,6 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
if (!drm_core_check_feature(dev, DRIVER_MODESET) && !dev->agp)
return -EINVAL;
- /* For the ugly agnostic INTEL_INFO macro */
- BUILD_BUG_ON(sizeof(*dev_priv) == sizeof(*dev));
-
BUILD_BUG_ON(I915_NUM_RINGS >= (1 << I915_NUM_RING_BITS));
dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index d1513e6ea50d..b6dcbf79b31c 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2081,8 +2081,16 @@ struct drm_i915_cmd_table {
};
/* Note that the (struct drm_i915_private *) cast is just to shut up gcc. */
-#define __I915__(p) ((sizeof(*(p)) == sizeof(struct drm_i915_private)) ? \
- (struct drm_i915_private *)(p) : to_i915(p))
+#define __I915__(p) ({ \
+ struct drm_i915_private *__p; \
+ if (__builtin_types_compatible_p(typeof(*p), struct drm_i915_private)) \
+ __p = (struct drm_i915_private *)p; \
+ else if (__builtin_types_compatible_p(typeof(*p), struct drm_device)) \
+ __p = to_i915((struct drm_device *)p); \
+ else \
+ BUILD_BUG(); \
+ __p; \
+})
#define INTEL_INFO(p) (&__I915__(p)->info)
#define INTEL_DEVID(p) (INTEL_INFO(p)->device_id)
--
2.1.0.rc1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drm/i915: Replace __I915__ with typesafe variant
2014-08-13 11:14 [PATCH] drm/i915: Replace __I915__ with typesafe variant Chris Wilson
@ 2014-08-13 11:40 ` Daniel Vetter
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Vetter @ 2014-08-13 11:40 UTC (permalink / raw)
To: Chris Wilson; +Cc: intel-gfx
On Wed, Aug 13, 2014 at 12:14:12PM +0100, Chris Wilson wrote:
> Ville pointed out the GCCism __builtin_types_compatible_p() that we
> could use to replace our heavily casted presumption __I915__ macro that
> was based on comparing struct sizes.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Yeah, that looks a bit less crazy. Queued for -next, thanks for the patch.
-Daniel
> ---
> drivers/gpu/drm/i915/i915_dma.c | 3 ---
> drivers/gpu/drm/i915/i915_drv.h | 12 ++++++++++--
> 2 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
> index 5e3b1390ac5c..b2e4dbcb77ae 100644
> --- a/drivers/gpu/drm/i915/i915_dma.c
> +++ b/drivers/gpu/drm/i915/i915_dma.c
> @@ -1582,9 +1582,6 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
> if (!drm_core_check_feature(dev, DRIVER_MODESET) && !dev->agp)
> return -EINVAL;
>
> - /* For the ugly agnostic INTEL_INFO macro */
> - BUILD_BUG_ON(sizeof(*dev_priv) == sizeof(*dev));
> -
> BUILD_BUG_ON(I915_NUM_RINGS >= (1 << I915_NUM_RING_BITS));
>
> dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index d1513e6ea50d..b6dcbf79b31c 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -2081,8 +2081,16 @@ struct drm_i915_cmd_table {
> };
>
> /* Note that the (struct drm_i915_private *) cast is just to shut up gcc. */
> -#define __I915__(p) ((sizeof(*(p)) == sizeof(struct drm_i915_private)) ? \
> - (struct drm_i915_private *)(p) : to_i915(p))
> +#define __I915__(p) ({ \
> + struct drm_i915_private *__p; \
> + if (__builtin_types_compatible_p(typeof(*p), struct drm_i915_private)) \
> + __p = (struct drm_i915_private *)p; \
> + else if (__builtin_types_compatible_p(typeof(*p), struct drm_device)) \
> + __p = to_i915((struct drm_device *)p); \
> + else \
> + BUILD_BUG(); \
> + __p; \
> +})
> #define INTEL_INFO(p) (&__I915__(p)->info)
> #define INTEL_DEVID(p) (INTEL_INFO(p)->device_id)
>
> --
> 2.1.0.rc1
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-08-13 11:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-13 11:14 [PATCH] drm/i915: Replace __I915__ with typesafe variant Chris Wilson
2014-08-13 11:40 ` Daniel Vetter
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.