On Wed, Jul 20, 2016 at 12:28:16PM +0100, Dave Gordon wrote: > On 20/07/16 09:59, Chris Wilson wrote: > >For symmetry with a forthcoming i915_gem_object_get() and > >i915_gem_object_pu(). > > > >Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx> > >--- > > drivers/gpu/drm/i915/i915_drv.h | 20 +++++++++++- > > drivers/gpu/drm/i915/i915_gem.c | 58 +++++++++++++++++----------------- > > drivers/gpu/drm/i915/i915_gem_tiling.c | 8 ++--- > > drivers/gpu/drm/i915/intel_display.c | 4 +-- > > drivers/gpu/drm/i915/intel_overlay.c | 5 ++- > > 5 files changed, 56 insertions(+), 39 deletions(-) > > > >diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h > >index 2131e7f1e57a..47f244f9c64e 100644 > >--- a/drivers/gpu/drm/i915/i915_drv.h > >+++ b/drivers/gpu/drm/i915/i915_drv.h > >@@ -2286,7 +2286,25 @@ struct drm_i915_gem_object { > > } userptr; > > }; > > }; > >-#define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base) > >+ > >+static inline struct drm_i915_gem_object * > >+to_intel_bo(struct drm_gem_object *gem) > >+{ > >+ /* Assert that to_intel_bo(NULL) == NULL */ > >+ BUILD_BUG_ON(offsetof(struct drm_i915_gem_object, base)); > >+ > >+ return container_of(gem, struct drm_i915_gem_object, base); > >+} > > Yes, I think this is a much better way of doing the conversion, 'cos > it's type-safe and we get that all-important check that 'base' is > still at offset 0. > > In my variant on this, I also introduced the reverse mapping, > to_gem_object(), so that we could completely abstract away the > conversion back-and-forth between the two classes. Do you think that > would be worth adding here too? The convention is that the downcast is tidied away, but as the upcast is just &foo->bar that is easy enough on the eyes. There is also the problem of a limited namespace, so picking who should be to_foo() and to_bar() is tricky. (Without delving into huge polymorphic macros.) -Chris -- Chris Wilson, Intel Open Source Technology Centre _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/intel-gfx